From 364cfbf1af7a9109be9af59b543b4ccef9c32916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=A6=82=E6=91=B8=E9=B1=BC=E5=8E=BB?= <1780903673@qq.com> Date: Wed, 31 Jul 2024 23:06:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20Input=20=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=96=B0=E5=A2=9Eclear-triger=E5=B1=9E=E6=80=A7=20(#476)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: #462 --- docs/component/input.md | 18 ++++ docs/component/search.md | 12 --- src/pages/input/Index.vue | 10 +- .../components/wd-input/types.ts | 15 ++- .../components/wd-input/wd-input.vue | 102 +++++++++++------- 5 files changed, 106 insertions(+), 51 deletions(-) diff --git a/docs/component/input.md b/docs/component/input.md index 9c7de246..0dd8ea08 100644 --- a/docs/component/input.md +++ b/docs/component/input.md @@ -44,6 +44,21 @@ function handleChange(event) { ``` +## 有值且聚焦时展示清空按钮 +设置 `clear-trigger` 属性,可以控制是否聚焦时才展示清空按钮。 + +```html + +``` + +## 点击清除按钮时不自动聚焦 + +设置`focus-when-clear` 属性,可以控制点击清除按钮时是否自动聚焦。 + +```html + +``` + ## 密码输入框 设置 `show-password` 属性。 @@ -150,6 +165,9 @@ function handleChange(event) { | no-border | 非 cell 类型下是否隐藏下划线 | boolean | - | false | - | - | | prop | 表单域 `model` 字段名,在使用表单校验功能的情况下,该属性是必填的 | string | - | - | - | | rules | 表单验证规则,结合`wd-form`组件使用 | `FormItemRule []` | - | `[]` | - | +| clearTrigger | 显示清除图标的时机,always 表示输入框不为空时展示,focus 表示输入框聚焦且不为空时展示 | `InputClearTrigger` | `focus` / `always` | `always` | $LOWEST_VERSION$ | +| focusWhenClear | 是否在点击清除按钮时聚焦输入框 | boolean | - | true | $LOWEST_VERSION$ | + ### FormItemRule 数据结构 diff --git a/docs/component/search.md b/docs/component/search.md index 48847a28..11f9a435 100644 --- a/docs/component/search.md +++ b/docs/component/search.md @@ -141,18 +141,6 @@ function changeSearchType({ item, index }) { ``` - ## Attributes diff --git a/src/pages/input/Index.vue b/src/pages/input/Index.vue index ccbb701d..20ee952a 100644 --- a/src/pages/input/Index.vue +++ b/src/pages/input/Index.vue @@ -15,6 +15,12 @@ + + + + + + @@ -45,7 +51,7 @@ - + @@ -76,6 +82,8 @@ const value16 = ref('') const value17 = ref('') const value18 = ref('') const value19 = ref('') +const value20 = ref('') +const value21 = ref('') function handleChange(event: any) { console.log(event) diff --git a/src/uni_modules/wot-design-uni/components/wd-input/types.ts b/src/uni_modules/wot-design-uni/components/wd-input/types.ts index e7b19cac..2c9638bb 100644 --- a/src/uni_modules/wot-design-uni/components/wd-input/types.ts +++ b/src/uni_modules/wot-design-uni/components/wd-input/types.ts @@ -1,6 +1,8 @@ import { baseProps, makeArrayProp, makeBooleanProp, makeNumberProp, makeNumericProp, makeStringProp } from '../common/props' import type { FormItemRule } from '../wd-form/types' +export type InputClearTrigger = 'focus' | 'always' + export const inputProps = { ...baseProps, customInputClass: makeStringProp(''), @@ -155,5 +157,16 @@ export const inputProps = { /** * 表单验证规则,结合wd-form组件使用 */ - rules: makeArrayProp() + rules: makeArrayProp(), + /** + * 显示清除图标的时机,always 表示输入框不为空时展示,focus 表示输入框聚焦且不为空时展示 + */ + clearTrigger: makeStringProp('always'), + /** + * 是否在点击清除按钮时聚焦输入框 + * 类型: boolean + * 默认值: true + * 最低版本: $LOWEST_VERSION$ + */ + focusWhenClear: makeBooleanProp(true) } diff --git a/src/uni_modules/wot-design-uni/components/wd-input/wd-input.vue b/src/uni_modules/wot-design-uni/components/wd-input/wd-input.vue index b316c4ea..0a305600 100644 --- a/src/uni_modules/wot-design-uni/components/wd-input/wd-input.vue +++ b/src/uni_modules/wot-design-uni/components/wd-input/wd-input.vue @@ -30,7 +30,7 @@ :placeholder="placeholder || translate('placeholder')" :disabled="disabled" :maxlength="maxlength" - :focus="isFocus" + :focus="focused" :confirm-type="confirmType" :confirm-hold="confirmHold" :cursor="cursor" @@ -49,7 +49,7 @@ @keyboardheightchange="handleKeyboardheightchange" /> - + @@ -85,7 +85,7 @@ export default {