Repository navigation
feat: add focus events to GridListItem - #10822
Conversation
|
seems like some tests are failing, could you take a look? |
|
Thanks for mentioning that |
snowystinger
left a comment
There was a problem hiding this comment.
In general looks good, couple nitpicks
|
|
||
| it.each(['onFocus', 'onBlur', 'onFocusChange'])( | ||
| 'should support %s independently', | ||
| async prop => { | ||
| let handler = jest.fn(); | ||
| let {getByRole} = render( | ||
| <> | ||
| <GridList aria-label="Test"> | ||
| <GridListItem {...{[prop]: handler}}>Cat</GridListItem> | ||
| </GridList> | ||
| <button>After</button> | ||
| </> | ||
| ); | ||
| await user.tab(); | ||
| expect(document.activeElement).toBe(getByRole('row')); | ||
| await user.tab(); | ||
| expect(document.activeElement).toBe(getByRole('button', {name: 'After'})); | ||
| expect(handler).toHaveBeenCalledTimes(prop === 'onFocusChange' ? 2 : 1); | ||
| } | ||
| ); |
There was a problem hiding this comment.
| it.each(['onFocus', 'onBlur', 'onFocusChange'])( | |
| 'should support %s independently', | |
| async prop => { | |
| let handler = jest.fn(); | |
| let {getByRole} = render( | |
| <> | |
| <GridList aria-label="Test"> | |
| <GridListItem {...{[prop]: handler}}>Cat</GridListItem> | |
| </GridList> | |
| <button>After</button> | |
| </> | |
| ); | |
| await user.tab(); | |
| expect(document.activeElement).toBe(getByRole('row')); | |
| await user.tab(); | |
| expect(document.activeElement).toBe(getByRole('button', {name: 'After'})); | |
| expect(handler).toHaveBeenCalledTimes(prop === 'onFocusChange' ? 2 : 1); | |
| } | |
| ); |
This isn't really providing value in addition to the first test, unless you ran into a case where this wasn't working, in which case make it closer to the real life case that caused it
|
|
||
| it('should not report focus for disabled items skipped during navigation', async () => { | ||
| let onDisabledFocusChange = jest.fn(); | ||
| let onFocusChange = jest.fn(); | ||
| let {getAllByRole} = render( | ||
| <GridList aria-label="Test" disabledKeys={['dog']}> | ||
| <GridListItem id="cat" onFocusChange={onFocusChange}> | ||
| Cat | ||
| </GridListItem> | ||
| <GridListItem id="dog" onFocusChange={onDisabledFocusChange}> | ||
| Dog | ||
| </GridListItem> | ||
| <GridListItem id="kangaroo" onFocusChange={onFocusChange}> | ||
| Kangaroo | ||
| </GridListItem> | ||
| </GridList> | ||
| ); | ||
| let rows = getAllByRole('row'); | ||
| await user.tab(); | ||
| await user.keyboard('{ArrowDown}'); | ||
| expect(document.activeElement).toBe(rows[2]); | ||
| expect(onFocusChange.mock.calls).toEqual([[true], [false], [true]]); | ||
| expect(onDisabledFocusChange).not.toHaveBeenCalled(); | ||
| }); |
There was a problem hiding this comment.
| it('should not report focus for disabled items skipped during navigation', async () => { | |
| let onDisabledFocusChange = jest.fn(); | |
| let onFocusChange = jest.fn(); | |
| let {getAllByRole} = render( | |
| <GridList aria-label="Test" disabledKeys={['dog']}> | |
| <GridListItem id="cat" onFocusChange={onFocusChange}> | |
| Cat | |
| </GridListItem> | |
| <GridListItem id="dog" onFocusChange={onDisabledFocusChange}> | |
| Dog | |
| </GridListItem> | |
| <GridListItem id="kangaroo" onFocusChange={onFocusChange}> | |
| Kangaroo | |
| </GridListItem> | |
| </GridList> | |
| ); | |
| let rows = getAllByRole('row'); | |
| await user.tab(); | |
| await user.keyboard('{ArrowDown}'); | |
| expect(document.activeElement).toBe(rows[2]); | |
| expect(onFocusChange.mock.calls).toEqual([[true], [false], [true]]); | |
| expect(onDisabledFocusChange).not.toHaveBeenCalled(); | |
| }); |
not providing value, we have tests that show that disabled elements are skipped
|
Thanks for the feedback |
Adds
onFocus,onBlur, andonFocusChangetoGridListItemfor mouse and keyboard interaction, using the existinguseFocushook. Includes regression tests and an interactive Storybook example.Part of #6460 (GridListItem only; table Row is outside this change).
✅ Pull Request Checklist:
API prop documentation derives from the inherited
FocusEventstype; no separate documentation files were changed.📝 Test Instructions:
yarn startand open React Aria Components → GridList → Item Focus Events.yarn test packages/react-aria-components/test/GridList.test.js --runInBand.Validation: all 110 GridList tests, repository lint, and all 74 SSR tests passed (SSR used a 120-second local timeout). The full unit run had 16 failing tests and the browser run had two failures. All reproduced with the original GridList source: unit failures involve Windows locale/path handling and an interactive codemod fixture; browser failures involve TokenField word deletion in Chromium and Firefox.
🧢 Your Project:
Independent open-source contribution.