Merge pull request #206 from mario-aleo/fix/teaxtAreaAutosizeEgdeBug
[textarea] Wait for textarea slot before init autoresize
This commit is contained in:
commit
2ed6a37430
1 changed files with 33 additions and 2 deletions
|
|
@ -62,8 +62,7 @@ export class LionTextarea extends ObserverMixin(LionInput) {
|
||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
// eslint-disable-next-line wc/guard-super-call
|
// eslint-disable-next-line wc/guard-super-call
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
this.setTextareaMaxHeight();
|
this.__initializeAutoresize();
|
||||||
autosize(this.inputElement);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnectedCallback() {
|
disconnectedCallback() {
|
||||||
|
|
@ -101,7 +100,39 @@ export class LionTextarea extends ObserverMixin(LionInput) {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get updateComplete() {
|
||||||
|
if (this.__textareaUpdateComplete) {
|
||||||
|
return Promise.all([this.__textareaUpdateComplete, super.updateComplete]);
|
||||||
|
}
|
||||||
|
return super.updateComplete;
|
||||||
|
}
|
||||||
|
|
||||||
resizeTextarea() {
|
resizeTextarea() {
|
||||||
autosize.update(this.inputElement);
|
autosize.update(this.inputElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__initializeAutoresize() {
|
||||||
|
if (this.__shady_native_contains) {
|
||||||
|
this.__textareaUpdateComplete = this.__waitForTextareaRenderedInRealDOM().then(() => {
|
||||||
|
this.__startAutoresize();
|
||||||
|
this.__textareaUpdateComplete = null;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.__startAutoresize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async __waitForTextareaRenderedInRealDOM() {
|
||||||
|
let count = 3; // max tasks to wait for
|
||||||
|
while (count !== 0 && !this.__shady_native_contains(this.inputElement)) {
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
await new Promise(resolve => setTimeout(resolve));
|
||||||
|
count -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__startAutoresize() {
|
||||||
|
autosize(this.inputElement);
|
||||||
|
this.setTextareaMaxHeight();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue