Skip to content

Commit 262cce9

Browse files
Shabi-xdundun003liweijie0812uyarn
authored
feat(TagInput): enhance max rows for TagInput component#3025 (#3293)
* feat(TagInput): enhance max rows functionality and styling #3025 * docs(tag-input): update documentation for max rows and tag input example * feat: 同步common提交内容 * chore: update snapshot * docs: 补充tag-input api文档说明 * chore: update common --------- Co-authored-by: dundun003 <[email protected]> Co-authored-by: 黎伟杰 <[email protected]> Co-authored-by: Uyarn <[email protected]>
1 parent 834d941 commit 262cce9

File tree

7 files changed

+1351
-1
lines changed

7 files changed

+1351
-1
lines changed

Diff for: src/tag-input/TagInput.tsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const TagInput = forwardRef<InputRef, TagInputProps>((originalProps, ref) => {
4343
suffixIcon,
4444
suffix,
4545
prefixIcon,
46+
maxRows,
4647
onClick,
4748
onPaste,
4849
onFocus,
@@ -133,10 +134,18 @@ const TagInput = forwardRef<InputRef, TagInputProps>((originalProps, ref) => {
133134
[WITH_SUFFIX_ICON_CLASS]: !!suffixIconNode,
134135
[`${prefix}-is-empty`]: isEmpty,
135136
[`${prefix}-tag-input--with-tag`]: !isEmpty,
137+
[`${prefix}-tag-input--max-rows`]: excessTagsDisplayType === 'break-line' && maxRows,
136138
},
137139
props.className,
138140
];
139141

142+
const maxRowsStyle = maxRows
143+
? ({
144+
'--max-rows': maxRows,
145+
'--tag-input-size': size,
146+
} as React.CSSProperties)
147+
: {};
148+
140149
return (
141150
<TInput
142151
ref={tagInputRef as React.RefObject<InputRef>}
@@ -152,7 +161,10 @@ const TagInput = forwardRef<InputRef, TagInputProps>((originalProps, ref) => {
152161
disabled={disabled}
153162
label={renderLabel({ displayNode, label })}
154163
className={classnames(classes)}
155-
style={props.style}
164+
style={{
165+
...props.style,
166+
...maxRowsStyle,
167+
}}
156168
tips={tips}
157169
status={status}
158170
placeholder={tagInputPlaceholder}

Diff for: src/tag-input/_example/max-row.tsx

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React, { useState } from 'react';
2+
import { TagInput, Space } from 'tdesign-react';
3+
4+
export default function TagInputMaxRowExample() {
5+
const [tags, setTags] = useState<string[]>([
6+
'Vue',
7+
'React',
8+
'Angular',
9+
'Svelte',
10+
'Solid',
11+
'MiniProgram',
12+
'Flutter',
13+
'UniApp',
14+
'Html5',
15+
'Css3',
16+
'JavaScript',
17+
'TypeScript',
18+
'Node.js',
19+
'Python',
20+
'Java',
21+
'Go',
22+
'Rust',
23+
'C++',
24+
]);
25+
26+
return (
27+
<Space direction="vertical" style={{ width: '80%' }}>
28+
<h3>最大高度为2</h3>
29+
<TagInput
30+
size="small"
31+
maxRows={2}
32+
value={tags}
33+
onChange={(val) => setTags(val.map(String))}
34+
clearable
35+
onPaste={(context) => console.log(context)}
36+
onEnter={(val, context) => console.log(val, context)}
37+
label="小尺寸: "
38+
placeholder="最大高度为2行,超出部分滚动显示"
39+
/>
40+
41+
<h3>最大高度为3</h3>
42+
<TagInput
43+
maxRows={3}
44+
value={tags}
45+
onChange={(val) => setTags(val.map(String))}
46+
label="中等尺寸: "
47+
clearable
48+
placeholder="最大高度为3行,超出部分滚动显示"
49+
/>
50+
51+
<h3>最大高度为4</h3>
52+
<TagInput
53+
size="large"
54+
maxRows={4}
55+
value={tags}
56+
onChange={(val) => setTags(val.map(String))}
57+
label="大尺寸: "
58+
clearable
59+
placeholder="最大高度为4行,超出部分换行显示"
60+
/>
61+
</Space>
62+
);
63+
}

Diff for: src/tag-input/tag-input.en-US.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ inputValue | String / Number | '' | input value。Typescript:`string` | N
2020
defaultInputValue | String / Number | '' | input value。uncontrolled property。Typescript:`string` | N
2121
label | TNode | - | Typescript:`string \| TNode`[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N
2222
max | Number | - | max tag number | N
23+
maxRows | Number | - | max tag rows | N
2324
minCollapsedNum | Number | 0 | \- | N
2425
placeholder | String | undefined | placeholder description | N
2526
prefixIcon | TElement | - | Typescript:`TNode`[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N

Diff for: src/tag-input/tag-input.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ inputValue | String / Number | '' | 输入框的值。TS 类型:`string` | N
2020
defaultInputValue | String / Number | '' | 输入框的值。非受控属性。TS 类型:`string` | N
2121
label | TNode | - | 左侧文本。TS 类型:`string \| TNode`[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N
2222
max | Number | - | 最大允许输入的标签数量 | N
23+
maxRows | Number | - | 最大允许显示的行数,超出会出现滚动条,默认为不限制。 | N
2324
minCollapsedNum | Number | 0 | 最小折叠数量,用于标签数量过多的情况下折叠选中项,超出该数值的选中项折叠。值为 0 则表示不折叠 | N
2425
placeholder | String | undefined | 占位符 | N
2526
prefixIcon | TElement | - | 组件前置图标。TS 类型:`TNode`[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N

Diff for: src/tag-input/type.ts

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ export interface TdTagInputProps {
4848
* @default break-line
4949
*/
5050
excessTagsDisplayType?: 'scroll' | 'break-line';
51+
/**
52+
* 标签最大换行数
53+
* @default 1
54+
*/
55+
maxRows?: number;
5156
/**
5257
* 透传 Input 输入框组件全部属性
5358
*/

0 commit comments

Comments
 (0)