File tree Expand file tree Collapse file tree 3 files changed +39
-1
lines changed
packages/react/src/ActionList Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @primer/react ' : minor
3+ ---
4+
5+ Add support to ActionList for 'tablist' and 'tab' roles
Original file line number Diff line number Diff line change @@ -354,4 +354,31 @@ describe('ActionList.Item', () => {
354354 expect ( item ) . toHaveTextContent ( 'Item, Description' )
355355 expect ( item ) . toHaveAccessibleDescription ( 'Description' )
356356 } )
357+
358+ it ( 'should add role="tab" when ActionList has role="tablist"' , ( ) => {
359+ const { getAllByRole} = HTMLRender (
360+ < ActionList role = "tablist" >
361+ < ActionList . Item > Tab 1</ ActionList . Item >
362+ < ActionList . Item > Tab 2</ ActionList . Item >
363+ < ActionList . Item > Tab 3</ ActionList . Item >
364+ </ ActionList > ,
365+ )
366+ const tabs = getAllByRole ( 'tab' )
367+ expect ( tabs [ 0 ] ) . toBeInTheDocument ( )
368+ expect ( tabs ) . toHaveLength ( 3 )
369+ } )
370+
371+ it ( 'should allow role="tab" on the li element' , ( ) => {
372+ const { getAllByRole} = HTMLRender (
373+ < ActionList role = "tablist" >
374+ < ActionList . Item role = "tab" > Tab 1</ ActionList . Item >
375+ < ActionList . Item role = "tab" > Tab 2</ ActionList . Item >
376+ < ActionList . Item role = "tab" > Tab 3</ ActionList . Item >
377+ </ ActionList > ,
378+ )
379+ const tabs = getAllByRole ( 'tab' )
380+ expect ( tabs [ 0 ] ) . toBeInTheDocument ( )
381+ expect ( tabs [ 0 ] . nodeType ) . toBe ( Node . ELEMENT_NODE )
382+ expect ( tabs ) . toHaveLength ( 3 )
383+ } )
357384} )
Original file line number Diff line number Diff line change @@ -123,6 +123,8 @@ const UnwrappedItem = <As extends React.ElementType = 'li'>(
123123 else inferredItemRole = 'menuitem'
124124 } else if ( listRole === 'listbox' ) {
125125 if ( selectionVariant !== undefined && ! role ) inferredItemRole = 'option'
126+ } else if ( listRole === 'tablist' ) {
127+ inferredItemRole = 'tab'
126128 }
127129
128130 const itemRole = role || inferredItemRole
@@ -142,7 +144,11 @@ const UnwrappedItem = <As extends React.ElementType = 'li'>(
142144 const itemSelectionAttribute = selectionAttribute || inferredSelectionAttribute
143145 // Ensures ActionList.Item retains list item semantics if a valid ARIA role is applied, or if item is inactive
144146 const listItemSemantics =
145- role === 'option' || role === 'menuitem' || role === 'menuitemradio' || role === 'menuitemcheckbox'
147+ itemRole === 'option' ||
148+ itemRole === 'menuitem' ||
149+ itemRole === 'menuitemradio' ||
150+ itemRole === 'menuitemcheckbox' ||
151+ itemRole === 'tab'
146152
147153 const listRoleTypes = [ 'listbox' , 'menu' , 'list' ]
148154 const listSemantics = ( listRole && listRoleTypes . includes ( listRole ) ) || inactive || listItemSemantics
You can’t perform that action at this time.
0 commit comments