Skip to content

Cover case where two focus traps are transitioned between pages #11

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

Merged
merged 2 commits into from
Sep 30, 2015

Conversation

nhunzaker
Copy link
Contributor

Hit an issue transitioning between two pages with focus traps in IE10 using hash location history. For some reason, focus is lost when the hash url changes (I think. It's kind of a mess to debug)

The real moral of the story is: don't use window#hash for URLs, but in any case this PR fixes the problem.

screen shot 2015-09-30 at 6 59 05 pm

// When transitioning between pages using hash route state,
// this anchor is some times lost. Do not attempt to focus
// on a non-existent anchor.
if (this.state.anchor != null && 'focus' in this.state.anchor) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be a strict equality check? just poking at it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually yes. If this value happens to be 0, or whatever, it'll throw an exception. Probably never going to happen, but I have no faith in that sort of thing anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thoughts on: if (typeof this.state.anchor === 'object' && 'focus' in this.state.anchor)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really, what we need is something like this.state.anchor instanceof ActualDOMElement

@averyvery
Copy link
Contributor

Ah, this is a good catch!

@nhunzaker nhunzaker merged commit a6293bb into master Sep 30, 2015
@nhunzaker nhunzaker deleted the fix-anchor-focus-edge-case branch December 15, 2015 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants