From 356dd3582d68651373b86715b169891417615251 Mon Sep 17 00:00:00 2001 From: dundun003 Date: Mon, 23 Dec 2024 16:33:08 +0800 Subject: [PATCH] feat(TagInput): enhance max rows functionality and styling #3025 --- src/tag-input/TagInput.tsx | 14 +++++- src/tag-input/_example/max-row.tsx | 72 ++++++++++++++++++++++++++++++ src/tag-input/type.ts | 5 +++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/tag-input/_example/max-row.tsx diff --git a/src/tag-input/TagInput.tsx b/src/tag-input/TagInput.tsx index 2dd097b912..2930c96212 100644 --- a/src/tag-input/TagInput.tsx +++ b/src/tag-input/TagInput.tsx @@ -43,6 +43,7 @@ const TagInput = forwardRef((originalProps, ref) => { suffixIcon, suffix, prefixIcon, + maxRows, onClick, onPaste, onFocus, @@ -133,10 +134,18 @@ const TagInput = forwardRef((originalProps, ref) => { [WITH_SUFFIX_ICON_CLASS]: !!suffixIconNode, [`${prefix}-is-empty`]: isEmpty, [`${prefix}-tag-input--with-tag`]: !isEmpty, + [`${prefix}-tag-input--max-rows`]: excessTagsDisplayType === 'break-line' && maxRows, }, props.className, ]; + const maxRowsStyle = maxRows + ? ({ + '--max-rows': maxRows, + '--tag-input-size': size, + } as React.CSSProperties) + : {}; + return ( } @@ -152,7 +161,10 @@ const TagInput = forwardRef((originalProps, ref) => { disabled={disabled} label={renderLabel({ displayNode, label })} className={classnames(classes)} - style={props.style} + style={{ + ...props.style, + ...maxRowsStyle, + }} tips={tips} status={status} placeholder={tagInputPlaceholder} diff --git a/src/tag-input/_example/max-row.tsx b/src/tag-input/_example/max-row.tsx new file mode 100644 index 0000000000..793665ca1c --- /dev/null +++ b/src/tag-input/_example/max-row.tsx @@ -0,0 +1,72 @@ +import React, { useState } from 'react'; +import { TagInput, Space } from 'tdesign-react'; +import type { TagInputProps, TagInputValue } from 'tdesign-react'; + +export default function TagInputMaxRowExample() { + const [tags1, setTags1] = useState(['Vue', 'React', 'Angular', 'Svelte', 'Solid', 'Preact']); + const [tags2, setTags2] = useState(['Ember', 'Backbone']); + const [tags3, setTags3] = useState(['Alpine', 'Lit']); + + const onTagInputEnter: TagInputProps['onEnter'] = (val, context) => { + console.log(val, context); + }; + + const onChange1: TagInputProps['onChange'] = (val, context) => { + console.log(val, context); + setTags1(val); + }; + + const onChange2: TagInputProps['onChange'] = (val, context) => { + console.log(val, context); + setTags2(val); + }; + + const onChange3: TagInputProps['onChange'] = (val, context) => { + console.log(val, context); + setTags3(val); + }; + + const onPaste: TagInputProps['onPaste'] = (context) => { + console.log(context); + }; + + return ( + +

Small Size with 2 Max Rows

+ + +

Default Size with 3 Max Rows

+ + +

Large Size with 4 Max Rows

+ +
+ ); +} diff --git a/src/tag-input/type.ts b/src/tag-input/type.ts index f7ebb16022..8348aae09a 100644 --- a/src/tag-input/type.ts +++ b/src/tag-input/type.ts @@ -48,6 +48,11 @@ export interface TdTagInputProps { * @default break-line */ excessTagsDisplayType?: 'scroll' | 'break-line'; + /** + * 标签最大换行数 + * @default 1 + */ + maxRows?: number; /** * 透传 Input 输入框组件全部属性 */