I have a little form in a modal in my app. It's working just fine. I've just added an autoFocus on one of its input and it's not working as intended : the focus is on the right input, with the caret blinking and all. But I just can't type text in it. If I press my tabulation key, focus switch to next input but I still can't type anything.
- If I select any of those inputs with my mouse (before or after autofocus/focus with tabulation), I can type text, no problem at all.
- If I put autofocus on an input outside of the modal, it works : I can type text.
- If I remove all autofocus (like it was this morning) and navigate to my modal's inputs with tabulations, it's the same problem : looks focused but can't type any text.
- If I focus a modal's input with my mouse and navigate to the next one with tabulation, I can type text.
I've tried to put the same condition on this autofocus that triggers my modal's opening, but it doesn't change anything.
So, to sum it up : when dealing with a modal's form, I need an active mouse focus to init text typing in this form, even though visual focus can be achieved anyway.
I'm not sure it will help but here's my modal's form :
<form
name="modifyVersion"
autoComplete="off"
onClick={() => {
changingActiveVersion();
}}
onSubmit={(e) => {
e.preventDefault();
}}
>
<input
type="text"
id="versionNumber"
placeholder="X.Y.Z"
required
value={!existingVersion ? streamVersion : ""}
onChange={(e) => setStreamVersion(e.target.value)}
onKeyUp={(e) => {
if (e.key === "Enter" || e.keyCode === 13) {
handleEditCreate("version");
setModifiedVersion(true);
}
}}
// autoFocus={true}
/>
<input
type="text"
id="versionDescription"
placeholder="description"
required
value={!existingVersion ? versionDescription : ""}
onChange={(e) => setVersionDescription(e.target.value)}
/>
<button
type="button"
onClick={() => {
handleEditCreate && handleEditCreate("version");
setModifiedVersion(true);
}}
>
<i className="bi bi-plus-lg" style={{ fontSize: "1rem" }} />
</button>
</form>