From 9b9d6b36e9c4702e177688ad0894327bfd8705d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZhuoYang=20Wu=28=E9=98=BF=E7=A6=BB=29?= Date: Fri, 15 Mar 2024 12:58:03 +0800 Subject: [PATCH] fix(select): fix onRemove method does not work (#2802) --- .vscode/settings.json | 2 +- src/select/_example/multiple.jsx | 20 ++++++++++++++++++-- src/select/base/Select.tsx | 6 ++++++ src/select/type.ts | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 6164b32ccd..beeb08a71e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -22,7 +22,7 @@ "editor.defaultFormatter": "esbenp.prettier-vscode" }, "editor.codeActionsOnSave": { - "source.fixAll.eslint": true, + "source.fixAll.eslint": "explicit" }, "cSpell.words": ["activable", "actived", "borderless", "Cascader", "Popconfirm", "Swiper", "tdesign"] } diff --git a/src/select/_example/multiple.jsx b/src/select/_example/multiple.jsx index 8f223b9ca0..02c5e7f322 100644 --- a/src/select/_example/multiple.jsx +++ b/src/select/_example/multiple.jsx @@ -35,8 +35,24 @@ const MultipleSelect = () => { return ( - + { + console.log('onRemove', options); + }} + > {options2.map((item) => ( ))} diff --git a/src/select/base/Select.tsx b/src/select/base/Select.tsx index 4d238e5a10..2dad56f6bf 100644 --- a/src/select/base/Select.tsx +++ b/src/select/base/Select.tsx @@ -350,6 +350,12 @@ const Select = forwardRefWithStatics( const selectedOptions = getSelectedOptions(values, multiple, valueType, keys, tmpPropOptions); onChange(values, { e, selectedOptions, trigger: 'uncheck' }); tagProps?.onClose?.({ e }); + + onRemove?.({ + value: value[key], + data: { label: v, value: value[key] }, + e, + }); }} > {v} diff --git a/src/select/type.ts b/src/select/type.ts index 1f32030582..777027a271 100644 --- a/src/select/type.ts +++ b/src/select/type.ts @@ -317,7 +317,7 @@ export type SelectValueChangeTrigger = 'clear' | 'tag-remove' | 'backspace' | 'c export interface SelectRemoveContext { value: string | number; data: T; - e: MouseEvent | KeyboardEvent; + e: MouseEvent | KeyboardEvent; } export type SelectOption = TdOptionProps | SelectOptionGroup | PlainObject;