ui(components): auto-focus first input in modal on open

- Added an x-init directive to automatically focus the first input element (input, textarea, or select) when the modal is opened, enhancing user experience and accessibility.
This commit is contained in:
Andras Bacsai 2025-10-01 18:43:32 +02:00
parent b00ab4c35f
commit 67ff4d0f8a

View file

@ -28,6 +28,7 @@ class="relative w-auto h-auto" wire:ignore>
@endif
<template x-teleport="body">
<div x-show="modalOpen"
x-init="$watch('modalOpen', value => { if(value) { $nextTick(() => { const firstInput = $el.querySelector('input, textarea, select'); firstInput?.focus(); }) } })"
class="fixed top-0 left-0 lg:px-0 px-4 z-99 flex items-center justify-center w-screen h-screen">
<div x-show="modalOpen" x-transition:enter="ease-out duration-100" x-transition:enter-start="opacity-0"
x-transition:enter-end="opacity-100" x-transition:leave="ease-in duration-100"