Skip to content

Commit d61bc2a

Browse files
fix: Do not toggle "Show all" when all tags are manually selected (#1111)
Signed-off-by: Adhitya Mamallan <[email protected]>
1 parent aabebe6 commit d61bc2a

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

src/components/tag-filter/__tests__/tag-filter.test.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,6 @@ describe(TagFilter.name, () => {
8888
expect(mockOnChangeValues).toHaveBeenCalledWith([]);
8989
});
9090

91-
it('automatically toggles to "show all" (empty array) when the last tag is clicked and all tags become selected', async () => {
92-
const { user, mockOnChangeValues } = setup({
93-
values: ['opt1', 'opt2'],
94-
});
95-
96-
// Click the last tag to select all tags - should auto-toggle to empty array
97-
await user.click(screen.getByText('Option 3'));
98-
99-
expect(mockOnChangeValues).toHaveBeenCalledWith([]);
100-
});
101-
10291
it('does not render "Show all" tag when hideShowAll is true', () => {
10392
setup({
10493
hideShowAll: true,

src/components/tag-filter/tag-filter.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,13 @@ export default function TagFilter<T extends string>({
2424
const isShowAll = useMemo(() => values.length === 0, [values]);
2525

2626
const onChangeSingleValue = useCallback(
27-
(value: T) => {
28-
const newValues = values.includes(value)
29-
? values.filter((v) => v !== value)
30-
: [...values, value];
31-
32-
// If all tags are selected, automatically toggle to "show all" (empty array)
33-
const areAllTagsSelected = tagKeys.every((key) =>
34-
newValues.includes(key)
35-
);
36-
onChangeValues(areAllTagsSelected ? [] : newValues);
37-
},
38-
[values, onChangeValues, tagKeys]
27+
(value: T) =>
28+
onChangeValues(
29+
values.includes(value)
30+
? values.filter((v) => v !== value)
31+
: [...values, value]
32+
),
33+
[values, onChangeValues]
3934
);
4035

4136
return (

0 commit comments

Comments
 (0)