Skip to content

Commit

Permalink
Accessibility: Move focus back to the modal dialog to More Menu when …
Browse files Browse the repository at this point in the history
…it was used to get there
  • Loading branch information
gziolo committed Sep 4, 2019
1 parent 0e55ef6 commit 7bdecb5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
8 changes: 6 additions & 2 deletions packages/components/src/dropdown/index.js
Expand Up @@ -49,10 +49,14 @@ class Dropdown extends Component {
* Closes the dropdown if a focus leaves the dropdown wrapper. This is
* intentionally distinct from `onClose` since focus loss from the popover
* is expected to occur when using the Dropdown's toggle button, in which
* case the correct behavior is to keep the dropdown closed.
* case the correct behavior is to keep the dropdown closed. The same applies
* in case when focus is moved to the modal dialog.
*/
closeIfFocusOutside() {
if ( ! this.containerRef.current.contains( document.activeElement ) ) {
if (
! this.containerRef.current.contains( document.activeElement ) &&
! document.activeElement.closest( '[role="dialog"]' )
) {
this.close();
}
}
Expand Down
Expand Up @@ -36,7 +36,7 @@ const MoreMenu = () => (
<PluginMoreMenuGroup.Slot fillProps={ { onClose } } />
<ToolsMoreMenuGroup.Slot fillProps={ { onClose } } />
<MenuGroup>
<OptionsMenuItem onSelect={ onClose } />
<OptionsMenuItem />
</MenuGroup>
</>
) }
Expand Down
Expand Up @@ -5,11 +5,10 @@ import { withDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { MenuItem } from '@wordpress/components';

export function OptionsMenuItem( { openModal, onSelect } ) {
export function OptionsMenuItem( { openModal } ) {
return (
<MenuItem
onClick={ () => {
onSelect();
openModal( 'edit-post/options' );
} }
>
Expand Down
Expand Up @@ -6,11 +6,10 @@ import { withDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { displayShortcut } from '@wordpress/keycodes';

export function KeyboardShortcutsHelpMenuItem( { openModal, onSelect } ) {
export function KeyboardShortcutsHelpMenuItem( { openModal } ) {
return (
<MenuItem
onClick={ () => {
onSelect();
openModal( 'edit-post/keyboard-shortcut-help' );
} }
shortcut={ displayShortcut.access( 'h' ) }
Expand Down
14 changes: 4 additions & 10 deletions packages/edit-post/src/plugins/manage-blocks-menu-item/index.js
@@ -1,22 +1,16 @@
/**
* External dependencies
*/
import { flow } from 'lodash';

/**
* WordPress dependencies
*/
import { MenuItem } from '@wordpress/components';
import { withDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';

export function ManageBlocksMenuItem( { onSelect, openModal } ) {
export function ManageBlocksMenuItem( { openModal } ) {
return (
<MenuItem
onClick={ flow( [
onSelect,
() => openModal( 'edit-post/manage-blocks' ),
] ) }
onClick={ () => {
openModal( 'edit-post/manage-blocks' );
} }
>
{ __( 'Block Manager' ) }
</MenuItem>
Expand Down

0 comments on commit 7bdecb5

Please sign in to comment.