2022-06-16 14:56:53 +02:00
|
|
|
import { Controller } from '@hotwired/stimulus';
|
|
|
|
|
|
|
|
export class AutofocusController extends Controller {
|
|
|
|
connect() {
|
2024-10-04 10:26:18 +02:00
|
|
|
const element = this.element as HTMLInputElement | HTMLElement;
|
2022-06-16 14:56:53 +02:00
|
|
|
element.focus();
|
2024-10-04 10:26:18 +02:00
|
|
|
if ('value' in element) {
|
|
|
|
element.setSelectionRange(0, element.value.length);
|
|
|
|
}
|
2022-06-16 14:56:53 +02:00
|
|
|
}
|
|
|
|
}
|