Skip to content

Commit

Permalink
Also use focus logic for when the list view is closed via the keyboar…
Browse files Browse the repository at this point in the history
…d shortcut
  • Loading branch information
andrewserong committed Sep 18, 2023
1 parent ae2f297 commit 0d5d016
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,29 @@ export default function ListViewSidebar( { listViewToggleElement } ) {
}
}

// This only fires when the sidebar is open because of the conditional rendering. It is the same shortcut to open but that is defined as a global shortcut and only fires when the sidebar is closed.
useShortcut( 'core/edit-post/toggle-list-view', () => {
const handleToggleListViewShortcut = useCallback( () => {
// If the sidebar has focus, it is safe to close.
if (
sidebarRef.current.contains(
sidebarRef.current.ownerDocument.activeElement
)
) {
setIsListViewOpened( false );
// TODO: Should we set focus here on the list view button toggle, too?
if ( ! hasBlocksSelected ) {
listViewToggleElement?.focus();
}
} else {
// If the list view or outline does not have focus, focus should be moved to it.
handleSidebarFocus( tab );
}
} );
}, [ hasBlocksSelected, listViewToggleElement, setIsListViewOpened, tab ] );

// This only fires when the sidebar is open because of the conditional rendering.
// It is the same shortcut to open but that is defined as a global shortcut and only fires when the sidebar is closed.
useShortcut(
'core/edit-post/toggle-list-view',
handleToggleListViewShortcut
);

/**
* Render tab content for a given tab name.
Expand Down

0 comments on commit 0d5d016

Please sign in to comment.