-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(input): prevent md-select-on-focus from refocusing blurred input #11129
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution! This looks really useful! I only made a few minor comments that will hopefully be easy to resolve. Then we can look at getting this merged 😄
src/components/input/input.js
Outdated
// Use HTMLInputElement#select to fix firefox select issues. | ||
// The debounce is here for Edge's sake, otherwise the selection doesn't work. | ||
element[0].select(); | ||
if(document.activeElement === element[0]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use $document
here and inject it above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a brief comment here explaining why this check is needed?
src/components/input/input.spec.js
Outdated
@@ -659,6 +659,23 @@ describe('md-input-container directive', function() { | |||
} | |||
})); | |||
|
|||
it('should not refocus the input after focus is lost', inject(function($timeout) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing, can we inject/use $document
here?
Thanks for taking the time to look this over @Splaktar and for the feedback! I'll make the updates, rebase, and get the updates pushed later today. |
dd9326e
to
38b82ed
Compare
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
84ee450
to
ed6f840
Compare
Eliminate race condition that causes a blurred input with md-select-on-focus from being re-selected. When there are two inputs with md-select-on-focus this can result in an infinite loop where focus moves back and forth between the two elements.
ed6f840
to
314d751
Compare
Changes have been made as suggested. Really sorry for any noise I generated while I tried to work through a git-mess-up-turned-git-disaster / Failed TravisCI builds. Phew! |
Just looking at googlebot's comment; not sure why it flipped the CLA status from "yes" to "no" (probably something I accidentally pushed while I was trying to rebase the pull request). To be clear, I have signed the CLA and am the only committer on this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Looks good. No problem with the git stuff. I know it happens 😄 |
…ngular#11129) Eliminate race condition that causes a blurred input with md-select-on-focus from being re-selected. When there are two inputs with md-select-on-focus this can result in an infinite loop where focus moves back and forth between the two elements.
…11129) Eliminate race condition that causes a blurred input with md-select-on-focus from being re-selected. When there are two inputs with md-select-on-focus this can result in an infinite loop where focus moves back and forth between the two elements.
Eliminate race condition that causes a blurred input with md-select-on-focus from being re-selected.
When there are two inputs with md-select-on-focus this can result in an infinite loop where focus
moves back and forth between the two elements.
PR Checklist
Please check that your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
md-select-on-focus will re-focus an input, even if it is no longer the active element on the page in order to select the input text. The most bizarre behaviour that this can produce is when there are two fields with md-select-on-focus that end up competing for focus in an infinite loop.
Here is a codepen with instructions to show the issue:
https://codepen.io/jonbcard/pen/PQQwLG
Issue Number: #11015
What is the new behavior?
md-select-on-focus will now only attempt to select the text of the field if it still retains focus.
Does this PR introduce a breaking change?
Other information