-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
focus considerations #1
Comments
@jdanyow I believe we have an |
Updating latest from upstream/master
FYI my experience of using the autofocus attribute was unreliable. It worked sometimes and not others but I wasn't paying too much attention when testing and replaced all of them with |
More accessibility stuff here, for reference - https://accessibility.oit.ncsu.edu/training/aria/modal-window/version-3/ |
@AdamWillden @jdanyow The |
Possibly. If we want to do that...it has to happen today. @jdanyow @jedd-ahyoung Thoughts? |
My two cents: I think building components that steal the focus when they are attached can be dangerous and hinder usability and composability of components. The I know that everyone does not agree with my view on this (@jods4 I think you and I have discussed this before elsewhere 😉). I do accept that |
Perhaps we should move this into templating, but @jdanyow may be right
2016-06-20 13:48 GMT-04:00 Jeremy Danyow [email protected]:
|
There's another option, which is to remove it altogether and either, then:
(We could work to make gists installable through the cli in the future.) |
Yes I remember we had this discussion in another thread. I think this custom attribute is generally useful and I add it in all my projects. Maybe it can be misused but for me the onus is on the dev. I don't mind if this doesn't belong to Aurelia proper, but I find it strange that it is offered by EDIT BTW: if you have a robust and comprehensive solution for focus management, I'm interested! ;) |
I liked how durandal did it: https://github.com/BlueSpire/Durandal/blob/master/src/plugins/js/dialog.js#L502 And in past projects had added logic to execute the same code on navigation complete events. This resulted in a convention that could be used throughout the app, avoiding components "fighting" for focus. On one hand I agree we could prescribe an approach with gists, etc, on the other hand it would be nice (if everyone agreed the durandal way is the best) if we specified a convention, updated the router and dialog plugins to follow that convention, and people could opt in by adding |
Perhaps @EisenbergEffect has the right idea here. If the ai-dialog elements don't make use of this attribute at all, we might be able to replace it or place it in a separate repository. As for the autofocus....that's something that I've been thinking about in terms of accessibility for the modal. Perhaps when the modal is opened, it will search for an |
@jdanyow I would be down with that. Then we can remove it from here. We can add the capability to the core. Anyone who wants another behavior can always write their own custom attribute to handle it. |
I've done this in the past as well. I went even further:
As you can see there is a fair bit of policy going on. Maybe best to do so in a global In the end, what I like with the attribute, is that it doesn't need duplication and works everywhere. You probably are going to want the same behavior for dialogs, but also pages (in the router) and possibly controls that make other UI appears, such as small non-modal popups... What is lost is the "first input by default" but I can live with that. Anyway it seems all these options are going to be non-framework samples for the moment. And it's probably best like that ;) I still wish WHATWG would fix |
All of that sounds good. However, I think it might be good to search for 2016-06-20 15:15 GMT-04:00 jods [email protected]:
|
In previous project, I only auto-focused textboxes and when opening dialog boxes. I agree all of this is highly personal policy/preferences dependent. |
Thinking more about this -a few thoughts:
We can leave this up to the developer to implement, but I don't think that makes for a good modal plugin. Alternatively, users can create a custom renderer plugin to use a modal solution that provides accessibility already (Bootstrap, JQueryUI, etc). I'm still not sure that I see a good solution to this. |
Ok, so what is the proposal? Is it to remove the autofocus from the dialog and instead add a core capability to the templating engine which is then used by modal and the router to focus UI? |
@EisenbergEffect yes I think so. Then we'd just need to define how that core capability works and how it can be overridden or disabled. I'm on board with going further than what the durandal logic did. What @jods4 described in #1 (comment) sounded good to me. in terms of |
I put That's the 5th bug I've noticed since I started using this plug-in. 😞 |
@jedd-ahyoung The latest version of "The Incredible Accessible Modal Window" is now at https://github.com/gdkraus/accessible-modal-dialog |
@glen-84 on latest this is confirmed as working. |
I'm confused. I understand that the autofocus behaviour is moving to templating-resources (btw: is there an issue for this that I can track?). But what of the other considerations from @jdanyow's original comment? I want to prevent users from tabbing of the modal, and restore focus when the modal closes. Will this be added to aurelia-dialog eventually? Or should I build a custom solution? |
@RomkeVdMeulen sorry I missed testing the point of tabbing on to the underlying view - is there a suggested approach for this in the modal that you linked before? Ok I was lazy just went and looked and they are high jacking the tab key and limiting to items that are in the dialog only. I'll open this back up to make sure we can do the same I don't think this will be a major change but a nice feature. Good catch! |
Allowing the user to I shouldn't really have to add logic to every control to disable it when dialogs are open! |
Putting this here as I was thinking of a custom attribute that would determine a "tabcontext" - basically tabindex the way I think it should have worked originally. This doesn't directly address the "initial focus" issue but it would address the "tabbing to underlying content" issue.
|
Any updates on this? We're still seeing the focus moving off the dialog and onto the underlying content. We would really like to prevent this from happening. |
PR welcome here. Some pseudo-code you could use -
|
Any news when this will happen? |
I've got something working by putting this <template>
<div class="modal" trap-focus>
<input attach-focus value.bind="name" />
<input value.bind="desc" />
<input value.bind="age" />
</div>
</template> @customAttribute('trap-focus')
@inject(Element)
export class TrapFocus {
private element: HTMLElement;
constructor(element: HTMLElement) {
this.element = element;
}
public attached() {
document.addEventListener('keyup', this.keyPress);
}
public detached() {
document.removeEventListener('keyup', this.keyPress);
}
private keyPress = (e: KeyboardEvent) => {
const key = e.which || e.keyCode;
if (key === 9 && this.element.offsetParent && !this.element.contains(e.srcElement)) {
const elements = Array.from(this.element.querySelectorAll('input:not(disabled), textarea:not(disabled), button:not(disabled), [tabindex]'))
.filter((el: HTMLElement) => el.tabIndex >= 0);
const next = elements[e.shiftKey ? elements.length - 1 : 0] as HTMLElement;
next.focus();
}
}
} |
Any updates on this? We're still seeing the focus moving off the dialog. I'm hoping for an official solution. |
@timfish I like your solution, but if I understand this correctly it intercepts every tab press, which might not be the best in terms of a11y (I'm not sure, but I imagine some screenreader software might have other uses for tab that are incompatible with this). I was thinking we could reverse this approach: once focus enters an element with |
My only concern with that is If we're going to consider screen readers there are other things too
|
Complying with all a11y requirements is indeed important, but I suggest we stick to focus considerations for this issue. That does include returning focus to the opening element when the dialog closes, but I'm not sure how to do that with the current structure of the aurelia-dialog plugin.
Good point. I've done some searching, but there's a lot of ways to potentially handle this. Here's an example from W3C: it listens for focus events. (See here for demo) |
Here are the WAI-ARIA specifications for dialog keyboard behaviour.
|
My implementation will probably also stop users from tabbing to the browsers search/URL entry and other UI which is not really desirable. My app is currently only running in Electron where this is not an issue. |
Is it a good idea to use the implementation @timfish provided while waiting for official support? I'd like to use an official implementation instead of this one so we don't have to support this piece of code for our dialogs. |
My testing of these demos in Chrome 64 seem to suggest that the HTML dialog element and EDIT EDIT 2 |
The native dialog tag comes with one caveat: it does not return focus when the dialog closes. See #375. |
(moved from aurelia/framework#142)
.autofocus
/autofocus
:The text was updated successfully, but these errors were encountered: