Skip to content

Commit

Permalink
Fix/712 fix scrolling (#791)
Browse files Browse the repository at this point in the history
* Implemented requestAnimationFrame to restore scroll position and focus
  • Loading branch information
JpunktWpunkt authored Jan 19, 2024
1 parent 203e1eb commit 6d6e97a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/ui-library/src/components/forms/textarea/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,28 @@ export class BlrTextarea extends LitElement {
}

protected updateCounter() {
const scrollTop = this.textareaElement?.scrollTop;
const isFocused = this.textareaElement === document.activeElement;

const length = this.textareaElement?.value?.length;
if (length !== undefined) {
this.count = length;
}

const shouldUpdateTextarea = this.textareaElement && scrollTop !== undefined;

if (shouldUpdateTextarea) {
requestAnimationFrame(() => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
this.textareaElement.scrollTop = scrollTop;
if (isFocused) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
this.textareaElement.focus();
}
});
}
}

protected determinateCounterVariant(): CounterVariantType {
Expand Down

0 comments on commit 6d6e97a

Please sign in to comment.