-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change focus
to input
tag
#3
Comments
A workaround could be to wrap the component in another element, then watch the click event on it to focus the inner input...
Ideally, this lib would expose the ref from the inner input for this kind of thing. |
Here is a fully working (as Id expect UX-wise, anyway) solution. It uses const EmailsInput = () => {
const [selected, setSelected] = useState([]);
const wrapperRef = useRef(null);
const handleWrapperClick = e => {
const wrapperEl = wrapperRef.current;
if (!wrapperEl) {
return;
}
const rtiContainerEl = wrapperEl.querySelector(".rti--container");
const rtiInputEl = wrapperEl.querySelector(".rti--input");
if (!rtiInputEl) {
return;
}
// Prevent default so that the input doesn't lose focus, if the mousedown
// event occured on the RTI container el wrapped by our outer wrapper el.
if (e.target === rtiContainerEl) {
e.preventDefault();
}
// Focus the input. If it was previously focused it will retain focus.
rtiInputEl.focus();
};
return (
<div ref={wrapperRef} onMouseDown={handleWrapperClick}>
<TagsInput
value={selected}
onChange={setSelected}
name="Email Addresses"
placeHolder="Add Email Address..."
isEditOnRemove={true}
separators={
[
"Enter",
"Tab",
",",
" "
]
}
/>
<div className="flex flex-row justify-end text-xs text-zinc-500 mt-2">
<em>Press "return" or "enter" to add new emails.</em>
</div>
</div>
);
}; Bless. |
I need change a focus to
input
tag whendiv
withrti--container
class clicked. I think that's more better .The text was updated successfully, but these errors were encountered: