Skip to content

Commit 140ea0b

Browse files
authored
fix: pass style and labels to TabPanels (adobe#9562)
* fix: make sure to pass style and labels on TabPanels * fix space
1 parent b4382b0 commit 140ea0b

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,14 +394,15 @@ export const TabPanels = /*#__PURE__*/ createHideableComponent(function TabPanel
394394
prevSize.current = ref.current.getBoundingClientRect();
395395
}
396396

397-
let DOMProps = filterDOMProps(props, {global: true});
397+
let DOMProps = filterDOMProps(props, {labelable: true, global: true});
398398
delete DOMProps.id;
399399

400400
return (
401401
<dom.div
402402
render={props.render}
403403
{...DOMProps}
404404
ref={ref}
405+
style={props.style}
405406
className={props.className || 'react-aria-TabPanels'}>
406407
<Collection {...props} />
407408
</dom.div>

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,42 @@ describe('Tabs', () => {
649649
expect(tabs[2]).toHaveAttribute('aria-selected', 'true');
650650
});
651651

652+
it('should support tabpanels with aria-labels', () => {
653+
let {getByTestId} = render(
654+
<Tabs>
655+
<TabList aria-label="test">
656+
<Tab id="a">A</Tab>
657+
<Tab id="b">B</Tab>
658+
</TabList>
659+
<TabPanels aria-label="test" data-testid="tabpanels">
660+
<TabPanel id="a">A</TabPanel>
661+
<TabPanel id="b">B</TabPanel>
662+
</TabPanels>
663+
</Tabs>
664+
);
665+
666+
let tabPanels = getByTestId('tabpanels');
667+
expect(tabPanels).toHaveAttribute('aria-label', 'test');
668+
});
669+
670+
it('should support tabpanels with custom styles', () => {
671+
let {getByTestId} = render(
672+
<Tabs>
673+
<TabList aria-label="test">
674+
<Tab id="a">A</Tab>
675+
<Tab id="b">B</Tab>
676+
</TabList>
677+
<TabPanels style={{width: '100px'}} data-testid="tabpanels">
678+
<TabPanel id="a">A</TabPanel>
679+
<TabPanel id="b">B</TabPanel>
680+
</TabPanels>
681+
</Tabs>
682+
);
683+
684+
let tabPanels = getByTestId('tabpanels');
685+
expect(tabPanels).toHaveStyle({width: '100px'});
686+
});
687+
652688
it('supports tooltips', async function () {
653689
let {getByRole, getAllByRole} = render(
654690
<Tabs>

0 commit comments

Comments
 (0)