demarches-normaliennes/app/javascript/controllers/autofocus_controller.ts

9 lines
255 B
TypeScript

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