-
Notifications
You must be signed in to change notification settings - Fork 130
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
Can the CloseWatcher API be utilized in a11y-dialog? #716
Comments
Hey Mayank! Thanks for opening an issue. I wasn’t aware of this API, so this is pretty cool to explore it. I opened a prototype in #717 which is half-decent, but I’m not convinced by the API itself tbh. |
Thanks for looking into this! I responded to some of the comments in your PR, and I mostly agree with your criticism of the API shape. However I do want to emphasize that this API provides new, important functionality that is either impossible or very difficult to achieve without using it. For example, there is no other way to respond to the "Back" interaction in Android or VoiceOver+iOS. |
Thanks for your review! Don't get me wrong, I'm all in favor of implementing it, I just don't know how to solve the lack of event details problem. Right now, a lot of implementations rely on having access to the event when closing the dialog, and that would essentially no longer work since the close watcher event is basically useless. |
I revisited the approach a little. Instead of moving all the internal calls to I tested it on Chrome Android and it closes the dialog when using the “Back” gesture instead of navigate back one page, which is awesome. I haven’t tried VoiceOver, but I assume it works similarly. That’s a really low effort and worthy addition, so I’d be keen on releasing it in v8.2.0. The only remaining problem is that a specific Cypress test related to the |
Awesome! I quite like this small snippet: new CloseWatcher().onclose = this.hide Just a thought: should this replace the if (typeof CloseWatcher !== 'undefined') {
new CloseWatcher().onclose = this.hide
} else {
this.$el.addEventListener('keydown', this.bindKeypress, true)
} As for the Cypress tests, I wonder if the Escape keypress fired by |
Mmh, no, we cannot do that. For two reasons:
So, to solve that situation we either:
|
It might be worth testing the order of events. If a11y-dialog/src/a11y-dialog.ts Line 137 in a5fe088
|
Well, I think this is fine because we actually never call So whenever we click a dialog closer (like the close button or the backdrop, or even the ESC key), we actually don’t go through the watcher whatsoever. We internally just call At least, that’s how I understand it. |
The
CloseWatcher
API provides a browser-native mechanism for listening to "close requests" from the operating system. This includes Esc keypresses on desktop, the "Back" gesture on mobile, as well as some other close requests, such as those from assistive technology (notably VoiceOver on iOS).Can
a11y-dialog
make use of this API to offer a better, more inclusive user experience?I'd imagine it could be added in the same place where it is currently listening for Esc keypresses.
a11y-dialog/src/a11y-dialog.ts
Line 106 in a5fe088
Since
CloseWatcher
is quite new, feature detection would need to be utilized to conditionally call the API only in supported browsers, while still continuing to call the existingbindKeypress
code in older browsers.The text was updated successfully, but these errors were encountered: