-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Select text input content on trapFocus #2106
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,13 @@ function trapFocus(container, elementToFocus = container) { | |
| document.addEventListener('focusin', trapFocusHandlers.focusin); | ||
|
|
||
| elementToFocus.focus(); | ||
|
|
||
| if (elementToFocus.tagName === 'INPUT' && | ||
| ['search', 'text', 'email', 'url'].includes(elementToFocus.type) && | ||
| elementToFocus.value) { | ||
| const end = elementToFocus.value.length; | ||
| elementToFocus.setSelectionRange(0, end); | ||
FCalabria marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this is in the We currently run
In all those cases, I think the search is the only scenario where the element receiving focus due to our I'm not sure if introducing this behaviour only for that one specific part of the theme makes sense when the rest of the input don't get the same behaviour on focus 🤔 But then having a listener for What do you think ? 🤔
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding this on every If there were some way to know if a focus has being triggered programatically or not (or by a mouse click) it could be a nice improvement for the theme, but I don't know any reliable way to do that.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'll approve the PR 👍 Though we should wait a bit before merging (once you get the second approval). |
||
| } | ||
|
|
||
| // Here run the querySelector to figure out if the browser supports :focus-visible or not and run code based on it. | ||
|
|
||
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.
Search only focuses when I close and re-enter the field:https://screenshot.click/08-12-xeqqs-dai70.mp4
That doesnt happen for the other inputs: https://screenshot.click/08-15-5ykcg-12f5p.mp4
Is that expected? 👀
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.
Interesting, I cannot reproduce that https://screenshot.click/10-59-0u5in-jynpn.mp4
What browser are you using? You are just tabbing around, right?
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.
I am using chrome and just tabbing 🤔 Am I missing something?
https://screenshot.click/10-34-j4hjv-6b43g.mp4
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.
This is meant to be that way based on how it's added in the code:
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.
Interesting 🤔 Then how come Paqui is able to do it in her video? https://screenshot.click/10-59-0u5in-jynpn.mp4
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.
That should be standard browser behaviour, it's not due to any change i have done
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.
What I mean is that the text input's content is selected when automatically focusing it on your video but not in mine
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.
We paired and it turns out that you need to use
shifttaband it does select it then :)