demarches-normaliennes/app/javascript/controllers/autofocus_controller.ts
2024-10-15 11:58:45 +02:00

11 lines
307 B
TypeScript

import { Controller } from '@hotwired/stimulus';
export class AutofocusController extends Controller {
connect() {
const element = this.element as HTMLInputElement | HTMLElement;
element.focus();
if ('value' in element) {
element.setSelectionRange(0, element.value.length);
}
}
}