first commit
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
export class AutoExpand {
|
||||
|
||||
/**
|
||||
* Autoexpand, Constructor
|
||||
*/
|
||||
constructor(target, opts) {
|
||||
|
||||
this.opts = { ... { minRows: 3 }, ... opts };
|
||||
|
||||
this.target = target;
|
||||
|
||||
if (this.target.dxData('autoexpand')) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.target.dxData('autoexpand', this);
|
||||
|
||||
this.update();
|
||||
|
||||
this.target.dxOn('input.autoExpand', this.setRows.bind(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoexpand, Update
|
||||
*/
|
||||
update() {
|
||||
|
||||
let val = this.target.dxVal();
|
||||
|
||||
this.target.dxVal('');
|
||||
|
||||
this.target.dataset.baseScrollHeight = this.target.scrollHeight;
|
||||
|
||||
this.target.dxVal(val);
|
||||
|
||||
if (val) {
|
||||
this.setRows();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoexpand, Set Rows
|
||||
*/
|
||||
setRows() {
|
||||
this.target.rows = this.opts.minRows;
|
||||
let rows = Math.ceil((this.target.scrollHeight - this.target.dataset.baseScrollHeight) / 16);
|
||||
this.target.rows = this.opts.minRows + rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoexpand, Destroy
|
||||
*/
|
||||
destroy = function() {
|
||||
this.target.dxOff('input.autoExpand');
|
||||
this.target.rows = 2;
|
||||
this.target.dxRemoveData('autoexpand');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user