-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NavigableContainer: use code instead of keyCode for keyboard events #43606
Changes from all commits
e90926f
63dc6be
8b72831
5cbbc56
b7f33e9
24001b5
37be0d4
d1455f7
9c38277
d5b3ad0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,7 +99,14 @@ class NavigableContainer extends Component { | |
// 'handling' the event, as voiceover will try to use arrow keys | ||
// for highlighting text. | ||
const targetRole = event.target.getAttribute( 'role' ); | ||
if ( MENU_ITEM_ROLES.includes( targetRole ) ) { | ||
const targetHasMenuItemRole = | ||
MENU_ITEM_ROLES.includes( targetRole ); | ||
|
||
// `preventDefault()` on tab to avoid having the browser move the focus | ||
// after this component has already moved it. | ||
const isTab = event.code === 'Tab'; | ||
|
||
if ( targetHasMenuItemRole || isTab ) { | ||
Comment on lines
+102
to
+109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, so if I understand correctly, this component kind of assumes that all navigable children will have a menuitem* role? 🤔 So in a NavigableMenu, the "prevent scroll containers from scrolling" part will not work if children don't have a menuitem* role. This seems like an important detail that is yet undocumented. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like it — it was a behaviour that existed before this PR, and it was not documented (it looks like I will add some documentation about it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 9c38277 I explicitly didn't mention the |
||
event.preventDefault(); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { NavigableMenu } from '..'; | ||
|
||
export default { | ||
title: 'Components/NavigableMenu', | ||
component: NavigableMenu, | ||
argTypes: { | ||
children: { type: null }, | ||
cycle: { | ||
type: 'boolean', | ||
}, | ||
onNavigate: { action: 'onNavigate' }, | ||
orientation: { | ||
options: [ 'horizontal', 'vertical' ], | ||
control: { type: 'radio' }, | ||
}, | ||
}, | ||
}; | ||
|
||
export const Default = ( args ) => { | ||
return ( | ||
<> | ||
<button>Before navigable menu</button> | ||
<NavigableMenu | ||
{ ...args } | ||
style={ { | ||
margin: '32px 0', | ||
padding: '16px', | ||
border: '1px solid black', | ||
} } | ||
> | ||
<div role="menuitem">Item 1 (non-tabbable, non-focusable)</div> | ||
<button role="menuitem">Item 2 (tabbable, focusable)</button> | ||
<button role="menuitem" disabled> | ||
Item 3 (disabled, therefore non-tabbable and not-focusable) | ||
</button> | ||
<span role="menuitem" tabIndex={ -1 }> | ||
Item 4 (non-tabbable, non-focusable) | ||
</span> | ||
<div role="menuitem" tabIndex={ 0 }> | ||
Item 5 (tabbable, focusable) | ||
</div> | ||
</NavigableMenu> | ||
<button>After navigable menu</button> | ||
</> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { TabbableContainer } from '..'; | ||
|
||
export default { | ||
title: 'Components/TabbableContainer', | ||
component: TabbableContainer, | ||
argTypes: { | ||
children: { type: null }, | ||
cycle: { | ||
type: 'boolean', | ||
}, | ||
onNavigate: { action: 'onNavigate' }, | ||
}, | ||
}; | ||
|
||
export const Default = ( args ) => { | ||
return ( | ||
<> | ||
<button>Before tabbable container</button> | ||
<TabbableContainer | ||
{ ...args } | ||
style={ { | ||
margin: '32px 0', | ||
padding: '16px', | ||
border: '1px solid black', | ||
} } | ||
> | ||
<button>Item 1</button> | ||
<button>Item 2</button> | ||
<button disabled>Item 3 (disabled)</button> | ||
<button tabIndex={ -1 }>Item 4 (non-tabbable)</button> | ||
<button tabIndex={ 0 }>Item 5</button> | ||
<button>Item 6</button> | ||
</TabbableContainer> | ||
<button>After tabbable container</button> | ||
</> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from changing the
keyCode
s tocode
s, this is the only other runtime change and it's a bug fix (see code comments and PR description for more details)