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

Lose focus when .focus() is called while the element already has the focus #673

Open
3 of 8 tasks
caoxiaoyi03 opened this issue Sep 12, 2018 · 1 comment
Open
3 of 8 tasks

Comments

@caoxiaoyi03
Copy link

Description

The paper-input element appears to lose its focus when .focus() is called while it already has the focus.

Expected outcome

Calling .focus() on paper-input when it's already in focus should keep the focus in the iron-input component.

Actual outcome

While paper-input appears to still have the focus (.focused === true), the iron-input inside is not (therefore, editing is not possible) and the appearance indicates out of focus.

Steps to reproduce

  1. Put a paper-input element in the page.
  2. Open the page in a web browser.
  3. Use some delaying mechanism (window.setTimeout or window.setInterval) to queue a .focus() call after some time.
  4. Focus on the paper-input element before the .focus() call triggers.
  5. Wait for the .focus() call to trigger. The paper-input element will appear to have lost its focus.

Live demo

This issue can be demonstrated with any live page with a paper-input element (for example, this page on WebComponents) by running the following code in console:

window.setInterval(() => {
  document.querySelector('paper-input').focus();
  console.log(document.querySelector('paper-input').focused);
}, 5000);

After the code above was run, whenever the first paper-input element on the page gets the focus, it will be gone during the next cycle in no more than 5 seconds. Console log will show that the .focused property of the paper-input is still true.

Browsers Affected

  • Chrome
  • Firefox
  • Safari 9 (not tested)
  • Safari 8 (not tested)
  • Safari 7 (not tested)
  • Edge
  • IE 11 (not tested due to not supporting ES6 features in the testing code)
  • IE 10 (not tested)
@caoxiaoyi03
Copy link
Author

While checking .focused before calling .focus() can be a workaround for this issue in most cases, this workaround will not prevent cases in other libraries (which should not expect .focus() to have such a behavior). For example, when using iron-dropdown's focusTarget property to link to a paper-input (I suppose .focus() is called in iron-dropdown's code).

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

No branches or pull requests

1 participant