Skip to content

Commit 14dd921

Browse files
authored
feat(input): support allowInputOverMax props (#3473)
1 parent b7f0422 commit 14dd921

File tree

6 files changed

+23
-8
lines changed

6 files changed

+23
-8
lines changed

src/input/README.en-US.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ style | Object | - | CSS(Cascading Style Sheets) | N
1010
custom-style | Object | - | CSS(Cascading Style Sheets),used to set style on virtual component | N
1111
adjust-position | Boolean | true | \- | N
1212
align | String | left | text align type。options: left/center/right | N
13+
allow-input-over-max | Boolean | false | allow to continue input on value length is over `maxlength` or `maxcharacter` | N
1314
always-embed | Boolean | false | \- | N
1415
auto-focus | Boolean | false | \- | N
1516
borderless | Boolean | false | input without border | N
@@ -107,4 +108,4 @@ Name | Default Value | Description
107108
--td-input-suffix-text-color | @text-color-primary | -
108109
--td-input-vertical-padding | 32rpx | -
109110
--td-input-warning-text-color | @warning-color | -
110-
--td-input-warning-tips-color | @warning-color | -
111+
--td-input-warning-tips-color | @warning-color | -

src/input/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ style | Object | - | 样式 | N
8989
custom-style | Object | - | 样式,一般用于开启虚拟化组件节点场景 | N
9090
adjust-position | Boolean | true | 键盘弹起时,是否自动上推页面 | N
9191
align | String | left | 文本内容位置,居左/居中/居右。可选项:left/center/right | N
92+
allow-input-over-max | Boolean | false | 超出 `maxlength``maxcharacter` 之后是否允许继续输入 | N
9293
always-embed | Boolean | false | 强制 input 处于同层状态,默认 focus 时 input 会切到非同层状态 (仅在 iOS 下生效) | N
9394
auto-focus | Boolean | false | (即将废弃,请直接使用 focus )自动聚焦,拉起键盘 | N
9495
borderless | Boolean | false | 是否开启无边框模式 | N
@@ -186,4 +187,4 @@ t-class-tips | 提示样式类
186187
--td-input-suffix-text-color | @text-color-primary | -
187188
--td-input-vertical-padding | 32rpx | -
188189
--td-input-warning-text-color | @warning-color | -
189-
--td-input-warning-tips-color | @warning-color | -
190+
--td-input-warning-tips-color | @warning-color | -

src/input/input.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ export default class Input extends SuperComponent {
6767

6868
methods = {
6969
updateValue(value) {
70-
const { maxcharacter, maxlength } = this.properties;
71-
if (maxcharacter && maxcharacter > 0 && !Number.isNaN(maxcharacter)) {
70+
const { allowInputOverMax, maxcharacter, maxlength } = this.properties;
71+
if (!allowInputOverMax && maxcharacter && maxcharacter > 0 && !Number.isNaN(maxcharacter)) {
7272
const { length, characters } = getCharacterLength('maxcharacter', value, maxcharacter);
7373
this.setData({
7474
value: characters,
7575
count: length,
7676
});
77-
} else if (maxlength && maxlength > 0 && !Number.isNaN(maxlength)) {
77+
} else if (!allowInputOverMax && maxlength && maxlength > 0 && !Number.isNaN(maxlength)) {
7878
const { length, characters } = getCharacterLength('maxlength', value, maxlength);
7979
this.setData({
8080
value: characters,

src/input/input.wxml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<view class="{{classPrefix}}__content {{classPrefix}}--{{status}}">
2828
<input
2929
class="{{this.getInputClass(classPrefix, suffix, align, disabled)}} {{prefix}}-class-input"
30-
maxlength="{{maxlength}}"
30+
maxlength="{{allowInputOverMax ? -1 : maxlength}}"
3131
disabled="{{disabled || readonly}}"
3232
placeholder="{{placeholder}}"
3333
placeholder-style="{{placeholderStyle}}"

src/input/props.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ const props: TdInputProps = {
1616
type: String,
1717
value: 'left',
1818
},
19+
/** 超出 `maxlength` 或 `maxcharacter` 之后是否允许继续输入 */
20+
allowInputOverMax: {
21+
type: Boolean,
22+
value: false,
23+
},
1924
/** 强制 input 处于同层状态,默认 focus 时 input 会切到非同层状态 (仅在 iOS 下生效) */
2025
alwaysEmbed: {
2126
type: Boolean,
@@ -36,7 +41,7 @@ const props: TdInputProps = {
3641
type: String,
3742
value: 'always',
3843
},
39-
/** 是否可清空,默认不启动。值为 `true` 表示使用默认清除空按钮,值为 `Object` 表示透传至 `icon` */
44+
/** 是否可清空,默认不启动。值为 `true` 表示使用默认清空按钮,值为 `Object` 表示透传至 `icon` */
4045
clearable: {
4146
type: null,
4247
value: false,

src/input/type.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ export interface TdInputProps {
2121
type: StringConstructor;
2222
value?: 'left' | 'center' | 'right';
2323
};
24+
/**
25+
* 超出 `maxlength` 或 `maxcharacter` 之后是否允许继续输入
26+
* @default false
27+
*/
28+
allowInputOverMax?: {
29+
type: BooleanConstructor;
30+
value?: boolean;
31+
};
2432
/**
2533
* 强制 input 处于同层状态,默认 focus 时 input 会切到非同层状态 (仅在 iOS 下生效)
2634
* @default false
@@ -54,7 +62,7 @@ export interface TdInputProps {
5462
value?: 'always' | 'focus';
5563
};
5664
/**
57-
* 是否可清空,默认不启动。值为 `true` 表示使用默认清除空按钮,值为 `Object` 表示透传至 `icon`
65+
* 是否可清空,默认不启动。值为 `true` 表示使用默认清空按钮,值为 `Object` 表示透传至 `icon`
5866
* @default false
5967
*/
6068
clearable?: {

0 commit comments

Comments
 (0)