You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 23, 2022. It is now read-only.
I'm not a UX researcher but I do know that it can feel a bit disorienting to be typing in an input and for it to just disappear with no other feedback when I hit enter. If the list of chips is long the user might not immediately realize there was a duplicate. A simple solution I came up with (maybe this exists already? felt pretty intuitive to me) is to focus the already-created chip so the user can clearly see that the chip exists already, until the user begins typing again:
I was able to implement this using a component ref and calling setState() from the parent:
functionFocusDuplicatesChipInput({ onAdd, ...rest}){constchips=rest.value;constchipInputRef=React.useRef();consthandleAdd=React.useCallback(chip=>{constfoundIndex=chips.findIndex(c=>chip===c);if(foundIndex>-1&&chipInputRef.current){chipInputRef.current.setState({focusedChip: foundIndex});}else{onAdd(chip);}},[chips,onAdd,chipInputRef]);return(<ChipInput{...rest}ref={chipInputRef}allowDuplicates// except not reallyonAdd={handleAdd}/>);}
If you were able to implement this, there's no need to increase the maintenance overhead of this component. :) If you want, you can create a PR that adds this great example to the storybook. 👍
Hmm.. the reason I'm not sure about that is because I don't normally think of setState() as a public API. It would imply that you won't change the effect of setting the focusedChip internal state until the next major version, and it would need to be documented. If that's fine, I would suggest componentRef.setState({ focusedChip }) should be added to the docs as API, not just an example. What do you think?
I'm not a UX researcher but I do know that it can feel a bit disorienting to be typing in an input and for it to just disappear with no other feedback when I hit enter. If the list of chips is long the user might not immediately realize there was a duplicate. A simple solution I came up with (maybe this exists already? felt pretty intuitive to me) is to focus the already-created chip so the user can clearly see that the chip exists already, until the user begins typing again:
I was able to implement this using a component ref and calling
setState()
from the parent:Playground: https://codesandbox.io/s/quizzical-field-t2kk9?file=/src/App.js
Obviously it would be much nicer for this to be implemented as a prop-driven option inside of
ChipInput
.The text was updated successfully, but these errors were encountered: