Skip to content
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

Fix search block button position dropdown accessibility/UX issues. #33376

Merged
merged 2 commits into from
Jul 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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