-
Notifications
You must be signed in to change notification settings - Fork 11
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
fix(searchbar): clear controlled searchbar #448
Conversation
✅ Deploy Preview for objective-bell-0ffbfb canceled.
|
FYI: @seaerchin |
we pass |
react/src/Searchbar/Searchbar.tsx
Outdated
if (onChange) { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
onChange({ target: { value: '' } }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is controlled, why is it always firing with ''
ah? just curious
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since its controlled, we need to use onChange
to clear the external state when the clear button is pressed so we send ''
. For all other purposes, the onChange
function is just passed to the Input
component which will handle everything else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also use the useControllableState
hook to convert all uncontrolled/controlled props passed into the component into a controlled component? Then we can handle the current value much better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Problem
Support for controlled searchbars was introduced in #218. However, the clear button does not trigger the
onChange
function and only supports uncontrolled inputs.Closes #446
Solution
Check if the searchbar is a controlled input by checking for the presence of
onChange
. If it is a controlled input, callonChange
with the appropriate value.Tests