Skip to content
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

"wormholing" elements destroys focus, selection #22

Closed
adamesque opened this issue Jul 15, 2015 · 4 comments · Fixed by #23
Closed

"wormholing" elements destroys focus, selection #22

adamesque opened this issue Jul 15, 2015 · 4 comments · Fixed by #23

Comments

@adamesque
Copy link
Contributor

If an element to be sent through an ember-wormhole currently has (or is the parent of an element that has) focus, the process of reparenting the element during appendRange destroys focus and shifts document.activeElement back to the <body>.

I'm running into this when using ember-cli-focus-input inside an ember-modal-dialog — the {{focus-input}} component's didInsertElement handler fires first, focuses & selects the input element, but if the dialog is also opening at the same time, the wormhole's didInsertElement fires last, reparenting the DOM nodes and wiping out the focus.

It might be reasonable to check document.activeElement at the beginning of appendToDestination and hang on the element if it's part of the wormhole's content so focus could be restored on the other side of appendRange.

I'm not sure how much extra work you'd need to do to preserve selection ranges as well; I mostly care about the selection inside the text input, which might be easier to handle than generic selection.

adamesque added a commit to adamesque/ember-wormhole that referenced this issue Jul 16, 2015
@krisselden
Copy link
Contributor

can you add a test for this?

@adamesque
Copy link
Contributor Author

Oh weird — I did! It's in the PR, right?

@krisselden
Copy link
Contributor

Sorry, I assumed it was squashed, it is the PR, I was just looking at the one commit by mistake.

@adamesque
Copy link
Contributor Author

No worries — I can squash too if that's what you prefer. Thanks for taking a look!

xcambar pushed a commit to xcambar/ember-wormhole that referenced this issue Nov 4, 2016
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 a pull request may close this issue.

2 participants