I have a Modal. It has a dropdown, an input, and a button.
When the modal launches the drop down has focus. I don’t want this, I want the button to have focus so the user can Hit Return and submit if the field already contains the values they want.
I tried placing the vanilla HTML autofocus attribute where I wanted it. It didn’t work. I tried setting the button as type “submit”. It didn’t work.
My code and an image of the Modal is below.
<div class="modal-container">
<.modal id={"delete-modal-#{testbed.id}"}>
<!-- Container -->
<!-- Login form -->
<div class="flex flex-wrap content-center justify-center bg-dark_blue_background text-white">
<div class="w-72 mt-10">
<!-- Heading -->
<small class="text-black-400 text-xl ">
You Are Reserving <%= testbed.name %>
</small>
<!-- Form -->
<form
class="mt-4"
phx-submit="create-status"
phx-hook="FormLocalStorageHook"
id={"local_storage_hoook-#{testbed.id}"}
>
<div class="mb-3">
<div class="flex justify-center"></div>
</div>
<div class="mb-3 h-2">
<input type="hidden" class="" value={testbed.id} name="testbed_id" />
</div>
<!--<div class="mb-3">
<label class="mb-2 block font-semibold">Status</label>
<input name="status" type="text" class="block w-full rounded-md border border-gray-300 focus:border-purple-700 focus:outline-none focus:ring-1 focus:ring-purple-700 py-1 px-1.5 text-gray-500" />
</div> -->
<div class="mb-6 ">
<p>Status</p>
<select
name="status"
id="status-id"
class="rounded mt-2 text-cyan-800"
>
<option value="Taken">Taken</option>
<option value="Frozen">Frozen</option>
</select>
</div>
<div class="mb-3">
<label class="mb-2 block font-semibold">Your Name</label>
<input
value={@developer}
name="developer"
type="text"
class="block w-full rounded-md border border-gray-300 focus:border-purple-700 focus:outline-none focus:ring-1 focus:ring-purple-700 py-1 px-1.5 text-gray-500"
/>
</div>
<div class="mb-3">
<.button class="bg-sky-500/75 mb-1.5 block w-full text-center text-white bg-cyan-700 hover:bg-cyan-900 px-2 py-1.5 rounded-md">
Reserve
</.button>
</div>
</form>
</div>
</div>
<!-- Login banner -->
</.modal>