Skip to content

Commit f28aba6

Browse files
authored
fix: Handle the case where the user deletes when there are no tags in a Multiselect (#1075)
1 parent 1e3915c commit f28aba6

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

packages/react-widgets/src/FocusListContext.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface FocusProps {
2626
}
2727

2828
export interface FocusList<TDataItem = unknown> {
29+
size(): number;
2930
focus: (el: HTMLElement | null | undefined) => void
3031
first: () => HTMLElement | undefined
3132
last: () => HTMLElement | undefined
@@ -103,6 +104,10 @@ export const useFocusList = <TDataItem>({
103104

104105
const list: any = useMemo(() => {
105106
return {
107+
size() {
108+
const [items] = get();
109+
return items.length;
110+
},
106111
get,
107112
toDataItem: (el: HTMLElement) => map.get(el),
108113

packages/react-widgets/src/Multiselect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ const Multiselect: Multiselect = React.forwardRef(function Multiselect<
383383
*/
384384

385385
const handleDelete = (dataItem: TDataItem, event: React.SyntheticEvent) => {
386-
if (isDisabled || readOnly) return
386+
if (isDisabled || readOnly || tagList.size() === 0) return
387387
focus()
388388
change(dataItem, event, REMOVE)
389389
}

0 commit comments

Comments
 (0)