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

Implement roving tabindex on the Image block #22696

Merged
merged 4 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { noop } from 'lodash';
import { __ } from '@wordpress/i18n';
import { DOWN } from '@wordpress/keycodes';
import {
Button,
ToolbarButton,
Dropdown,
ToolbarGroup,
__experimentalAlignmentMatrixControl as AlignmentMatrixControl,
Expand Down Expand Up @@ -41,7 +41,7 @@ export function BlockAlignmentMatrixToolbar( props ) {

return (
<ToolbarGroup>
<Button
<ToolbarButton
onClick={ onToggle }
aria-haspopup="true"
aria-expanded={ isOpen }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
NavigableMenu,
MenuItem,
ToolbarGroup,
Button,
ToolbarButton,
Dropdown,
} from '@wordpress/components';
import { withDispatch, useSelect } from '@wordpress/data';
Expand Down Expand Up @@ -110,14 +110,14 @@ const MediaReplaceFlow = ( {
contentClassName="block-editor-media-replace-flow__options"
renderToggle={ ( { isOpen, onToggle } ) => (
<ToolbarGroup className="media-replace-flow">
<Button
<ToolbarButton
ref={ editMediaButtonRef }
aria-expanded={ isOpen }
onClick={ onToggle }
onKeyDown={ openOnArrowDown }
>
{ name }
</Button>
</ToolbarButton>
</ToolbarGroup>
) }
renderContent={ ( { onClose } ) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { find, isEmpty, each, map } from 'lodash';
import { __ } from '@wordpress/i18n';
import { useRef, useState, useCallback } from '@wordpress/element';
import {
ToolbarButton,
Button,
NavigableMenu,
MenuItem,
Expand Down Expand Up @@ -258,7 +259,7 @@ const ImageURLInputUI = ( {

return (
<>
<Button
<ToolbarButton
icon={ linkIcon }
className="components-toolbar__control"
label={ url ? __( 'Edit link' ) : __( 'Insert link' ) }
Expand Down
235 changes: 132 additions & 103 deletions packages/block-library/src/rich-image/rich-image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {
} from '@wordpress/block-editor';
import { Fragment, Component } from '@wordpress/element';
import {
Toolbar,
ToolbarGroup,
ToolbarButton,
__experimentalToolbarItem as ToolbarItem,
Icon,
Button,
Spinner,
withNotices,
RangeControl,
Expand Down Expand Up @@ -210,57 +210,73 @@ class RichImage extends Component {

{ isEditing && (
<BlockControls>
<Toolbar>
<DropdownMenu
icon={ <RotateLeftIcon /> }
label={ __( 'Rotate' ) }
popoverProps={ POPOVER_PROPS }
controls={ [
{
icon: <RotateLeftIcon />,
title: __( 'Rotate left' ),
isDisabled: inProgress,
onClick: () =>
this.adjustImage( 'rotate', {
angle: -ROTATE_STEP,
} ),
},
{
icon: <RotateRightIcon />,
title: __( 'Rotate right' ),
isDisabled: inProgress,
onClick: () =>
this.adjustImage( 'rotate', {
angle: ROTATE_STEP,
} ),
},
] }
/>
<DropdownMenu
icon={ <FlipVerticalIcon /> }
label={ __( 'Flip' ) }
popoverProps={ POPOVER_PROPS }
controls={ [
{
icon: <FlipVerticalIcon />,
title: __( 'Flip vertical' ),
isDisabled: inProgress,
onClick: () =>
this.adjustImage( 'flip', {
direction: 'vertical',
} ),
},
{
icon: <FlipHorizontalIcon />,
title: __( 'Flip horizontal' ),
isDisabled: inProgress,
onClick: () =>
this.adjustImage( 'flip', {
direction: 'horizontal',
} ),
},
] }
/>
<ToolbarGroup>
<ToolbarItem>
{ ( toggleProps ) => (
<DropdownMenu
icon={ <RotateLeftIcon /> }
label={ __( 'Rotate' ) }
popoverProps={ POPOVER_PROPS }
toggleProps={ toggleProps }
controls={ [
{
icon: <RotateLeftIcon />,
title: __( 'Rotate left' ),
isDisabled: inProgress,
onClick: () =>
this.adjustImage(
'rotate',
{
angle: -ROTATE_STEP,
}
),
},
{
icon: <RotateRightIcon />,
title: __( 'Rotate right' ),
isDisabled: inProgress,
onClick: () =>
this.adjustImage(
'rotate',
{
angle: ROTATE_STEP,
}
),
},
] }
/>
) }
</ToolbarItem>
Comment on lines +214 to +249
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff got messed up. But this is basically wrapping <DropdownMenu> with <ToolbarItem> and passing the toolbar item props to toggleProps:

<ToolbarItem>
	{ ( toggleProps ) => (
		<DropdownMenu
			...
			toggleProps={ toggleProps }
		/>
	) }
</ToolbarItem>

<ToolbarItem>
{ ( toggleProps ) => (
<DropdownMenu
icon={ <FlipVerticalIcon /> }
label={ __( 'Flip' ) }
popoverProps={ POPOVER_PROPS }
toggleProps={ toggleProps }
controls={ [
{
icon: <FlipVerticalIcon />,
title: __( 'Flip vertical' ),
isDisabled: inProgress,
onClick: () =>
this.adjustImage( 'flip', {
direction: 'vertical',
} ),
},
{
icon: <FlipHorizontalIcon />,
title: __( 'Flip horizontal' ),
isDisabled: inProgress,
onClick: () =>
this.adjustImage( 'flip', {
direction: 'horizontal',
} ),
},
] }
/>
) }
</ToolbarItem>
<ToolbarButton
disabled={ inProgress }
icon={ <CropIcon /> }
Expand All @@ -272,57 +288,70 @@ class RichImage extends Component {
} )
}
/>
</Toolbar>
</ToolbarGroup>
</BlockControls>
) }

{ isCrop && (
<BlockControls>
<Toolbar>
<ToolbarGroup>
<div className="richimage__crop-icon">
<Icon icon={ CropIcon } />
</div>
</Toolbar>
<Toolbar>
<DropdownMenu
icon={ <AspectIcon /> }
label={ __( 'Aspect Ratio' ) }
popoverProps={ POPOVER_PROPS }
controls={ [
{
title: __( '16:10' ),
isDisabled: inProgress,
onClick: () =>
this.setState( {
aspect: 16 / 10,
} ),
},
{
title: __( '16:9' ),
isDisabled: inProgress,
onClick: () =>
this.setState( { aspect: 16 / 9 } ),
},
{
title: __( '4:3' ),
isDisabled: inProgress,
onClick: () =>
this.setState( { aspect: 4 / 3 } ),
},
{
title: __( '3:2' ),
isDisabled: inProgress,
onClick: () =>
this.setState( { aspect: 3 / 2 } ),
},
{
title: __( '1:1' ),
isDisabled: inProgress,
onClick: () =>
this.setState( { aspect: 1 } ),
},
] }
/>
</ToolbarGroup>
<ToolbarGroup>
<ToolbarItem>
{ ( toggleProps ) => (
<DropdownMenu
icon={ <AspectIcon /> }
label={ __( 'Aspect Ratio' ) }
popoverProps={ POPOVER_PROPS }
toggleProps={ toggleProps }
controls={ [
{
title: __( '16:10' ),
isDisabled: inProgress,
onClick: () =>
this.setState( {
aspect: 16 / 10,
} ),
},
{
title: __( '16:9' ),
isDisabled: inProgress,
onClick: () =>
this.setState( {
aspect: 16 / 9,
} ),
},
{
title: __( '4:3' ),
isDisabled: inProgress,
onClick: () =>
this.setState( {
aspect: 4 / 3,
} ),
},
{
title: __( '3:2' ),
isDisabled: inProgress,
onClick: () =>
this.setState( {
aspect: 3 / 2,
} ),
},
{
title: __( '1:1' ),
isDisabled: inProgress,
onClick: () =>
this.setState( {
aspect: 1,
} ),
},
] }
/>
) }
</ToolbarItem>
<ToolbarButton
className="richimage-toolbar__dropdown"
disabled={ inProgress }
Expand All @@ -334,19 +363,19 @@ class RichImage extends Component {
} ) )
}
/>
</Toolbar>
<Toolbar>
<Button onClick={ this.cropImage }>
</ToolbarGroup>
<ToolbarGroup>
<ToolbarButton onClick={ this.cropImage }>
{ __( 'Apply' ) }
</Button>
<Button
</ToolbarButton>
<ToolbarButton
onClick={ () =>
this.setState( { isCrop: false } )
}
>
{ __( 'Cancel' ) }
</Button>
</Toolbar>
</ToolbarButton>
</ToolbarGroup>
</BlockControls>
) }
</Fragment>
Expand Down