@@ -22,6 +22,7 @@ import {
2222import { Checkbox as AriaCheckbox , CheckboxButton , CheckboxField } from '../src/Checkbox' ;
2323import { Button } from '../src/Button' ;
2424import { Collection } from 'react-aria/Collection' ;
25+ import { ComboBox } from '../src/ComboBox' ;
2526import { Dialog , DialogTrigger } from '../src/Dialog' ;
2627import { DropIndicator , useDragAndDrop } from '../src/useDragAndDrop' ;
2728import { getFocusableTreeWalker } from 'react-aria/private/focus/FocusScope' ;
@@ -33,13 +34,17 @@ import {
3334 GridListSection
3435} from '../src/GridList' ;
3536import { GridListLoadMoreItem } from '../src/GridList' ;
37+ import { Input } from '../src/Input' ;
3638import { installPointerEvent , User } from '@react-aria/test-utils' ;
3739import { Label } from '../src/Label' ;
40+ import { ListBox , ListBoxItem } from '../src/ListBox' ;
3841import { ListLayout } from 'react-stately/useVirtualizerState' ;
3942import { Modal } from '../src/Modal' ;
43+ import { Popover } from '../src/Popover' ;
4044import React from 'react' ;
4145import { RouterProvider } from 'react-aria/private/utils/openLink' ;
4246import { Tag , TagGroup , TagList } from '../src/TagGroup' ;
47+ import { Toolbar } from '../src/Toolbar' ;
4348import userEvent from '@testing-library/user-event' ;
4449import { Virtualizer } from '../src/Virtualizer' ;
4550
@@ -2002,5 +2007,79 @@ describe('GridList', () => {
20022007 expect ( new Set ( onSelectionChange . mock . calls [ 0 ] [ 0 ] ) ) . toEqual ( new Set ( [ 'item1' ] ) ) ;
20032008 }
20042009 ) ;
2010+
2011+ it . each ( [
2012+ [ 'keyboardNavigationBehavior="tab"' , { keyboardNavigationBehavior : 'tab' } ] ,
2013+ [ 'layout="grid"' , { layout : 'grid' } ]
2014+ ] ) (
2015+ 'should exit the grid when tabbing from a combobox or toolbar, not focus the next row (%s)' ,
2016+ async ( _ , listProps ) => {
2017+ let { getByRole} = render (
2018+ < div >
2019+ < input aria-label = "before" />
2020+ < GridList aria-label = "Test" { ...listProps } >
2021+ < GridListItem id = "1" textValue = "combobox" >
2022+ < ComboBox aria-label = "combobox" >
2023+ < Input />
2024+ < Button > ▼</ Button >
2025+ < Popover >
2026+ < ListBox >
2027+ < ListBoxItem > Foo</ ListBoxItem >
2028+ < ListBoxItem > Bar</ ListBoxItem >
2029+ </ ListBox >
2030+ </ Popover >
2031+ </ ComboBox >
2032+ </ GridListItem >
2033+ < GridListItem id = "2" textValue = "formatting" >
2034+ < Toolbar aria-label = "formatting" >
2035+ < Button > Bold</ Button >
2036+ < Button > Italic</ Button >
2037+ </ Toolbar >
2038+ </ GridListItem >
2039+ < GridListItem id = "3" textValue = "plain input row" >
2040+ < input aria-label = "row 2 input" />
2041+ </ GridListItem >
2042+ </ GridList >
2043+ < input aria-label = "after" />
2044+ </ div >
2045+ ) ;
2046+
2047+ let combobox = getByRole ( 'combobox' ) ;
2048+ let afterInput = getByRole ( 'textbox' , { name : 'after' } ) ;
2049+ let boldButton = getByRole ( 'button' , { name : 'Bold' } ) ;
2050+ let row2Input = getByRole ( 'textbox' , { name : 'row 2 input' } ) ;
2051+
2052+ let gridListTester = testUtilUser . createTester ( 'GridList' , { root : getByRole ( 'grid' ) } ) ;
2053+ let rows = gridListTester . getRows ( ) ;
2054+
2055+ await user . tab ( ) ;
2056+ await user . tab ( ) ;
2057+ await user . tab ( ) ;
2058+ expect ( document . activeElement ) . toBe ( combobox ) ;
2059+
2060+ await user . tab ( ) ;
2061+ expect ( document . activeElement ) . toBe ( afterInput ) ;
2062+
2063+ // note that shift tabbing move focus back to gridlist item not the combobox itself,
2064+ // will need to look into this later
2065+ await user . tab ( { shift : true } ) ;
2066+ expect ( document . activeElement ) . toBe ( rows [ 0 ] ) ;
2067+ await user . keyboard ( listProps . layout === 'grid' ? '{ArrowRight}' : '{ArrowDown}' ) ;
2068+ expect ( document . activeElement ) . toBe ( rows [ 1 ] ) ;
2069+ await user . tab ( ) ;
2070+ expect ( document . activeElement ) . toBe ( boldButton ) ;
2071+ await user . tab ( ) ;
2072+ expect ( document . activeElement ) . toBe ( afterInput ) ;
2073+
2074+ await user . tab ( { shift : true } ) ;
2075+ expect ( document . activeElement ) . toBe ( rows [ 1 ] ) ;
2076+ await user . keyboard ( listProps . layout === 'grid' ? '{ArrowRight}' : '{ArrowDown}' ) ;
2077+ expect ( document . activeElement ) . toBe ( rows [ 2 ] ) ;
2078+ await user . tab ( ) ;
2079+ expect ( document . activeElement ) . toBe ( row2Input ) ;
2080+ await user . tab ( ) ;
2081+ expect ( document . activeElement ) . toBe ( afterInput ) ;
2082+ }
2083+ ) ;
20052084 } ) ;
20062085} ) ;
0 commit comments