File tree Expand file tree Collapse file tree 3 files changed +45
-1
lines changed
@react-spectrum/tabs/test
react-aria-components/test Expand file tree Collapse file tree 3 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ export function useTab<T>(
58
58
let { tabIndex} = itemProps ;
59
59
60
60
let item = state . collection . getItem ( key ) ;
61
- let domProps = filterDOMProps ( item ?. props , { isLink : ! ! item ?. props ?. href } ) ;
61
+ let domProps = filterDOMProps ( item ?. props , { isLink : ! ! item ?. props ?. href , labelable : true } ) ;
62
62
delete domProps . id ;
63
63
64
64
return {
Original file line number Diff line number Diff line change @@ -782,6 +782,30 @@ describe('Tabs', function () {
782
782
expect ( tabPanelInput . value ) . toBe ( '' ) ;
783
783
} ) ;
784
784
785
+ it ( 'Tabs can be aria-labelled' , ( ) => {
786
+ let { getAllByRole, getByLabelText} = render (
787
+ < Provider theme = { theme } >
788
+ < Tabs aria-label = "Tab Example" maxWidth = { 500 } >
789
+ < TabList >
790
+ < Item aria-label = "Foo" > Tab 1</ Item >
791
+ < Item > Tab 2</ Item >
792
+ </ TabList >
793
+ < TabPanels >
794
+ < Item >
795
+ < input data-testid = "panel1_input" />
796
+ </ Item >
797
+ < Item >
798
+ < input disabled data-testid = "panel2_input" />
799
+ </ Item >
800
+ </ TabPanels >
801
+ </ Tabs >
802
+ </ Provider >
803
+ ) ;
804
+
805
+ let tab = getByLabelText ( 'Foo' ) ;
806
+ expect ( tab ) . toBe ( getAllByRole ( 'tab' ) [ 0 ] ) ;
807
+ } ) ;
808
+
785
809
it ( 'supports custom props for parent tabs element' , function ( ) {
786
810
let { getByTestId} = renderComponent ( { 'data-testid' : 'tabs1' } ) ;
787
811
let tabs = getByTestId ( 'tabs1' ) ;
Original file line number Diff line number Diff line change @@ -313,4 +313,24 @@ describe('Tabs', () => {
313
313
fireEvent . keyDown ( tabs [ 1 ] , { key : 'ArrowRight' } ) ;
314
314
expect ( tabs [ 2 ] ) . toHaveAttribute ( 'aria-selected' , 'true' ) ;
315
315
} ) ;
316
+
317
+ it ( 'should render tab with aria-label' , ( ) => {
318
+ let { getAllByRole} = render (
319
+ < Tabs >
320
+ < TabList >
321
+ < Tab id = "a" aria-label = "Tab A" > A</ Tab >
322
+ < Tab id = "b" aria-label = "Tab B" > B</ Tab >
323
+ < Tab id = "c" aria-label = "Tab C" > C</ Tab >
324
+ </ TabList >
325
+ < TabPanel id = "a" > A</ TabPanel >
326
+ < TabPanel id = "b" > B</ TabPanel >
327
+ < TabPanel id = "c" > C</ TabPanel >
328
+ </ Tabs >
329
+ ) ;
330
+
331
+ let tabs = getAllByRole ( 'tab' ) ;
332
+ expect ( tabs [ 0 ] ) . toHaveAttribute ( 'aria-label' , 'Tab A' ) ;
333
+ expect ( tabs [ 1 ] ) . toHaveAttribute ( 'aria-label' , 'Tab B' ) ;
334
+ expect ( tabs [ 2 ] ) . toHaveAttribute ( 'aria-label' , 'Tab C' ) ;
335
+ } ) ;
316
336
} ) ;
You can’t perform that action at this time.
0 commit comments