-
Notifications
You must be signed in to change notification settings - Fork 1k
add event listener to close tip on escape #7566
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
Conversation
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.
On the tip/simple story when I hover onto the tooltip content and then try to press 'esc' the tip doesn't close.
If I set defaultVisible=true
and then hover over the target and press 'esc' the tip doesn't close.
Update: confirmed these are working as expected when I open the story in a new window |
src/js/components/Tip/Tip.js
Outdated
@@ -21,6 +21,20 @@ const Tip = forwardRef( | |||
|
|||
const componentRef = useForwardedRef(tipRef); | |||
|
|||
useEffect(() => { |
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.
Just occurred to me that we may want to use <Keyboard>
instead like we do in Layer for onEsc
and avoid the useEffect and such altogether. I was just reading something this morning about avoiding this kind of usage of useEffect
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.
it was originally not working with keyboard
but now that I see its more not working in the storybook iframe let me try and switch out with keyboard
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.
Just occurred to me that we may want to use
<Keyboard>
instead like we do in Layer foronEsc
and avoid the useEffect and such altogether. I was just reading something this morning about avoiding this kind of usage of useEffect
This usage of useEffect is very typical and appropriate. The article I read was trying to advocate using this newer API instead:
import { useSyncExternalStore } from 'react';
// Simplified example for browser window size
function useWindowSize() {
return useSyncExternalStore(
// Subscribe function
callback => {
window.addEventListener('resize', callback);
return () => window.removeEventListener('resize', callback);
},
// Get snapshot function
() => ({ width: window.innerWidth, height: window.innerHeight })
);
}
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.
aw gotcha will I just switched it out with keyboard
but my test that I originally had was now failing. But if you want to test this way out and check out the code lmk I can work on the test in backround
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.
Behavior looks good, just holding off on marking as approved until jest test is ready
Here is the test I have
unfortunately though in the logs its showing Escape key is presses |
I've never had much luck with certain key handlers in jest tests. I think if they are at the |
Just a thought after testing the tip, can you try adding focus to whatever component you're rendering? Storybook only works if you put focus in the story pane somewhere |
yes I can do that for the test. I kinda wanted to test the UPDATE: Added the test where I added focus to the button then press |
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.
Looks good. Just waiting on the circle ci tests
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.
Look good!
What does this PR do?
This PR adds an event listener to the tooltip so that when a user clicks
escape
the tooltip will closeWhere should the reviewer start?
tip.js
What testing has been done on this PR?
storybook
How should this be manually tested?
open storybook of any of the tip stories and open in a new window then hover over tip and press
escape
Do Jest tests follow these best practices?
screen
is used for querying.asFragment()
is used for snapshot testing.Any background context you want to provide?
Tip is currently not passing these WCAG points for WCAG 1.4.13:
Dismissible
A mechanism is available to dismiss the additional content without moving pointer hover or keyboard focus, unless the additional content communicates an input error or does not obscure or replace other content;
What are the relevant issues?
Part 1 of #7552
Screenshots (if appropriate)
Do the grommet docs need to be updated?
no
Should this PR be mentioned in the release notes?
yes
Is this change backwards compatible or is it a breaking change?
backwards compatible