Skip to content

Commit 42e5a2c

Browse files
authored
fix: add role to react aria taggroup when empty (#8723)
* fix: add role to react aria taggroup when empty * add test
1 parent 7a0cb64 commit 42e5a2c

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

packages/@react-aria/tag/src/useTagGroup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export function useTagGroup<T>(props: AriaTagGroupOptions<T>, state: ListState<T
114114

115115
return {
116116
gridProps: mergeProps(gridProps, domProps, {
117-
role: state.collection.size ? 'grid' : null,
117+
role: state.collection.size ? 'grid' : 'group',
118118
'aria-atomic': false,
119119
'aria-relevant': 'additions',
120120
'aria-live': isFocusWithin ? 'polite' : 'off',

packages/react-aria-components/stories/TagGroup.stories.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,13 @@ export const TagGroupExampleWithRemove: Story = {
111111
</TagGroup>
112112
)
113113
};
114+
115+
export const EmptyTagGroup: Story = {
116+
render: (props: TagGroupProps) => (
117+
<TagGroup {...props} aria-label="Categories" >
118+
<TagList renderEmptyState={() => 'No categories.'}>
119+
{[]}
120+
</TagList>
121+
</TagGroup>
122+
)
123+
};

packages/react-aria-components/test/TagGroup.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ describe('TagGroup', () => {
306306
let grid = getByTestId('list');
307307
expect(grid).toHaveAttribute('data-empty', 'true');
308308
expect(grid).toHaveTextContent('No results');
309+
expect(grid).toHaveAttribute('role', 'group');
309310
});
310311

311312
it('supports tooltips', async function () {

0 commit comments

Comments
 (0)