Compare commits
No commits in common. "315b15ae53909c73afd5e3ec4831c7f28ab88251" and "9e8d0e6c98f6272e7597692be23b75d3d1b5c16f" have entirely different histories.
315b15ae53
...
9e8d0e6c98
@ -611,21 +611,3 @@ hr {
|
|||||||
height: 50px;
|
height: 50px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.auto-textarea {
|
|
||||||
width: 100%;
|
|
||||||
min-height: 40px; /* 初始高度 */
|
|
||||||
max-height: 150px; /* 最大高度:超过此高度将滚动 */
|
|
||||||
line-height: 1.5;
|
|
||||||
padding: 10px;
|
|
||||||
box-sizing: border-box;
|
|
||||||
resize: none; /* 禁用右下角手动拉伸 */
|
|
||||||
overflow-y: hidden; /* 初始隐藏滚动条 */
|
|
||||||
border: 1px solid #ccc;
|
|
||||||
border-radius: 4px;
|
|
||||||
outline: none;
|
|
||||||
transition: border-color 0.2s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.inputbox:focus {
|
|
||||||
border-color: #007bff;
|
|
||||||
}
|
|
||||||
|
|||||||
@ -914,6 +914,8 @@ bricks.UiText =class extends bricks.UiType {
|
|||||||
value:
|
value:
|
||||||
defaultValue:
|
defaultValue:
|
||||||
tip:
|
tip:
|
||||||
|
rows:
|
||||||
|
cols:
|
||||||
readonly:
|
readonly:
|
||||||
required:
|
required:
|
||||||
}
|
}
|
||||||
@ -921,37 +923,13 @@ bricks.UiText =class extends bricks.UiType {
|
|||||||
constructor(opts){
|
constructor(opts){
|
||||||
opts.dynsize = opts.dynsize || true;
|
opts.dynsize = opts.dynsize || true;
|
||||||
opts.cfontsize = opts.cfontsize || 1;
|
opts.cfontsize = opts.cfontsize || 1;
|
||||||
if (opts.css){
|
opts.height = '200px';
|
||||||
opts.css += 'auto-textarea';
|
|
||||||
} else {
|
|
||||||
opts.css = 'auto-textarea';
|
|
||||||
}
|
|
||||||
super(opts);
|
super(opts);
|
||||||
this.uitype='text';
|
this.uitype='text';
|
||||||
this.build();
|
this.build();
|
||||||
this.charsize_sizing();
|
this.charsize_sizing();
|
||||||
this.bind('input', this.handleInput.bind(this));
|
this.set_style('overflow', 'auto');
|
||||||
this.bind('keydown', this.key_handle.bind(this));
|
this.bind('keydown', this.key_handle.bind(this))
|
||||||
}
|
|
||||||
handleInput() {
|
|
||||||
// 1. 重置高度为 auto,以便能够正确计算缩减后的 scrollHeight
|
|
||||||
var el = this.dom_element;
|
|
||||||
el.style.height = 'auto';
|
|
||||||
|
|
||||||
// 2. 获取当前的滚动高度
|
|
||||||
const scrollHeight = el.scrollHeight;
|
|
||||||
// 3. 获取 CSS 中定义的 max-height (150px)
|
|
||||||
const maxHeight = parseInt(window.getComputedStyle(el).maxHeight);
|
|
||||||
|
|
||||||
if (scrollHeight >= maxHeight) {
|
|
||||||
// 4. 如果内容高度超过最大高度,固定为最大高度并显示滚动条
|
|
||||||
el.style.height = maxHeight + 'px';
|
|
||||||
el.style.overflowY = 'auto';
|
|
||||||
} else {
|
|
||||||
// 5. 否则持续自适应高度,并隐藏滚动条
|
|
||||||
el.style.height = scrollHeight + 'px';
|
|
||||||
el.style.overflowY = 'hidden';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
create(){
|
create(){
|
||||||
this.dom_element = this._create('textarea');
|
this.dom_element = this._create('textarea');
|
||||||
@ -959,6 +937,8 @@ bricks.UiText =class extends bricks.UiType {
|
|||||||
build(){
|
build(){
|
||||||
var e = this.dom_element;
|
var e = this.dom_element;
|
||||||
e.id = e.name = this.opts.name;
|
e.id = e.name = this.opts.name;
|
||||||
|
e.rows = this.opts.rows || 5;
|
||||||
|
e.cols = this.opts.cols || 40;
|
||||||
this.reset();
|
this.reset();
|
||||||
this.bind('input', this.set_value_from_input.bind(this))
|
this.bind('input', this.set_value_from_input.bind(this))
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user