Skip to content

Commit

Permalink
Fix Aria label on sections (#5603)
Browse files Browse the repository at this point in the history
  • Loading branch information
snowystinger authored Dec 19, 2023
1 parent 125d65c commit 1193073
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/react-aria-components/src/ListBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ function ListBoxSection<T>({section, className, style}: ListBoxSectionProps<T>)
let [headingRef, heading] = useSlot();
let {headingProps, groupProps} = useListBoxSection({
heading,
'aria-label': section['aria-label'] ?? undefined
'aria-label': section.props['aria-label'] ?? undefined
});

let children = useCachedChildren({
Expand Down
3 changes: 1 addition & 2 deletions packages/react-aria-components/stories/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ export const ListBoxSections = () => (
<MyListBoxItem>Baz</MyListBoxItem>
</Section>
<Separator style={{borderTop: '1px solid gray', margin: '2px 5px'}} />
<Section className={styles.group}>
<Header style={{fontSize: '1.2em'}}>Section 1</Header>
<Section className={styles.group} aria-label="Section 2">
<MyListBoxItem>Foo</MyListBoxItem>
<MyListBoxItem>Bar</MyListBoxItem>
<MyListBoxItem>Baz</MyListBoxItem>
Expand Down
4 changes: 2 additions & 2 deletions packages/react-aria-components/test/ListBox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ describe('ListBox', () => {
<ListBoxItem id="tomato">Tomato</ListBoxItem>
<ListBoxItem id="onion">Onion</ListBoxItem>
</Section>
<Section data-test-prop="test-section-2">
<Header>Protein</Header>
<Section data-test-prop="test-section-2" aria-label="Protein">
<ListBoxItem id="ham">Ham</ListBoxItem>
<ListBoxItem id="tuna">Tuna</ListBoxItem>
<ListBoxItem id="tofu">Tofu</ListBoxItem>
Expand All @@ -157,6 +156,7 @@ describe('ListBox', () => {

expect(groups[0]).toHaveAttribute('aria-labelledby');
expect(document.getElementById(groups[0].getAttribute('aria-labelledby'))).toHaveTextContent('Veggies');
expect(groups[1].getAttribute('aria-label')).toEqual('Protein');

expect(groups[0]).toHaveAttribute('data-test-prop', 'test-section-1');
expect(groups[1]).toHaveAttribute('data-test-prop', 'test-section-2');
Expand Down

1 comment on commit 1193073

@rspbot
Copy link

@rspbot rspbot commented on 1193073 Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.