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. |
cchaos
left a comment
There was a problem hiding this comment.
Thanks for jumping in here to add this.
A couple of things:
- Can you actually move this to the
servicesfolder instead ofcomponentsas 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.
| @@ -0,0 +1 @@ | |||
| export { default as EuiWindowEvent } from './window_event'; No newline at end of file | |||
There was a problem hiding this comment.
I don't think you need the default as here as it's in the component file.
There was a problem hiding this comment.
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.
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 |
| - 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.
This is a copied heading, you can just append your bullets after the EuiSuperSelect one.
| }], | ||
| text: ( | ||
| <p> | ||
| Use an <EuiCode>EuiWindowEvent</EuiCode> to safely manage adding and auto-removing event listeners to <EuiCode>window</EuiCode>. |
| </p> | ||
| ), | ||
| components: { EuiWindowEvent }, | ||
| demo: <WindowEvent />, |
There was a problem hiding this comment.
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. |
cchaos
left a comment
There was a problem hiding this comment.
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.
Add props: { EuiWindowEvent }
The keyDown event listener for the
Flyoutcomponent 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:EuiWindowEventcomponent 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
componentsinstead of fromcomponents/window_event... all fixed now :)