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

Accessibility: Dismiss BlockMover tooltips on escape key press. #15578

Closed
wants to merge 22 commits into from
Closed

Accessibility: Dismiss BlockMover tooltips on escape key press. #15578

wants to merge 22 commits into from

Conversation

nicolad
Copy link
Member

@nicolad nicolad commented May 11, 2019

Description

Fixes: #15145
Contextual PR: https://github.com/WordPress/gutenberg/pull/8147/files

How has this been tested?

Screenshots

Peek 2019-05-11 11-29

Types of changes

Passed onKeyDown to createToggleIsOver method of Tooltip component.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@nicolad nicolad added the [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). label May 11, 2019
@nicolad nicolad requested review from afercia and aduth May 11, 2019 08:34
@nicolad nicolad self-assigned this May 11, 2019
@@ -45,7 +45,7 @@ function IconButton( props, ref ) {
// the children are empty and...
( ! children || ( isArray( children ) && ! children.length ) ) &&
// the tooltip is not explicitly disabled.
false !== tooltip
tooltip !== false
Copy link
Member Author

Choose a reason for hiding this comment

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

Readability improvement.

Copy link
Member

Choose a reason for hiding this comment

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

Noting that this will probably conflict with changes currently proposed in #19193 . Regardless if it's an improvement, I might suggest to remove it here, since it's not entirely relevant (or close in proximity) to the intended changes.

@nicolad nicolad requested a review from ellatrix as a code owner May 11, 2019 08:51
@nicolad nicolad changed the title Dismiss BlockMover tooltips on escape key press. Accessibility: Dismiss BlockMover tooltips on escape key press. May 11, 2019
@youknowriad
Copy link
Contributor

Can we make the dismissable tooltip behavior something built-in into the Tooltip component so it can apply holistically to all tooltips?

@aduth
Copy link
Member

aduth commented May 13, 2019

Can we make the dismissable tooltip behavior something built-in into the Tooltip component so it can apply holistically to all tooltips?

Yes. There's some implementation notes at the earlier (since-closed) #8147 (review)

@@ -12,6 +12,7 @@ import {
cloneElement,
concatChildren,
} from '@wordpress/element';
import { KeyboardShortcuts } from '@wordpress/components';
Copy link
Member Author

Choose a reason for hiding this comment

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

@aduth, this is a little bit strange, just by importing KeyboardShortcuts I do get that nasty error:
Fatal error: Allowed memory size of 268435456 bytes exhausted ...
Am I doing something wrong here?
Peek 2019-05-20 16-57

Copy link
Contributor

Choose a reason for hiding this comment

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

you can't import something from the same package using the @wordpress/* syntax, just use relative paths.

Copy link
Member

Choose a reason for hiding this comment

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

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.

In this branch, while I do see that the tooltip is dismissed when pressing Escape, I also see that focus is lost entirely. I don't see this in master, and I wouldn't think it should be expected.

@nicolad
Copy link
Member Author

nicolad commented May 21, 2019

In this branch, while I do see that the tooltip is dismissed when pressing Escape, I also see that focus is lost entirely. I don't see this in master, and I wouldn't think it should be expected.

I recall that there was an issue related to handling focus after modal is closed or smth similar. Will post here if I will find that.

@@ -117,7 +120,13 @@ class Tooltip extends Component {
aria-hidden="true"
animate={ false }
>
{ text }
<KeyboardShortcuts
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 surprised this works, if it does. text is the text of the tooltip itself, which I wouldn't expect should ever have focus such that the KeyboardShortcuts could capture keyboard events. Instead, I would expect the KeyboardShortcuts should wrap the child.props.children (the original children).

Copy link
Member Author

Choose a reason for hiding this comment

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

@aduth, please let me know if the implementation is ok, so I can start adjusting failing tests. Thank you.

@nicolad nicolad requested a review from nerrad as a code owner May 25, 2019 21:52
@aduth
Copy link
Member

aduth commented Jun 25, 2019

The general approach with KeyboardShortcuts seems like it would be a good approach.

There are a few concerns, however:

  • Why do we need any changes around onMouseOver, onKeyDown? To me, it seems like there should be almost no other changes necessary in this pull request aside from adding the KeyboardShortcuts wrapping element.
  • In the escape handler for KeyboardShortcuts, we can probably avoid createToggleIsOver (I doubt it works anyways) and instead bind a callback which calls setState directly.
  • A more difficult issue is the design regression seen in this screenshot:
    • image
    • It seems that adding a new div wrapper (from KeyboardShortcuts) may affect styles of icon buttons. I'm not sure if there's an easy way to account for this universally. The div wrapper would be nice to avoid if we could, but we still need some way to capture events.

In further investigation, I wonder if we avoid KeyboardShortcuts and implement the onKeyDown as a property of the cloneElement props. You already have this. But as mentioned above, maybe we want to avoid createToggleIsOver, or at least check that the key being pressed is Escape. I don't recall what the earlier changes looked like, but with onKeyDown only, did it not achieve the desired effect?

@nicolad
Copy link
Member Author

nicolad commented Jul 24, 2019

Removed KeyboardShortcuts, it works as expected:
Peek 2019-07-25 02-40

@@ -90,6 +95,7 @@ class Tooltip extends Component {

render() {
const { children, position, text, shortcut } = this.props;
const { isOver } = this.state;
Copy link
Member

Choose a reason for hiding this comment

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

Why was this changed? Technically it's a violation of the no-unused-vars-before-return rule, but there is an explicit exemption for property destructuring since they're more difficult (but foreseeably possible) to handle. It's for this temporary exemption only that this doesn't emit an ESLint error. In fact: Looking at this usage, I'm tempted to remove the exemption when the destructuring only contains a single property.

I might suggest it be put back where it was.

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved this back.
It was changed to make destructuring first in order to ease readability.
This is a frequent pattern I've seen through various react apps/libs.

@@ -66,6 +66,8 @@ export class BlockMover extends Component {
aria-disabled={ isFirst }
onFocus={ this.onFocus }
onBlur={ this.onBlur }
onMouseEnter={ this.onFocus }
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

This PR is based on @afercia 's PR
Maybe @afercia might help here since I've iterated over his initial work?

Copy link
Contributor

Choose a reason for hiding this comment

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

Honestly I can't remember why I made that change. That was one year ago 😬 Sorry!

Copy link
Member Author

Choose a reason for hiding this comment

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

@aduth @afercia, FYI - I have reverted these changes.

@@ -71,6 +71,11 @@ class Tooltip extends Component {
return;
}

// If pressed key is escape, no further actions are needed.
if ( event.keyCode === 27 ) { // 27 is the keyCode for escape
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest to use the @wordpress/keycodes package to get a constant value, which negates the need for an inline code comment to explain the magic constant. It's already a dependency of @wordpress/components, so you should be able to just import it as such:

import { ESCAPE } from '@wordpress/keycodes';

// ...
Suggested change
if ( event.keyCode === 27 ) { // 27 is the keyCode for escape
if ( event.keyCode === ESCAPE ) {

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @aduth, updated this.

@nicolad nicolad requested a review from aduth December 17, 2019 18:18
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.

Apologies for having not revisited this sooner. I was away from the project for some time between August and November, so I missed the updates.

I could use some clarification about what it is in the event handler which is actually causing the tooltip to be dismissed. At the very least, we should consider to include more detail about this behavior in the existing proposed inline comment.

@@ -89,6 +90,11 @@ class Tooltip extends Component {
return;
}

// If pressed key is escape, no further actions are needed.
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 a bit confused by this. What actions have been taken at this point in the event handler when pressing Escape?

@@ -45,7 +45,7 @@ function IconButton( props, ref ) {
// the children are empty and...
( ! children || ( isArray( children ) && ! children.length ) ) &&
// the tooltip is not explicitly disabled.
false !== tooltip
tooltip !== false
Copy link
Member

Choose a reason for hiding this comment

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

Noting that this will probably conflict with changes currently proposed in #19193 . Regardless if it's an improvement, I might suggest to remove it here, since it's not entirely relevant (or close in proximity) to the intended changes.

@tellthemachines
Copy link
Contributor

I'm wondering how this is going to play with the escape key now being used to put the editor in select mode. Should we change that interaction so that pressing escape if a tooltip is open only closes the tooltip?

@nicolad
Copy link
Member Author

nicolad commented Jun 22, 2020

IconButton has been merged into Button here: #19193

@nicolad
Copy link
Member Author

nicolad commented Feb 5, 2021

@tellthemachines is this PR still relevant?
shall I close it?

@tellthemachines
Copy link
Contributor

@nicolad the issue persists, though to fix it we need to take into account potential conflicts with the Escape key also being used to enter Select mode.

Are you still keen and able to work on this? If not, I'd suggest closing the PR.

@nicolad
Copy link
Member Author

nicolad commented Feb 8, 2021

Are you still keen and able to work on this? If not, I'd suggest closing the PR.

I am not able to work on this ATM.

Thanks for your input, have an awesome week 🚀

@nicolad nicolad closed this Feb 8, 2021
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).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make tooltips dismissable
5 participants