Skip to content

Commit 68b5ca8

Browse files
authored
feat(Input): support format props (#1602)
* feat(Input): support format props * docs(Input): update
1 parent b0c1a18 commit 68b5ca8

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/input/input.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ borderless | Boolean | false | 是否开启无边框模式 | N
1414
clearTrigger | String | always | 清空图标触发方式,仅在输入框有值时有效。可选项:always / focus | N
1515
clearable | Boolean | false | 是否可清空 | N
1616
disabled | Boolean | undefined | 是否禁用输入框 | N
17-
format | Function | - | 【开发中】指定输入框展示值的格式。TS 类型:`InputFormatType` `type InputFormatType = (value: InputValue) => string`[详细类型定义](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/input/type.ts) | N
17+
format | Function | - | 指定输入框展示值的格式。TS 类型:`InputFormatType` `type InputFormatType = (value: InputValue) => string`[详细类型定义](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/input/type.ts) | N
1818
label | String / Slot / Function | - | 左侧文本。TS 类型:`string \| TNode`[通用类型定义](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N
1919
layout | String | horizontal | 标题输入框布局方式。可选项:vertical/horizontal | N
2020
maxcharacter | Number | - | 用户最多可以输入的字符个数,一个中文汉字表示两个字符长度。`maxcharacter``maxlength` 二选一使用 | N

src/input/input.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
BrowseOffIcon as TBrowseOffIcon,
55
CloseCircleFilledIcon as TCloseCircleFilledIcon,
66
} from 'tdesign-icons-vue-next';
7+
import isFunction from 'lodash/isFunction';
78
import config from '../config';
89
import InputProps from './props';
910
import { InputValue, TdInputProps } from './type';
@@ -132,6 +133,17 @@ export default defineComponent({
132133

133134
const handleBlur = (e: FocusEvent) => {
134135
focused.value = false;
136+
137+
// 失焦时处理 format
138+
if (isFunction(props.format)) {
139+
innerValue.value = props.format(innerValue.value);
140+
nextTick(() => {
141+
setInputValue(innerValue.value);
142+
props.onBlur?.(innerValue.value, { e });
143+
});
144+
return;
145+
}
146+
135147
props.onBlur?.(innerValue.value, { e });
136148
};
137149

0 commit comments

Comments
 (0)