DEV: Add selectText option to auto-focus modifier (#24458)

This commit is contained in:
Jarek Radosz 2023-11-20 14:53:20 +01:00 committed by GitHub
parent c5affa9ca2
commit 1a43010603
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,11 +3,15 @@ import Modifier from "ember-modifier";
export default class AutoFocusModifier extends Modifier { export default class AutoFocusModifier extends Modifier {
didFocus = false; didFocus = false;
modify(element) { modify(element, _, { selectText }) {
if (!this.didFocus) { if (!this.didFocus) {
element.autofocus = true; element.autofocus = true;
element.focus(); element.focus();
if (selectText) {
element.select();
}
this.didFocus = true; this.didFocus = true;
} }
} }