Skip to content

Commit b29dba0

Browse files
authored
Ensure Section has [data-rac] data attribute (#6452)
1 parent d7fc932 commit b29dba0

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

packages/react-aria-components/src/ListBox.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,18 @@ function ListBoxSection<T extends object>(props: SectionProps<T>, ref: Forwarded
266266
heading,
267267
'aria-label': props['aria-label'] ?? undefined
268268
});
269+
let renderProps = useRenderProps({
270+
defaultClassName: 'react-aria-Section',
271+
className: props.className,
272+
style: props.style,
273+
values: {}
274+
});
269275

270276
return (
271277
<section
272278
{...filterDOMProps(props as any)}
273279
{...groupProps}
274-
className={props?.className || 'react-aria-Section'}
275-
style={props?.style}
280+
{...renderProps}
276281
ref={ref}>
277282
<HeaderContext.Provider value={{...headingProps, ref: headingRef}}>
278283
<CollectionChildren collection={state.collection} parent={section} />

packages/react-aria-components/src/Menu.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,18 @@ function MenuSection<T extends object>(props: SectionProps<T>, ref: ForwardedRef
230230
heading,
231231
'aria-label': section.props['aria-label'] ?? undefined
232232
});
233+
let renderProps = useRenderProps({
234+
defaultClassName: 'react-aria-Section',
235+
className: section.props?.className,
236+
style: section.props?.style,
237+
values: {}
238+
});
233239

234240
return (
235241
<section
236242
{...filterDOMProps(props as any)}
237243
{...groupProps}
238-
className={section.props?.className || 'react-aria-Section'}
239-
style={section.props?.style}
244+
{...renderProps}
240245
ref={ref}>
241246
<HeaderContext.Provider value={{...headingProps, ref: headingRef}}>
242247
<CollectionChildren collection={state.collection} parent={section} />

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,32 @@ describe('ListBox', () => {
6767
jest.restoreAllMocks();
6868
});
6969

70+
it('should have the base set of aria and data attributes', () => {
71+
let {getByRole, getAllByRole} = render(
72+
<ListBox aria-label="Animals">
73+
<ListBoxItem id="cat">Cat</ListBoxItem>
74+
<ListBoxItem id="dog">Dog</ListBoxItem>
75+
<ListBoxItem id="kangaroo">Kangaroo</ListBoxItem>
76+
<Section>
77+
<Header>Fish</Header>
78+
<ListBoxItem id="salmon">Salmon</ListBoxItem>
79+
<ListBoxItem id="tuna">Tuna</ListBoxItem>
80+
<ListBoxItem id="cod">Cod</ListBoxItem>
81+
</Section>
82+
</ListBox>
83+
);
84+
let menu = getByRole('listbox');
85+
expect(menu).toHaveAttribute('data-rac');
86+
87+
for (let group of getAllByRole('group')) {
88+
expect(group).toHaveAttribute('data-rac');
89+
}
90+
91+
for (let option of getAllByRole('option')) {
92+
expect(option).toHaveAttribute('data-rac');
93+
}
94+
});
95+
7096
it('should render with default classes', () => {
7197
let {getByRole, getAllByRole} = renderListbox();
7298
let listbox = getByRole('listbox');

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,26 @@ describe('Menu', () => {
6161
});
6262

6363
it('should have the base set of aria and data attributes', () => {
64-
let {getByRole, getAllByRole} = renderMenu();
64+
let {getByRole, getAllByRole} = render(
65+
<Menu aria-label="Animals">
66+
<MenuItem id="cat">Cat</MenuItem>
67+
<MenuItem id="dog">Dog</MenuItem>
68+
<MenuItem id="kangaroo">Kangaroo</MenuItem>
69+
<Section>
70+
<Header>Fish</Header>
71+
<MenuItem id="salmon">Salmon</MenuItem>
72+
<MenuItem id="tuna">Tuna</MenuItem>
73+
<MenuItem id="cod">Cod</MenuItem>
74+
</Section>
75+
</Menu>
76+
);
6577
let menu = getByRole('menu');
6678
expect(menu).toHaveAttribute('data-rac');
6779

80+
for (let group of getAllByRole('group')) {
81+
expect(group).toHaveAttribute('data-rac');
82+
}
83+
6884
for (let menuitem of getAllByRole('menuitem')) {
6985
expect(menuitem).toHaveAttribute('data-rac');
7086
}

0 commit comments

Comments
 (0)