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

Add arrow navigation in Preview menu #24465

Merged
merged 3 commits into from
Aug 11, 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
42 changes: 21 additions & 21 deletions packages/block-editor/src/components/preview-options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { Button, Dropdown, MenuGroup, MenuItem } from '@wordpress/components';
import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { check } from '@wordpress/icons';

Expand All @@ -17,27 +17,27 @@ export default function PreviewOptions( {
deviceType,
setDeviceType,
} ) {
const popoverProps = {
className: classnames(
className,
'block-editor-post-preview__dropdown-content'
),
position: 'bottom left',
};
const toggleProps = {
isTertiary: true,
className: 'block-editor-post-preview__button-toggle',
disabled: ! isEnabled,
children: __( 'Preview' ),
};
return (
<Dropdown
<DropdownMenu
className="block-editor-post-preview__dropdown"
contentClassName={ classnames(
className,
'block-editor-post-preview__dropdown-content'
) }
popoverProps={ { role: 'menu' } }
position="bottom left"
renderToggle={ ( { isOpen, onToggle } ) => (
<Button
isTertiary
onClick={ onToggle }
className="block-editor-post-preview__button-toggle"
aria-expanded={ isOpen }
disabled={ ! isEnabled }
>
{ __( 'Preview' ) }
</Button>
) }
renderContent={ () => (
popoverProps={ popoverProps }
toggleProps={ toggleProps }
icon={ null }
>
{ () => (
<>
<MenuGroup>
<MenuItem
Expand Down Expand Up @@ -65,6 +65,6 @@ export default function PreviewOptions( {
{ children }
</>
) }
/>
</DropdownMenu>
);
}
12 changes: 11 additions & 1 deletion packages/block-editor/src/components/preview-options/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@
overflow-y: visible;
}

&.edit-post-post-preview-dropdown {
.components-menu-group {
&:first-child {
padding-bottom: $grid-unit-10;
}
&:last-child {
margin-bottom: 0;
}
}
}

.components-menu-group + .components-menu-group {
border-top: $border-width solid $gray-400;
padding: $grid-unit-10 $grid-unit-15;
margin-left: -$grid-unit-15;
margin-right: -$grid-unit-15;
Expand Down
1 change: 1 addition & 0 deletions packages/edit-post/src/components/device-preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default function DevicePreview() {
className={
'edit-post-header-preview__button-external'
}
role="menuitem"
forceIsAutosaveable={ hasActiveMetaboxes }
forcePreviewLink={ isSaving ? null : undefined }
textContent={
Expand Down
3 changes: 2 additions & 1 deletion packages/editor/src/components/post-preview-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class PostPreviewButton extends Component {
}

render() {
const { previewLink, currentPostLink, isSaveable } = this.props;
const { previewLink, currentPostLink, isSaveable, role } = this.props;

// Link to the `?preview=true` URL if we have it, since this lets us see
// changes that were autosaved since the post was last published. Otherwise,
Expand All @@ -203,6 +203,7 @@ export class PostPreviewButton extends Component {
disabled={ ! isSaveable }
onClick={ this.openPreviewWindow }
ref={ this.buttonRef }
role={ role }
>
{ this.props.textContent
? this.props.textContent
Expand Down