-
Notifications
You must be signed in to change notification settings - Fork 843
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
Uses new WindowEvent component for Flyout "close on ESC" #1127
Conversation
6c6d790
to
48608b7
Compare
Do we still need the event listener on the flyout? eui/src/components/flyout/flyout.js Line 75 in 6c6d790
Won't |
@sqren good catch -- I'd removed that and then accidentally killed my changes in that file with |
Note: this PR addresses a TODO item in elastic/kibana#21300 |
LGTM! You also need a 👍 from someone on the EUI before merging. |
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 for jumping in here to add this.
A couple of things:
- Can you actually move this to the
services
folder instead ofcomponents
as it doesn't actually render any dom elements but is just a helper? - Can you also add a documentation page under the Utilities category with some more explanation of what it does and why one would need to use it.
- Don't forget to add an entry to the Changelog.
src/components/window_event/index.js
Outdated
@@ -0,0 +1 @@ | |||
export { default as EuiWindowEvent } from './window_event'; |
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 don't think you need the default as
here as it's in the component file.
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.
This is how you "proxy export" a default component from another file, I think. Or I could make the export in window_event
be named and drop default as
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.
Yeah I think we just name everything so we ensure there are no conflicts or that we can add to them down the line without breaking changes.
Hey @cchaos, I just pushed some example/docs and changelog additions, but please let me know if I've done anything funky in there. I'll add a bit more explanation to what I've got in the docs stuff, and I'll move the component into |
CHANGELOG.md
Outdated
- Added a new `EuiWindowEvent` component for declarative, safe management of `window` event listeners | ||
- Changed `Flyout` component to close on ESC keypress even if the flyout does not have focus | ||
|
||
## [`master`](https://github.com/elastic/eui/tree/master) |
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.
This is a copied heading, you can just append your bullets after the EuiSuperSelect
one.
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.
Addressed here: 73f0ed0
}], | ||
text: ( | ||
<p> | ||
Use an <EuiCode>EuiWindowEvent</EuiCode> to safely manage adding and auto-removing event listeners to <EuiCode>window</EuiCode>. |
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.
Can you also describe how?
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.
Sure!
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.
Addressed: e4d90d9
</p> | ||
), | ||
components: { EuiWindowEvent }, | ||
demo: <WindowEvent />, |
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.
Also add a props key here to populate a props tab with the props listed in a table like so:
props: { EuiWindowEvent }
New component moved to services directory here: a348dbb |
@cchaos re: scope, I think the answer is that my example is a bad one (or at least bad for that particular problem). Normally you wouldn't be listening for such a common key-press. If you were instead listening for "esc", for example, and there was a typeahead that was directly also listening on "esc" to clear results, the typeahead would do In other words, window events will always fire unless a more targeted event stops the event propagation earlier, so they need to be less generic than "any backspace key press". I can change that to "escape" in the example if you think that would help? And/or make a note to this effect in the example docs? |
Yeah, I think I would err on the side of creating an example that is the proper use of the service. We see a lot of just copy and paste style usages and want to make sure that doing so doesn't introduce issues. But I also think adding another paragraph or even a callout, to describe this issue would be good as well. |
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.
These new examples are fantastic. I think it's a lot clearer when and why to use this helper. Thanks so much for adding it all.
Just had one more adjustment to add, but LGTM!
</div> | ||
), | ||
components: { EuiWindowEvent }, | ||
demo: <BasicWindowEvent />, |
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.
Add props: { EuiWindowEvent }
The keyDown event listener for the
Flyout
component was attached to the Flyout node itself, so if you clicked anywhere outside of the Flyout and pressed "ESC", the Flyout would remain open. This PR does the following:EuiWindowEvent
component to safely handle the adding and necessary unmount-removal of window eventsI built the code locally and ran in local Kibana and it works as described here. The local build fails on the webpack bundle step, which I'm looking more into now.Update: local webpack error was a circular dependency because I was importing directly from
components
instead of fromcomponents/window_event
... all fixed now :)