-
Notifications
You must be signed in to change notification settings - Fork 12
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
How we can clear the old value? #23
Comments
You could probably make use of initialValue. const YourComponent = ({items}) => {
const [userSelectedValue, setUserSelectedValue] = useState('');
const onSelect = useCallback((selectedItem) => {
setUserSelectedValue(selectedItem.label);
...
}, []);
const onClose = useCallback(() => {
setUserSelectedValue('');
...
}, [setUserSelectedValue]);
return (
<Modal>
....
<DataListInput
placeholder="Select an option from the drop down menu..."
items={items}
onSelect={onSelect}
initialValue={userSelectedValue}
/>
....
</Modal>
);
}; Let me know if that works! |
Hi, maybe we could have ref prop that will have the input ref. thanks. |
Hi @margadt, Thanks for your feedback. Yeah, I was testing around with it earlier and I think the cleanest solution would be to introduce an optional I would probably deprecate Internally I would replace useEffect(() => {
if (value !== currentInput) {
setCurrentInput(value)
}
}, [value, currentInput]) (Currently, initalValue works kinda the same but I am only setting current input if it's empty and initialValue is not to protect the user input when the user is typing). So in case you need to manipulate the input field value in edge cases, you will have to manage the state of the input value on your own. The package already offers the Would that work for you? |
Hi @andrelandgraf , Thank you for the fast response, I'm trying to implement clean button like @sajidfrommerqata , great package though, |
Your clean button would need to There is a similar package react-select that makes use of this. You could use that package as well. |
Published as |
Works great, thanks for the patch. |
Thank you for your help. |
How we can clear the old value without a page refresh?
I'm using react-datalist-input in bootstrap modal. I want to clear the textbox when someone clicks on the close button of the modal.
Screenshot: https://prnt.sc/vn866j
Thanks
The text was updated successfully, but these errors were encountered: