Skip to content

Commit

Permalink
Explore overriding role attributes to semantically indicate that we a…
Browse files Browse the repository at this point in the history
…re using approximating select/option
  • Loading branch information
andrewserong committed Dec 14, 2021
1 parent 216f9db commit 3e7af65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions packages/components/src/custom-select-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { __, sprintf } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { DropdownMenu, MenuGroup, MenuItem, VisuallyHidden } from '../';
import { DropdownMenu, MenuItem, VisuallyHidden } from '../';

const itemToString = ( item ) => item?.name;

Expand Down Expand Up @@ -61,6 +61,10 @@ export default function CustomSelectControlWithDropdownMenu( {
),
};

const menuProps = {
role: 'select',
};

return (
<div
className={ classnames(
Expand All @@ -85,17 +89,19 @@ export default function CustomSelectControlWithDropdownMenu( {
'components-custom-select-control__inner',
className
) }
menuProps={ menuProps }
popoverProps={ POPOVER_PROPS }
toggleProps={ toggleProps }
icon={ null }
noIcons={ true }
>
{ ( { isOpen, onClose } ) =>
isOpen && (
<MenuGroup>
<>
{ items.map( ( item, index ) => (
<MenuItem
key={ index }
role="option"
{ ...{
className: classnames(
item.className,
Expand Down Expand Up @@ -126,7 +132,7 @@ export default function CustomSelectControlWithDropdownMenu( {
) }
</MenuItem>
) ) }
</MenuGroup>
</>
)
}
</DropdownMenu>
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/dropdown-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function DropdownMenu( dropdownMenuProps ) {
);

return (
<NavigableMenu { ...mergedMenuProps } role="menu">
<NavigableMenu role="menu" { ...mergedMenuProps }>
{ isFunction( children ) ? children( props ) : null }
{ flatMap( controlSets, ( controlSet, indexOfSet ) =>
controlSet.map( ( control, indexOfControl ) => (
Expand Down

0 comments on commit 3e7af65

Please sign in to comment.