Skip to content

Commit

Permalink
fix(Input): fix input max length (#2598)
Browse files Browse the repository at this point in the history
* fix(input): fix input maxlength behavior

* chore: update common

* chore: update snapshot
  • Loading branch information
uyarn authored Nov 15, 2023
1 parent 337761f commit 5d12b57
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ const Input = forwardRefWithStatics(
onBlur={handleBlur}
onPaste={handlePaste}
name={name}
maxLength={maxlength && !allowInputOverMax ? maxlength : null}
/>
);

Expand Down
4 changes: 2 additions & 2 deletions src/input/_example/max-length-count.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export default function InputExample() {
<Input
value={value1}
onChange={setValue1}
maxlength={5}
maxlength={10}
showLimitNumber
placeholder="内置字数限制,最大文本长度,一个中文字等于一个长度"
placeholder="内置字数限制,最大文本长度为10"
/>

<Input
Expand Down
12 changes: 8 additions & 4 deletions test/snap/__snapshots__/csr.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -116573,7 +116573,8 @@ exports[`csr snapshot test > csr test src/input/_example/max-length-count.jsx 1`
>
<input
class="t-input__inner"
placeholder="内置字数限制,最大文本长度,一个中文字等于一个长度"
maxlength="10"
placeholder="内置字数限制,最大文本长度为10"
type="text"
value=""
/>
Expand All @@ -116583,7 +116584,7 @@ exports[`csr snapshot test > csr test src/input/_example/max-length-count.jsx 1`
<div
class="t-input__limit-number"
>
0/5
0/10
</div>
</div>
</div>
Expand Down Expand Up @@ -116657,6 +116658,7 @@ exports[`csr snapshot test > csr test src/input/_example/max-length-count.jsx 1`
>
<input
class="t-input__inner"
maxlength="5"
placeholder="自定义字数限制文本"
type="text"
value=""
Expand Down Expand Up @@ -116689,7 +116691,8 @@ exports[`csr snapshot test > csr test src/input/_example/max-length-count.jsx 1`
>
<input
class="t-input__inner"
placeholder="内置字数限制,最大文本长度,一个中文字等于一个长度"
maxlength="10"
placeholder="内置字数限制,最大文本长度为10"
type="text"
value=""
/>
Expand All @@ -116699,7 +116702,7 @@ exports[`csr snapshot test > csr test src/input/_example/max-length-count.jsx 1`
<div
class="t-input__limit-number"
>
0/5
0/10
</div>
</div>
</div>
Expand Down Expand Up @@ -116773,6 +116776,7 @@ exports[`csr snapshot test > csr test src/input/_example/max-length-count.jsx 1`
>
<input
class="t-input__inner"
maxlength="5"
placeholder="自定义字数限制文本"
type="text"
value=""
Expand Down
2 changes: 1 addition & 1 deletion test/snap/__snapshots__/ssr.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ exports[`ssr snapshot test > ssr test src/input/_example/format.jsx 1`] = `"<div

exports[`ssr snapshot test > ssr test src/input/_example/group.jsx 1`] = `"<div style=\\"gap:16px\\" class=\\"t-space t-space-vertical\\"><div class=\\"t-space-item\\"><div class=\\"t-input-group t-input-group--separate\\"><div style=\\"width:100px\\" class=\\"t-input__wrap\\"><div class=\\"t-input t-align-left\\"><input placeholder=\\"please enter\\" type=\\"text\\" class=\\"t-input__inner\\" value=\\"0731\\"/></div></div><div class=\\"t-input__wrap\\"><div class=\\"t-input t-align-left\\"><input placeholder=\\"please enter\\" type=\\"text\\" class=\\"t-input__inner\\" value=\\"12345677\\"/></div></div></div></div><div class=\\"t-space-item\\"><div class=\\"t-input-group t-input-group--separate\\"><div class=\\"t-input__wrap\\"><div class=\\"t-input t-align-left\\"><input placeholder=\\"please enter\\" type=\\"text\\" class=\\"t-input__inner\\" value=\\"\\"/></div></div><div class=\\"t-input__wrap\\"><div class=\\"t-input t-align-left\\"><input placeholder=\\"please enter\\" type=\\"text\\" class=\\"t-input__inner\\" value=\\"\\"/></div></div></div></div><div class=\\"t-space-item\\"><div class=\\"t-input-group t-input-group--separate\\"><div style=\\"width:100px\\" class=\\"t-input__wrap\\"><div class=\\"t-input t-align-left\\"><input placeholder=\\"please enter\\" type=\\"text\\" class=\\"t-input__inner\\" value=\\"0731\\"/></div></div><span style=\\"line-height:32px\\"> - </span><div style=\\"width:100px\\" class=\\"t-input__wrap\\"><div class=\\"t-input t-align-left\\"><input placeholder=\\"please enter\\" type=\\"text\\" class=\\"t-input__inner\\" value=\\"12345\\"/></div></div><div style=\\"width:100px\\" class=\\"t-input__wrap\\"><div class=\\"t-input t-align-left\\"><input placeholder=\\"please enter\\" type=\\"text\\" class=\\"t-input__inner\\" value=\\"678901\\"/></div></div><div style=\\"width:100px\\" class=\\"t-input__wrap\\"><div class=\\"t-input t-align-left\\"><input placeholder=\\"please enter\\" type=\\"text\\" class=\\"t-input__inner\\" value=\\"\\"/></div></div></div></div></div>"`;

exports[`ssr snapshot test > ssr test src/input/_example/max-length-count.jsx 1`] = `"<div style=\\"gap:24px;width:500px\\" class=\\"t-space t-space-vertical\\"><div class=\\"t-space-item\\"><div class=\\"t-input__wrap\\" value=\\"\\"><div class=\\"t-input t-align-left\\"><input placeholder=\\"内置字数限制,最大文本长度,一个中文字等于一个长度\\" type=\\"text\\" class=\\"t-input__inner\\" value=\\"\\"/><div class=\\"t-input__suffix\\"><div class=\\"t-input__limit-number\\">0/5</div></div></div></div></div><div class=\\"t-space-item\\"><div class=\\"t-input__wrap\\" value=\\"\\"><div class=\\"t-input t-align-left\\"><input placeholder=\\"内置字数限制,最大字符数量限制,一个中文字等于两个字符\\" type=\\"text\\" class=\\"t-input__inner\\" value=\\"\\"/><div class=\\"t-input__suffix\\"><div class=\\"t-input__limit-number\\">0/10</div></div></div></div></div><div class=\\"t-space-item\\"><div class=\\"t-input__wrap\\" value=\\"\\"><div class=\\"t-input t-align-left\\"><input placeholder=\\"内置字数限制,字数超出时允许继续输入\\" type=\\"text\\" class=\\"t-input__inner\\" value=\\"\\"/><div class=\\"t-input__suffix\\"><div class=\\"t-input__limit-number\\">0/5</div></div></div></div></div><div class=\\"t-space-item\\"><div class=\\"t-input__wrap\\" value=\\"\\"><div class=\\"t-input t-align-left t-input--suffix\\"><input placeholder=\\"自定义字数限制文本\\" type=\\"text\\" class=\\"t-input__inner\\" value=\\"\\"/><div class=\\"t-input__suffix\\">0/5</div></div></div></div></div>"`;
exports[`ssr snapshot test > ssr test src/input/_example/max-length-count.jsx 1`] = `"<div style=\\"gap:24px;width:500px\\" class=\\"t-space t-space-vertical\\"><div class=\\"t-space-item\\"><div class=\\"t-input__wrap\\" value=\\"\\"><div class=\\"t-input t-align-left\\"><input placeholder=\\"内置字数限制,最大文本长度为10\\" type=\\"text\\" class=\\"t-input__inner\\" maxLength=\\"10\\" value=\\"\\"/><div class=\\"t-input__suffix\\"><div class=\\"t-input__limit-number\\">0/10</div></div></div></div></div><div class=\\"t-space-item\\"><div class=\\"t-input__wrap\\" value=\\"\\"><div class=\\"t-input t-align-left\\"><input placeholder=\\"内置字数限制,最大字符数量限制,一个中文字等于两个字符\\" type=\\"text\\" class=\\"t-input__inner\\" value=\\"\\"/><div class=\\"t-input__suffix\\"><div class=\\"t-input__limit-number\\">0/10</div></div></div></div></div><div class=\\"t-space-item\\"><div class=\\"t-input__wrap\\" value=\\"\\"><div class=\\"t-input t-align-left\\"><input placeholder=\\"内置字数限制,字数超出时允许继续输入\\" type=\\"text\\" class=\\"t-input__inner\\" value=\\"\\"/><div class=\\"t-input__suffix\\"><div class=\\"t-input__limit-number\\">0/5</div></div></div></div></div><div class=\\"t-space-item\\"><div class=\\"t-input__wrap\\" value=\\"\\"><div class=\\"t-input t-align-left t-input--suffix\\"><input placeholder=\\"自定义字数限制文本\\" type=\\"text\\" class=\\"t-input__inner\\" maxLength=\\"5\\" value=\\"\\"/><div class=\\"t-input__suffix\\">0/5</div></div></div></div></div>"`;

exports[`ssr snapshot test > ssr test src/input/_example/password.jsx 1`] = `"<div style=\\"gap:16px\\" class=\\"t-space t-space-vertical\\"><div class=\\"t-space-item\\"><div class=\\"t-input__wrap\\" value=\\"\\"><div class=\\"t-input t-align-left t-input--prefix t-input--suffix\\"><span class=\\"t-input__prefix t-input__prefix-icon\\"><svg fill=\\"none\\" viewBox=\\"0 0 24 24\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-lock-on\\"><path fill=\\"currentColor\\" d=\\"M5.5 7.5a6.5 6.5 0 0113 0V9h2v13h-17V9h2V7.5zm2 1.5h9V7.5a4.5 4.5 0 10-9 0V9zm-2 2v9h13v-9h-13zM9 14.5h6v2H9v-2z\\"></path></svg></span><input placeholder=\\"请输入\\" type=\\"password\\" class=\\"t-input__inner\\" value=\\"\\"/><span class=\\"t-input__suffix t-input__suffix-icon\\"><svg fill=\\"none\\" viewBox=\\"0 0 26 24\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-browse-off t-input__suffix-clear\\"><path fill=\\"currentColor\\" d=\\"M4 1.59l6.17 6.17 7.07 7.07L23.41 21 22 22.41l-2.97-2.96A12.5 12.5 0 011.08 12.3L1 12l.1-.3c.77-2.4 2.24-4.5 4.18-6.02L2.59 3 4 1.59zM6.7 7.1A10.53 10.53 0 003.1 12a10.5 10.5 0 0014.45 5.97l-1.8-1.8a5 5 0 01-6.93-6.93L6.7 7.11zm3.6 3.6a3 3 0 004 4l-4-4zM13 5c-.58 0-1.14.05-1.7.14l-.98.16L10 3.32l.99-.16A12.5 12.5 0 0124.9 11.7l.1.31-.1.3c-.41 1.3-1.03 2.5-1.82 3.58l-.59.8-1.61-1.18.59-.8c.6-.82 1.08-1.73 1.42-2.7A10.5 10.5 0 0013 5zm.51 1.93l.96.29a5 5 0 013.31 3.31l.3.96-1.92.58-.3-.95a3 3 0 00-1.98-1.99l-.95-.3.58-1.9z\\"></path></svg></span></div></div></div><div class=\\"t-space-item\\"><div class=\\"t-input__wrap\\" value=\\"\\"><div class=\\"t-input t-align-left t-input--prefix t-input--suffix\\"><span class=\\"t-input__prefix t-input__prefix-icon\\"><svg fill=\\"none\\" viewBox=\\"0 0 24 24\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-lock-on\\"><path fill=\\"currentColor\\" d=\\"M5.5 7.5a6.5 6.5 0 0113 0V9h2v13h-17V9h2V7.5zm2 1.5h9V7.5a4.5 4.5 0 10-9 0V9zm-2 2v9h13v-9h-13zM9 14.5h6v2H9v-2z\\"></path></svg></span><input placeholder=\\"请输入\\" type=\\"password\\" class=\\"t-input__inner\\" value=\\"\\"/><span class=\\"t-input__suffix t-input__suffix-icon\\"><svg fill=\\"none\\" viewBox=\\"0 0 26 24\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-browse-off t-input__suffix-clear\\"><path fill=\\"currentColor\\" d=\\"M4 1.59l6.17 6.17 7.07 7.07L23.41 21 22 22.41l-2.97-2.96A12.5 12.5 0 011.08 12.3L1 12l.1-.3c.77-2.4 2.24-4.5 4.18-6.02L2.59 3 4 1.59zM6.7 7.1A10.53 10.53 0 003.1 12a10.5 10.5 0 0014.45 5.97l-1.8-1.8a5 5 0 01-6.93-6.93L6.7 7.11zm3.6 3.6a3 3 0 004 4l-4-4zM13 5c-.58 0-1.14.05-1.7.14l-.98.16L10 3.32l.99-.16A12.5 12.5 0 0124.9 11.7l.1.31-.1.3c-.41 1.3-1.03 2.5-1.82 3.58l-.59.8-1.61-1.18.59-.8c.6-.82 1.08-1.73 1.42-2.7A10.5 10.5 0 0013 5zm.51 1.93l.96.29a5 5 0 013.31 3.31l.3.96-1.92.58-.3-.95a3 3 0 00-1.98-1.99l-.95-.3.58-1.9z\\"></path></svg></span></div></div></div></div>"`;

Expand Down

0 comments on commit 5d12b57

Please sign in to comment.