Skip to content

Commit 75df3f0

Browse files
fix(SelectInput): onTagChange not work when tagInputProps.tagProps.onClose (#4070)
* fix(SelectInput): `tagInputProps.tagProps` not work * chore: stash changelog [ci skip] * fix(Select): `props.tagInputProps?.tagProps` not work * fix(Tag): `closeable` not work * chore: update changelog --------- Co-authored-by: tdesign-bot <tdesign@tencent.com>
1 parent a260dbf commit 75df3f0

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

packages/components/select-input/useMultiple.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ export default function useMultiple(props: SelectInputProps) {
110110
if (context?.trigger === 'enter' || context?.trigger === 'blur') return;
111111
setTInputValue(val, { trigger: context.trigger, e: context.e });
112112
}}
113-
tagProps={props.tagProps}
114113
onClear={p.onInnerClear}
115114
// [Important Info]: SelectInput.blur is not equal to TagInput, example: click popup panel
116115
onFocus={handleFocus}
117116
onBlur={handleBlur}
118117
{...props.tagInputProps}
118+
tagProps={{ ...props.tagProps, ...props.tagInputProps?.tagProps }}
119119
inputProps={{
120120
...props.inputProps,
121121
readOnly: !props.allowInput || readOnly,

packages/components/select/base/Select.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ const Select = forwardRefWithStatics(
8787
panelTopContent,
8888
selectInputProps,
8989
tagInputProps,
90-
tagProps,
9190
scroll,
9291
suffixIcon,
9392
label,
@@ -102,6 +101,7 @@ const Select = forwardRefWithStatics(
102101
onPopupVisibleChange,
103102
} = props;
104103
const readOnly = props.readOnly || props.readonly;
104+
const tagProps = { ...props.tagProps, ...props.tagInputProps?.tagProps };
105105

106106
const [value, onChange] = useControlled(props, 'value', props.onChange);
107107

packages/components/tag-input/useTagList.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,19 @@ export default function useTagList(props: TagInputProps) {
8080
? [<Fragment key="display-node">{displayNode}</Fragment>]
8181
: newList?.map((item, index) => {
8282
const tagContent = isFunction(tag) ? tag({ value: item }) : tag;
83+
const handleClose = (context) => {
84+
tagProps?.onClose?.(context);
85+
onClose({ e: context?.e, index });
86+
};
8387
return (
8488
<Tag
8589
key={index}
8690
size={size}
8791
disabled={disabled}
88-
onClose={(context) => onClose({ e: context.e, index })}
8992
closable={!readOnly && !disabled}
9093
{...getDragProps?.(index, item)}
9194
{...tagProps}
95+
onClose={handleClose}
9296
>
9397
{tagContent ?? item}
9498
</Tag>

packages/components/tag/Tag.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const TagFunction: ForwardRefRenderFunction<HTMLDivElement, TagProps> = (
7171
className,
7272
);
7373

74-
const TagCloseIcon = () => {
74+
const tagCloseIcon = useMemo(() => {
7575
const iconNode = tagConfig?.closeIcon ? tagConfig.closeIcon : <CloseIcon />;
7676
if (React.isValidElement(iconNode)) {
7777
const element = iconNode as React.ReactElement<any>;
@@ -84,7 +84,8 @@ export const TagFunction: ForwardRefRenderFunction<HTMLDivElement, TagProps> = (
8484
className: classNames(element.props?.className, `${tagClassPrefix}__icon-close`),
8585
});
8686
}
87-
};
87+
return null;
88+
}, [CloseIcon, disabled, tagClassPrefix, tagConfig.closeIcon, onClose]);
8889

8990
const title = useMemo(() => {
9091
if (Reflect.has(props, 'title')) return titleAttr;
@@ -143,7 +144,7 @@ export const TagFunction: ForwardRefRenderFunction<HTMLDivElement, TagProps> = (
143144
<span className={maxWidth ? `${tagClassPrefix}--text` : undefined} style={getTextStyle} {...titleAttribute}>
144145
{children ?? content}
145146
</span>
146-
{closable && !disabled && <TagCloseIcon />}
147+
{closable && !disabled && tagCloseIcon}
147148
</>
148149
</div>
149150
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
pr_number: 4070
3+
contributor: RylanBot
4+
---
5+
6+
- fix(SelectInput): 修复 `1.16.0` 版本的修复导致点击 `closable` 图标时无法清除选项的问题 @RylanBot ([#4070](https://github.com/Tencent/tdesign-react/pull/4070))
7+
- fix(SelectInput): 修复传入 `tagInputProps.tagProps.onClose` 时,`onTagChange` 不生效的问题 @RylanBot ([#4070](https://github.com/Tencent/tdesign-react/pull/4070))
8+
- fix(Select): 修复 `tagInputProps.tagProps` 不生效的问题 @RylanBot ([#4070](https://github.com/Tencent/tdesign-react/pull/4070))

0 commit comments

Comments
 (0)