Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/components/textarea/textarea.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default class SlTextarea extends ShoelaceElement implements ShoelaceFormC
this.resizeObserver = new ResizeObserver(() => this.setTextareaHeight());

this.updateComplete.then(() => {
this.setTextareaHeight();
this.setTextareaHeight(true);
this.resizeObserver.observe(this.input);
});
}
Expand Down Expand Up @@ -195,13 +195,14 @@ export default class SlTextarea extends ShoelaceElement implements ShoelaceFormC
this.formControlController.emitInvalidEvent(event);
}

private setTextareaHeight() {
private setTextareaHeight(isProgrammatic?: boolean) {
if (this.resize === 'auto') {
// This prevents layout shifts. We use `clientHeight` instead of `scrollHeight` to account for if the `<textarea>` has a max-height set on it. In my tests, this has worked fine. Im not aware of any edge cases. [Konnor]
this.sizeAdjuster.style.height = `${this.input.clientHeight}px`;
this.input.style.height = 'auto';
this.input.style.height = `${this.input.scrollHeight}px`;
} else {
} else if(isProgrammatic){
// The height only be changed by user resize, so no need to reset the value.
this.input.style.height = '';
}
}
Expand All @@ -214,7 +215,7 @@ export default class SlTextarea extends ShoelaceElement implements ShoelaceFormC

@watch('rows', { waitUntilFirstUpdate: true })
handleRowsChange() {
this.setTextareaHeight();
this.setTextareaHeight(true);
}

@watch('value', { waitUntilFirstUpdate: true })
Expand Down