Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Improve compatibility with wicg-inert #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ptrin
Copy link

@ptrin ptrin commented May 24, 2019

When trying to use https://github.com/WICG/inert as the inert polyfill, I found that setting focus after closing the modal was not working because inert was not really removed yet when focus was being set. Here's a quote from the wing-inert README about the issue:

It relies on mutation observers to detect the addition of the inert
attribute, and to detect dynamically added content within inert subtrees.
Testing for inert-ness in any way immediately after either type of mutation
will therefore give inconsistent results; please allow the current task to end
before relying on mutation-related changes to take effect, for example via
setTimeout(fn, 0) or Promise.resolve().

index.js Outdated
if ( main && !returnToBody ) {
main.tabIndex = -1;
main.focus();
Promise.resolve().then(function() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the only issue i have with this right now is that prior to this change, the script worked with IE11 out of the box.

can this be done in a way to avoid having to polyfill promise? or would the script need a new dependency like the promise polyfill?

@jfhector
Copy link

jfhector commented May 25, 2019

I think that setTimeout(fn, 0) should work.

The first answer to this Stack Overflow question explains what the technique does:
https://stackoverflow.com/questions/33955650/what-is-settimeout-doing-when-set-to-0-milliseconds/33955673

@scottaohara
Copy link
Owner

@ptrin, you wouldn't happen to have a chance to check this out again per my comment, would you?

@ptrin
Copy link
Author

ptrin commented Nov 5, 2019

setTimeout looks like it works just as well, so thanks for the suggestion @jfhector :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants