From d07da1a475fef47cc64c19e0b2f830d33e53eab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B1=E7=9C=A0=E5=84=80=E5=BC=8F?= <854085467@qq.com> Date: Thu, 28 Jul 2022 11:04:56 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(component):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20textarea=20=E7=BB=84=E4=BB=B6=20maxlength=20=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E4=B8=8D=E5=8F=AF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package/component/src/component/input/index.ts | 2 +- .../component/src/component/textarea/index.vue | 18 ++++++++++-------- .../src/document/zh-CN/components/textarea.md | 5 +++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/package/component/src/component/input/index.ts b/package/component/src/component/input/index.ts index a1b16342..bc751ebc 100644 --- a/package/component/src/component/input/index.ts +++ b/package/component/src/component/input/index.ts @@ -2,4 +2,4 @@ import { withInstall, WithInstallType } from "../../utils"; import Component from "./index.vue"; const component: WithInstallType = withInstall(Component); -export default component; \ No newline at end of file +export default component; diff --git a/package/component/src/component/textarea/index.vue b/package/component/src/component/textarea/index.vue index 097697d5..662510ab 100644 --- a/package/component/src/component/textarea/index.vue +++ b/package/component/src/component/textarea/index.vue @@ -15,15 +15,16 @@ export interface LayTextareaProps { disabled?: boolean; showCount?: boolean; allowClear?: boolean; + maxlength?: number; } const props = defineProps(); interface TextareaEmits { (e: "blur", event: Event): void; - (e: "input", event: Event): void; + (e: "input", value: string ): void; (e: "update:modelValue", value: string): void; - (e: "change", event: Event): void; + (e: "change", value: string): void; (e: "focus", event: Event): void; (e: "clear"): void; } @@ -35,7 +36,7 @@ const attrs = useAttrs(); const onInput = function (event: Event) { const inputElement = event.target as HTMLInputElement; emit("update:modelValue", inputElement.value); - emit("input", event); + emit("input", inputElement.value); }; const onFocus = function (event: Event) { @@ -47,7 +48,8 @@ const onBlur = function (event: Event) { }; const onChange = (event: Event) => { - emit("change", event); + const inputElement = event.target as HTMLInputElement; + emit("change", inputElement.value); }; const onClear = function () { @@ -59,8 +61,8 @@ const hasContent = computed(() => (props.modelValue as string)?.length > 0); const wordCount = computed(() => { let count = String(props.modelValue?.length ?? 0); - if (attrs.maxlength) { - count += "/" + attrs.maxlength; + if (props.maxlength) { + count += "/" + props.maxlength; } return count; }); @@ -69,12 +71,12 @@ const wordCount = computed(() => {