From 1df7641b53de11e61be38e79365680812d0122ac Mon Sep 17 00:00:00 2001 From: 07akioni <07akioni2@gmail.com> Date: Tue, 19 Jul 2022 23:55:36 +0800 Subject: [PATCH] refactor(input): scrollTo --- src/input/demos/enUS/focus.demo.vue | 11 +++-------- src/input/demos/enUS/index.demo-entry.md | 2 +- src/input/demos/zhCN/focus.demo.vue | 11 +++-------- src/input/demos/zhCN/index.demo-entry.md | 2 +- src/input/src/Input.tsx | 12 +++++++----- 5 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/input/demos/enUS/focus.demo.vue b/src/input/demos/enUS/focus.demo.vue index daf7a3b66..cadb11a98 100644 --- a/src/input/demos/enUS/focus.demo.vue +++ b/src/input/demos/enUS/focus.demo.vue @@ -20,12 +20,7 @@ ScrollToEnd - + @@ -38,7 +33,7 @@ export default defineComponent({ const inputInstRef = ref(null) return { inputInstRef, - inputValue: ref("I heard you're going to select all?\n".repeat(4)), + inputValue: ref("I heard you're going to select all? ".repeat(4).trim()), handleFocus () { inputInstRef.value?.focus() }, @@ -51,7 +46,7 @@ export default defineComponent({ handleScrollEnd () { inputInstRef.value?.scrollTo({ behavior: 'smooth', - top: 10000 + left: 10000 }) } } diff --git a/src/input/demos/enUS/index.demo-entry.md b/src/input/demos/enUS/index.demo-entry.md index da54276fa..4992793e9 100644 --- a/src/input/demos/enUS/index.demo-entry.md +++ b/src/input/demos/enUS/index.demo-entry.md @@ -92,4 +92,4 @@ pattern.vue | blur | `() => void` | Blur the input element. | | | focus | `() => void` | Focus the input element. | | | select | `() => void` | Select the input element. | | -| scrollTo | `(options?: ScrollToOptions) => void` | Scroll To. | NEXT_VERSION | +| scrollTo | `(options: { left?: number, top?: number, behavior?: 'auto' \| 'smooth' }) => void` | Scroll To. | NEXT_VERSION | diff --git a/src/input/demos/zhCN/focus.demo.vue b/src/input/demos/zhCN/focus.demo.vue index 4e1b511ab..1b68ec056 100644 --- a/src/input/demos/zhCN/focus.demo.vue +++ b/src/input/demos/zhCN/focus.demo.vue @@ -20,12 +20,7 @@ ScrollToEnd - + @@ -38,7 +33,7 @@ export default defineComponent({ const inputInstRef = ref(null) return { inputInstRef, - inputValue: ref('马儿乖,马儿好,马儿光跑不吃草\n'.repeat(4)), + inputValue: ref('马儿乖,马儿好,马儿光跑不吃草。'.repeat(4)), handleFocus () { inputInstRef.value?.focus() }, @@ -51,7 +46,7 @@ export default defineComponent({ handleScrollEnd () { inputInstRef.value?.scrollTo({ behavior: 'smooth', - top: 10000 + left: 10000 }) } } diff --git a/src/input/demos/zhCN/index.demo-entry.md b/src/input/demos/zhCN/index.demo-entry.md index 75b9934db..1c6f9693e 100644 --- a/src/input/demos/zhCN/index.demo-entry.md +++ b/src/input/demos/zhCN/index.demo-entry.md @@ -94,4 +94,4 @@ prefix-debug.vue | blur | `() => void` | Blur input 元素 | | | focus | `() => void` | Focus input 元素 | | | select | `() => void` | Select input 元素 | | -| scrollTo | `(options?: ScrollToOptions) => void` | 滚动到 | NEXT_VERSION | +| scrollTo | `(options: { left?: number, top?: number, behavior?: 'auto' \| 'smooth' }) => void` | 滚动到 | NEXT_VERSION | diff --git a/src/input/src/Input.tsx b/src/input/src/Input.tsx index a3724e71d..fe62f93ff 100644 --- a/src/input/src/Input.tsx +++ b/src/input/src/Input.tsx @@ -697,12 +697,14 @@ export default defineComponent({ } } - function scrollTo (options?: ScrollToOptions | undefined): void { - const { value: textareaEl } = textareaElRef - if (!textareaEl) { - return + function scrollTo (options: ScrollToOptions): void { + if (props.type === 'textarea') { + const { value: textareaEl } = textareaElRef + textareaEl?.scrollTo(options) + } else { + const { value: inputEl } = inputElRef + inputEl?.scrollTo(options) } - textareaEl.scrollTo(options) } function syncMirror (value: string | null): void {