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

Disable navigation block for text mode. #12185

Merged
merged 8 commits into from
Feb 5, 2019
11 changes: 8 additions & 3 deletions packages/editor/src/components/block-navigation/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { Fragment } from '@wordpress/element';
import { IconButton, Dropdown, SVG, Path, KeyboardShortcuts } from '@wordpress/components';
import { withSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { rawShortcut, displayShortcut } from '@wordpress/keycodes';

Expand All @@ -17,7 +18,7 @@ const MenuIcon = (
</SVG>
);

function BlockNavigationDropdown() {
function BlockNavigationDropdown( { hasBlocks, isTextModeEnabled } ) {
return (
<Dropdown
renderToggle={ ( { isOpen, onToggle } ) => (
Expand All @@ -31,10 +32,11 @@ function BlockNavigationDropdown() {
<IconButton
icon={ MenuIcon }
aria-expanded={ isOpen }
onClick={ onToggle }
onClick={ hasBlocks || ! isTextModeEnabled ? onToggle : undefined }
label={ __( 'Block Navigation' ) }
className="editor-block-navigation"
shortcut={ displayShortcut.access( 'o' ) }
aria-disabled={ ! hasBlocks || isTextModeEnabled }
Copy link
Member

Choose a reason for hiding this comment

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

Can we use the disabled attribute instead of aria-disabled? I think it has the same effect for screen readers users and avoids the need for the onClick change done here as the onClick is not called if disabled is set to true.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you @jorgefilipecosta for tips.
Had adjusted details you've pointed.
And because this PR had been merged before:
https://github.com/WordPress/gutenberg/pull/12073/files
I did not touch any of those modifications regarding onClick. Only my changes had been discarded.

Copy link
Member

Choose a reason for hiding this comment

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

@jorgefilipecosta - in my testing there is a subtle difference between disabled and aria-disabled - in case of using disabled you never have to tab through the disabled element which seems to be reasonable but differs from other buttons like redo or undo. I have already landed this PR, but given that we need to do something similar for Document Outline I can open a follow-up and include that, too. What do you think?

/>
</Fragment>
) }
Expand All @@ -45,4 +47,7 @@ function BlockNavigationDropdown() {
);
}

export default BlockNavigationDropdown;
export default withSelect( ( select ) => ( {
hasBlocks: !! select( 'core/editor' ).getBlockCount(),
isTextModeEnabled: select( 'core/edit-post' ).getEditorMode() === 'text',
} ) )( BlockNavigationDropdown );