Skip to content

Commit

Permalink
feat(input): enable props clear-trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
betavs committed Sep 21, 2023
1 parent c0b9c85 commit 40a5ce6
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/input/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ align | String | left | options:left/center/right | N
layout | String | horizontal | options:vertical/horizontal | N
borderless | Boolean | true | \- | N
clearable | Boolean | false | \- | N
clear-trigger | String | always | options:always / focus | N
disabled | Boolean | - | \- | N
error-message | String | - | `deprecated` | N
external-classes | Array | - | `['t-class', 't-class-input', 't-class-placeholder', 't-class-error-msg']` | N
Expand Down
1 change: 1 addition & 0 deletions src/input/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ align | String | left | 文本内容位置,居左/居中/居右。可选项:
layout | String | horizontal | 标题输入框布局方式。可选项:vertical/horizontal | N
borderless | Boolean | false | 是否开启无边框模式 | N
clearable | Boolean / Object | false | 是否可清空,默认不启动。值为 `true` 表示使用默认清除空按钮,值为 `Object` 表示透传至 `icon` | N
clear-trigger | String | always | 清空图标触发方式。可选项:always / focus | N
disabled | Boolean | false | 是否禁用输入框 | N
error-message | String | - | 已废弃。错误提示文本,值为空不显示(废弃属性,如果需要,请更为使用 status 和 tips) | N
format | Function | - | 【开发中】指定输入框展示值的格式。TS 类型:`InputFormatType` `type InputFormatType = (value: InputValue) => number | string`[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/input/type.ts) | N
Expand Down
8 changes: 8 additions & 0 deletions src/input/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default class Input extends SuperComponent {
classPrefix: name,
classBasePrefix: prefix,
excludeType: ['number', 'digit'],
showClearIcon: true,
};

lifetimes = {
Expand Down Expand Up @@ -59,6 +60,10 @@ export default class Input extends SuperComponent {
_clearIcon: calcIcon(v, 'close-circle-filled'),
});
},

clearTrigger(v) {
this.setData({ showClearIcon: v === 'always' });
},
};

methods = {
Expand Down Expand Up @@ -90,9 +95,12 @@ export default class Input extends SuperComponent {
this.triggerEvent('change', { value: this.data.value, cursor, keyCode });
},
onFocus(e) {
this.setData({ showClearIcon: true });
this.triggerEvent('focus', e.detail);
},
onBlur(e) {
const { clearTrigger } = this.properties;
this.setData({ showClearIcon: clearTrigger === 'always' });
this.triggerEvent('blur', e.detail);
},
onConfirm(e) {
Expand Down
2 changes: 1 addition & 1 deletion src/input/input.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
安卓不会播报aria-label,会播报aria-roledescription的内容
-->
<view
wx:if="{{_clearIcon && value.length > 0}}"
wx:if="{{_clearIcon && value.length > 0 && showClearIcon}}"
class="{{classPrefix}}__wrap--clearable-icon"
bind:touchstart="clearInput"
>
Expand Down
5 changes: 5 additions & 0 deletions src/input/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const props: TdInputProps = {
type: null,
value: false,
},
/** 清空图标触发方式 */
clearTrigger: {
type: String,
value: 'always',
},
/** 是否禁用输入框 */
disabled: {
type: Boolean,
Expand Down
8 changes: 8 additions & 0 deletions src/input/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ export interface TdInputProps {
type: null;
value?: boolean | object;
};
/**
* 清空图标触发方式
* @default always
*/
clearTrigger?: {
type: StringConstructor;
value?: 'always' | 'focus';
};
/**
* 自定义组件样式
* @default ''
Expand Down

0 comments on commit 40a5ce6

Please sign in to comment.