mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
fix(textarea): properly adjust auto-grow textarea in scrolled content (#19776)
fixes #19193
This commit is contained in:

committed by
Liam DeBeasi

parent
a3fc77be91
commit
8bd5bace73
@ -21,6 +21,7 @@ export class Textarea implements ComponentInterface {
|
|||||||
private nativeInput?: HTMLTextAreaElement;
|
private nativeInput?: HTMLTextAreaElement;
|
||||||
private inputId = `ion-input-${textareaIds++}`;
|
private inputId = `ion-input-${textareaIds++}`;
|
||||||
private didBlurAfterEdit = false;
|
private didBlurAfterEdit = false;
|
||||||
|
private textareaWrapper?: HTMLElement;
|
||||||
|
|
||||||
@Element() el!: HTMLElement;
|
@Element() el!: HTMLElement;
|
||||||
|
|
||||||
@ -191,13 +192,15 @@ export class Textarea implements ComponentInterface {
|
|||||||
this.runAutoGrow();
|
this.runAutoGrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: performance hit, this cause layout thrashing
|
|
||||||
private runAutoGrow() {
|
private runAutoGrow() {
|
||||||
const nativeInput = this.nativeInput;
|
const nativeInput = this.nativeInput;
|
||||||
if (nativeInput && this.autoGrow) {
|
if (nativeInput && this.autoGrow) {
|
||||||
readTask(() => {
|
readTask(() => {
|
||||||
nativeInput.style.height = 'inherit';
|
nativeInput.style.height = 'auto';
|
||||||
nativeInput.style.height = nativeInput.scrollHeight + 'px';
|
nativeInput.style.height = nativeInput.scrollHeight + 'px';
|
||||||
|
if (this.textareaWrapper) {
|
||||||
|
this.textareaWrapper.style.height = nativeInput.scrollHeight + 'px';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -309,6 +312,10 @@ export class Textarea implements ComponentInterface {
|
|||||||
...createColorClasses(this.color),
|
...createColorClasses(this.color),
|
||||||
[mode]: true,
|
[mode]: true,
|
||||||
}}
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="textarea-wrapper"
|
||||||
|
ref={el => this.textareaWrapper = el}
|
||||||
>
|
>
|
||||||
<textarea
|
<textarea
|
||||||
class="native-textarea"
|
class="native-textarea"
|
||||||
@ -333,6 +340,7 @@ export class Textarea implements ComponentInterface {
|
|||||||
>
|
>
|
||||||
{value}
|
{value}
|
||||||
</textarea>
|
</textarea>
|
||||||
|
</div>
|
||||||
</Host>
|
</Host>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user