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

Fix: Blocks: Alt+F10 should navigate to block toolbar regardless of visibility #11607

Conversation

jorgefilipecosta
Copy link
Member

@jorgefilipecosta jorgefilipecosta commented Nov 7, 2018

Description

Closes: #10907
When pressing alt + f10 if the contextual toolbar was not visible because the user was typing, we did not focus the block contextual toolbar, and we focused the header instead.

This PR addresses this problem.
To solve the problem, the PR performs the following actions:
Adds a prop to NavigableToolbar that enables it to focus when mounting.
Adds an event handler for pressing alt+f10 key combination on BlockListBlock and state flag the indicates that the handling is in progress.

How has this been tested?

I checked the unified toolbar mode was not enabled.
I added a paragraph, I wrote something until the toolbar disappears I pressed alt+f10, and I verified the block toolbar appeared with the first item focused.
I repeated the test with other blocks, e.g., writing on the image caption.

@jorgefilipecosta jorgefilipecosta added [Type] Task Issues or PRs that have been broken down into an individual action to take [Priority] High Used to indicate top priority items that need quick attention [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). labels Nov 7, 2018
packages/editor/src/components/block-list/block.js Outdated Show resolved Hide resolved
packages/editor/src/components/block-list/block.js Outdated Show resolved Hide resolved
if ( this.state.isHandlingAltF10 && ! this.props.isTypingWithinBlock ) {
// When the component updates and the user is not typing within the block
// we know that handling alt+f10 keypress is finished (the necessary child blocks are rendered).
this.setState( {
Copy link
Member

Choose a reason for hiding this comment

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

Would it be easy enough to use an instance variable this.isForcingContextualToolbar? This would avoid the need for a second re-render.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can use an instance variable the catch is that we need to force a re-render when changing the variable to true. I updated to use this approach.

/>
) }
{ ! shouldShowContextualToolbar && contextualSidebarMayAppear && isSelected && (
<KeyboardShortcuts
Copy link
Member

Choose a reason for hiding this comment

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

An impact of how we render this is that pressing Alt+F10 while in the block inspector will cause focus to be moved into the contextual toolbar. Is that expected?

Copy link
Member

Choose a reason for hiding this comment

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

The alternative being to wrap the editable region.

Copy link
Member Author

Choose a reason for hiding this comment

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

An impact of how we render this is that pressing Alt+F10 while in the block inspector will cause focus to be moved into the contextual toolbar. Is that expected?

That is already the case in master. When we are on the block inspector the toolbar will always be shown normally without the forcing as we are not typing so in this PR we are not changing any behavior for that case. I personally find this behavior acceptable as the block inspector is part of the block.

@aduth
Copy link
Member

aduth commented Nov 8, 2018

Probably conflicts with #10699, though addressing different (similar) issues.

@jorgefilipecosta jorgefilipecosta force-pushed the fix/Alt-F10-should-navigate-to-block-toolbar-regardless-of-visibility branch 2 times, most recently from 31f3ff0 to c095313 Compare November 8, 2018 19:42
@jorgefilipecosta
Copy link
Member Author

Hi @aduth thank you for your review. I think I addressed your feedback.

packages/editor/src/components/block-list/block.js Outdated Show resolved Hide resolved
@@ -86,6 +88,12 @@ export class BlockListBlock extends Component {
}

componentDidUpdate( prevProps ) {
if ( this.isForcingContextualToolbar && ! this.props.isTypingWithinBlock ) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we even need this condition? Or can it be assumed that since the render will occur following the assignment of the instance property that it's safe to immediately unset it in componentDidUpdate?

What is it about moving focus to the toolbar that causes this.props.isTypingWithinBlock to become false? It doesn't seem like something which could be strictly depended upon.

Copy link
Member Author

@jorgefilipecosta jorgefilipecosta Nov 9, 2018

Choose a reason for hiding this comment

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

Do we even need this condition?

We don't need this condition and the code was updated. It is safe to immediately unset it.

What is it about moving focus to the toolbar that causes this.props.isTypingWithinBlock to become false?

The expectation I had was that if the RichText loses focus, a stop typing action is dispatched.

@@ -61,6 +61,12 @@ class NavigableToolbar extends Component {
}
}

componentDidMount() {
if ( this.props.focusOnMount ) {
Copy link
Member

Choose a reason for hiding this comment

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

If it's part of the public interface, we should include a note in the CHANGELOG.md file.

Ideally also in README.md for the component, but it doesn't exist (until #10699).

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a note to the CHANGELOG.md.

Regarding the README.md given that it is already being added in #10699 my plan is to add a commit in #10699 after merging this PR updating its description to include the new property (provided it is not merged before if that is the case I will add the commit here).

@jorgefilipecosta jorgefilipecosta force-pushed the fix/Alt-F10-should-navigate-to-block-toolbar-regardless-of-visibility branch 3 times, most recently from 018d019 to 3c11419 Compare November 9, 2018 11:47
@@ -403,7 +416,8 @@ export class BlockListBlock extends Component {
// We render block movers and block settings to keep them tabbale even if hidden
const shouldRenderMovers = ! isFocusMode && ( isSelected || hoverArea === 'left' ) && ! showEmptyBlockSideInserter && ! isMultiSelecting && ! isPartOfMultiSelection && ! isTypingWithinBlock;
const shouldShowBreadcrumb = ! isFocusMode && isHovered && ! isEmptyDefaultBlock;
const shouldShowContextualToolbar = ! hasFixedToolbar && ! showSideInserter && ( ( isSelected && ( ! isTypingWithinBlock || isCaretWithinFormattedText ) ) || isFirstMultiSelected );
const contextualToolbarMayAppear = ! hasFixedToolbar && ! showSideInserter;
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if this really ought to be a condition including showSideInserter, or if it's enough to render KeyboardShortcuts with direct consideration of ! hasFixedToolbar. Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @aduth,
I added a new condition, that specifies in which cases we should render KeyboardShortcuts more explicitly.
We should take into account the isEmptyDefaultBlock flag, if true we should not use the shortcut as in this case the block has no toolbar, and we should continue to focus the header toolbar.
Let me know you prefer this condition; it should be equivalent to the previous one, just in a different format.

Copy link
Member

Choose a reason for hiding this comment

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

I like it 👍

@jorgefilipecosta jorgefilipecosta force-pushed the fix/Alt-F10-should-navigate-to-block-toolbar-regardless-of-visibility branch from 3c11419 to 2e907e4 Compare November 9, 2018 17:20
@jorgefilipecosta jorgefilipecosta force-pushed the fix/Alt-F10-should-navigate-to-block-toolbar-regardless-of-visibility branch from 2e907e4 to 4b08bb4 Compare November 9, 2018 17:24
@aduth aduth added this to the 4.3 milestone Nov 9, 2018
Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Nice 👍

@jorgefilipecosta jorgefilipecosta merged commit a2fee33 into master Nov 9, 2018
@jorgefilipecosta jorgefilipecosta deleted the fix/Alt-F10-should-navigate-to-block-toolbar-regardless-of-visibility branch November 9, 2018 17:57
@mtias
Copy link
Member

mtias commented Nov 12, 2018

Thanks!

@afercia
Copy link
Contributor

afercia commented Nov 12, 2018

Seems to me there's now a warning:

Warning: React does not recognize the `focusOnMount` prop on a DOM element. ...
    in div (created by NavigableContainer)
    ...

/Cc @jorgefilipecosta

@aduth
Copy link
Member

aduth commented Nov 13, 2018

Seems to me there's now a warning:

Warning: React does not recognize the `focusOnMount` prop on a DOM element. ...
    in div (created by NavigableContainer)
    ...

/Cc @jorgefilipecosta

Issue at #11769. Pull request at #11804.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Priority] High Used to indicate top priority items that need quick attention [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants