-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Accessibility: Dismiss BlockMover tooltips on escape key press. #15578
Conversation
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Readability improvement.
There was a problem hiding this comment.
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.
Can we make the dismissable tooltip behavior something built-in into the |
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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed in Slack thread (link requires registration):
https://wordpress.slack.com/archives/C02QB2JS7/p1557863367231300
There was a problem hiding this 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.
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 |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
The general approach with There are a few concerns, however:
In further investigation, I wonder if we avoid |
…ility/improve-tooltips-behavior
…ility/improve-tooltips-behavior
@@ -90,6 +95,7 @@ class Tooltip extends Component { | |||
|
|||
render() { | |||
const { children, position, text, shortcut } = this.props; | |||
const { isOver } = this.state; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -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 |
There was a problem hiding this comment.
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';
// ...
if ( event.keyCode === 27 ) { // 27 is the keyCode for escape | |
if ( event.keyCode === ESCAPE ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @aduth, updated this.
There was a problem hiding this 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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
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? |
|
@tellthemachines is this PR still relevant? |
@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. |
I am not able to work on this ATM. Thanks for your input, have an awesome week 🚀 |
Description
Fixes: #15145
Contextual PR: https://github.com/WordPress/gutenberg/pull/8147/files
How has this been tested?
Screenshots
Types of changes
Passed
onKeyDown
tocreateToggleIsOver
method ofTooltip
component.Checklist: