From 0dbb72efe9b3e426375d14b2ab83c0f9c78ac574 Mon Sep 17 00:00:00 2001 From: Cory LaViska Date: Sat, 29 May 2021 10:55:56 -0400 Subject: [PATCH] add scrollPosition method --- docs/resources/changelog.md | 1 + src/components/textarea/textarea.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/docs/resources/changelog.md b/docs/resources/changelog.md index 5e7e0646..0a28991f 100644 --- a/docs/resources/changelog.md +++ b/docs/resources/changelog.md @@ -9,6 +9,7 @@ _During the beta period, these restrictions may be relaxed in the event of a mis ## Next - Added `?` to optional arguments in methods tables +- Added the `scrollPosition()` method to `sl-textarea` to get/set scroll position ## 2.0.0-beta.42 diff --git a/src/components/textarea/textarea.ts b/src/components/textarea/textarea.ts index ee5683d4..db62392a 100644 --- a/src/components/textarea/textarea.ts +++ b/src/components/textarea/textarea.ts @@ -162,6 +162,20 @@ export default class SlTextarea extends LitElement { return this.input.select(); } + /** Gets or sets the textarea's scroll position. */ + scrollPosition(position?: { top?: number; left?: number }) { + if (position) { + if (typeof position.top === 'number') this.input.scrollTop = position.top; + if (typeof position.left === 'number') this.input.scrollLeft = position.left; + return; + } + + return { + top: this.input.scrollTop, + left: this.input.scrollTop + }; + } + /** Sets the start and end positions of the text selection (0-based). */ setSelectionRange( selectionStart: number,