-
Notifications
You must be signed in to change notification settings - Fork 82
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
add component to safely restore focus #81
Comments
Relevant snippet for restoring activeElement from jQuery UI dialog: https://github.com/jquery/jquery-ui/blob/ffcfb85c9818954adda69e73cf9ba76ea07b554c/ui/widgets/dialog.js#L224-L230 - has some inline comments for WebKit specific issues, might be useful. That uses our safeBlur and safeActiveElement helpers - both have a bunch of support comments as well. I haven't looked through ally.js enough to see if any of those aren't yet covered. |
thx for the pointers! You're mostly dealing with browsers "misbehaving" when hiding or even removing the activeElement.
nothing so far. I guess I'll want to test these things before proceeding with implementing this issue. |
I think the try/catch addresses: https://bugs.jqueryui.com/ticket/8443 |
indeed. looks like we should copy the |
Seems good to me. CCing @scottgonzalez and @tjvantoll on this, they might have some more useful insight as well. |
This topic came up while talking jQueryUI integration with @jzaefferer:
The dialog tutorial features a naive method of storing and restoring focus. The following scenarios (upon restore) are not unheard of:
safe
focus()
Calling
element.focus()
on something that is not focusable or attached to the DOM will cause<body>
to become theactiveElement
. In case we're trying to focus a non-focusable element, we could however traverse the parents to find a focusable element and pass focus to that element instead.ally.get.focusTarget
should help with that. We would wrap this inally.element.focus
and could provide the following options:ally.get.focusTarget
for convenience)ally.when.focusable
but not returning the service handle)restore current
activeElement
serviceIf we simply store the
activeElement
and it is detached from the DOM before we restore focus, we can't get its ancestry anymore. For that reason it makes sense to provide a service that upon engaging stores the current element hierarchy. The service handle would expose a function.restore()
that tries to shift focus to an element in the previously saved hierarchy. Atengage()
andrestore()
a "fallback" callback can be passed that is invoked should the service not be able to restore focus.Should this be made available at
ally.maintain.restorableFocus
?The text was updated successfully, but these errors were encountered: