Skip to content

Commit

Permalink
Fix search block button position dropdown accessibility/UX issues. (#…
Browse files Browse the repository at this point in the history
…33376)

* Fix search block using non-accessible toolbar dropdown

* Fix more accessibility issues
  • Loading branch information
talldan authored Jul 13, 2021
1 parent 54e8671 commit 0814608
Showing 1 changed file with 40 additions and 44 deletions.
84 changes: 40 additions & 44 deletions packages/block-library/src/search/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import {
__experimentalUnitControl as UnitControl,
} from '@wordpress/block-editor';
import {
DropdownMenu,
MenuGroup,
MenuItem,
ToolbarDropdownMenu,
ToolbarGroup,
Button,
ButtonGroup,
Expand Down Expand Up @@ -115,6 +113,42 @@ export default function SearchEdit( {
);
};

const buttonPositionControls = [
{
role: 'menuitemradio',
title: __( 'Button outside' ),
isActive: buttonPosition === 'button-outside',
icon: buttonOutside,
onClick: () => {
setAttributes( {
buttonPosition: 'button-outside',
} );
},
},
{
role: 'menuitemradio',
title: __( 'Button inside' ),
isActive: buttonPosition === 'button-inside',
icon: buttonInside,
onClick: () => {
setAttributes( {
buttonPosition: 'button-inside',
} );
},
},
{
role: 'menuitemradio',
title: __( 'No button' ),
isActive: buttonPosition === 'no-button',
icon: noButton,
onClick: () => {
setAttributes( {
buttonPosition: 'no-button',
} );
},
},
];

const getButtonPositionIcon = () => {
switch ( buttonPosition ) {
case 'button-inside':
Expand Down Expand Up @@ -201,49 +235,11 @@ export default function SearchEdit( {
} }
className={ showLabel ? 'is-pressed' : undefined }
/>
<DropdownMenu
<ToolbarDropdownMenu
icon={ getButtonPositionIcon() }
label={ __( 'Change button position' ) }
>
{ ( { onClose } ) => (
<MenuGroup className="wp-block-search__button-position-menu">
<MenuItem
icon={ noButton }
onClick={ () => {
setAttributes( {
buttonPosition: 'no-button',
} );
onClose();
} }
>
{ __( 'No Button' ) }
</MenuItem>
<MenuItem
icon={ buttonOutside }
onClick={ () => {
setAttributes( {
buttonPosition: 'button-outside',
} );
onClose();
} }
>
{ __( 'Button Outside' ) }
</MenuItem>
<MenuItem
icon={ buttonInside }
onClick={ () => {
setAttributes( {
buttonPosition: 'button-inside',
} );
onClose();
} }
>
{ __( 'Button Inside' ) }
</MenuItem>
</MenuGroup>
) }
</DropdownMenu>

controls={ buttonPositionControls }
/>
{ 'no-button' !== buttonPosition && (
<ToolbarButton
title={ __( 'Use button with icon' ) }
Expand Down

0 comments on commit 0814608

Please sign in to comment.