Skip to content

Commit cf05d0d

Browse files
authored
Select text input content on trapFocus (#2106)
* Select text input content on trapFocus * PR fix
1 parent b86d1f3 commit cf05d0d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

assets/global.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ function trapFocus(container, elementToFocus = container) {
6868
document.addEventListener('focusin', trapFocusHandlers.focusin);
6969

7070
elementToFocus.focus();
71+
72+
if (elementToFocus.tagName === 'INPUT' &&
73+
['search', 'text', 'email', 'url'].includes(elementToFocus.type) &&
74+
elementToFocus.value) {
75+
elementToFocus.setSelectionRange(0, elementToFocus.value.length);
76+
}
7177
}
7278

7379
// Here run the querySelector to figure out if the browser supports :focus-visible or not and run code based on it.

0 commit comments

Comments
 (0)