Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(input & textarea): add maxlength string prop type #2733

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/input/input.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ format | Function | - | Typescript:`InputFormatType` `type InputFormatType = (
inputClass | String / Object / Array | - | Typescript:`ClassName`。[see more ts definition](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
label | String / Slot / Function | - | Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
maxcharacter | Number | - | \- | N
maxlength | Number | - | \- | N
maxlength | Number / String | - | \- | N
name | String | - | \- | N
placeholder | String | undefined | \- | N
prefixIcon | Slot / Function | - | Typescript:`TNode`。[see more ts definition](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
Expand Down
2 changes: 1 addition & 1 deletion src/input/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ format | Function | - | 指定输入框展示值的格式。TS 类型:`InputFo
inputClass | String / Object / Array | - | t-input 同级类名,示例:'name1 name2 name3' 或 `['name1', 'name2']` 或 `[{ 'name1': true }]`。TS 类型:`ClassName`。[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
label | String / Slot / Function | - | 左侧文本。TS 类型:`string \| TNode`。[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
maxcharacter | Number | - | 用户最多可以输入的字符个数,一个中文汉字表示两个字符长度。`maxcharacter` 和 `maxlength` 二选一使用 | N
maxlength | Number | - | 用户最多可以输入的文本长度,一个中文等于一个计数长度。值为空,则表示不限制输入长度。`maxcharacter` 和 `maxlength` 二选一使用 | N
maxlength | Number / String | - | 用户最多可以输入的文本长度,一个中文等于一个计数长度。值为空,则表示不限制输入长度。`maxcharacter` 和 `maxlength` 二选一使用 | N
name | String | - | 名称 | N
placeholder | String | undefined | 占位符 | N
prefixIcon | Slot / Function | - | 组件前置图标。TS 类型:`TNode`。[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
Expand Down
2 changes: 1 addition & 1 deletion src/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ export default mixins(
if (!(maxlength || maxcharacter) || allowInputOverMax || !inputValue) return inputValue;
if (maxlength) {
// input value could be unicode 😊
return limitUnicodeMaxLength(inputValue, maxlength);
return limitUnicodeMaxLength(inputValue, Number(maxlength));
}
if (maxcharacter) {
const r = getCharacterLength(inputValue, maxcharacter);
Expand Down
2 changes: 1 addition & 1 deletion src/input/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default {
},
/** 用户最多可以输入的文本长度,一个中文等于一个计数长度。值为空,则表示不限制输入长度。`maxcharacter` 和 `maxlength` 二选一使用 */
maxlength: {
type: Number,
type: [Number, String] as PropType<TdInputProps['maxlength']>,
},
/** 名称 */
name: {
Expand Down
2 changes: 1 addition & 1 deletion src/input/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface TdInputProps {
/**
* 用户最多可以输入的文本长度,一个中文等于一个计数长度。值为空,则表示不限制输入长度。`maxcharacter` 和 `maxlength` 二选一使用
*/
maxlength?: number;
maxlength?: number | string;
/**
* 名称
* @default ''
Expand Down
2 changes: 1 addition & 1 deletion src/textarea/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default {
},
/** 用户最多可以输入的字符个数 */
maxlength: {
type: Number,
type: [Number, String] as PropType<TdTextareaProps['maxlength']>,
},
/** 名称,HTML 元素原生属性 */
name: {
Expand Down
2 changes: 1 addition & 1 deletion src/textarea/textarea.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ autosize | Boolean / Object | false | Typescript:`boolean \| { minRows?: numbe
disabled | Boolean | false | \- | N
label | String / Slot / Function | - | Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
maxcharacter | Number | - | \- | N
maxlength | Number | - | \- | N
maxlength | Number / String | - | \- | N
name | String | - | \- | N
placeholder | String | undefined | \- | N
readonly | Boolean | false | \- | N
Expand Down
2 changes: 1 addition & 1 deletion src/textarea/textarea.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ autosize | Boolean / Object | false | 高度自动撑开。 autosize = true 表
disabled | Boolean | false | 是否禁用文本框 | N
label | String / Slot / Function | - | 左侧文本。TS 类型:`string \| TNode`。[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
maxcharacter | Number | - | 用户最多可以输入的字符个数,一个中文汉字表示两个字符长度 | N
maxlength | Number | - | 用户最多可以输入的字符个数 | N
maxlength | Number / String | - | 用户最多可以输入的字符个数 | N
name | String | - | 名称,HTML 元素原生属性 | N
placeholder | String | undefined | 占位符 | N
readonly | Boolean | false | 只读状态 | N
Expand Down
4 changes: 3 additions & 1 deletion src/textarea/textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ export default mixins(Vue as VueConstructor<Textarea>, classPrefixMixins).extend
inputValueChangeHandle(e: InputEvent) {
const { target } = e;
let val = (target as HTMLInputElement).value;
val = limitUnicodeMaxLength(val, this.maxlength);
if (this.maxlength) {
val = limitUnicodeMaxLength(val, Number(this.maxlength));
}
if (this.maxcharacter && this.maxcharacter >= 0) {
const stringInfo = getCharacterLength(val, this.maxcharacter);
val = typeof stringInfo === 'object' && stringInfo.characters;
Expand Down
2 changes: 1 addition & 1 deletion src/textarea/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface TdTextareaProps {
/**
* 用户最多可以输入的字符个数
*/
maxlength?: number;
maxlength?: number | string;
/**
* 名称,HTML 元素原生属性
* @default ''
Expand Down
Loading