-
Notifications
You must be signed in to change notification settings - Fork 58
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(searchbox): handle Enter key in the input field to search + blur #1065
Conversation
Now I noticed the difference. In Vanilla examples the So a better solution would be to change the React component to use |
This is needed every time we have a search box to filter the results in any table / list of results. No form in that case as the action (filtering) is performed |
I don't think this component was meant to do filtering at all. Search & Filter component was meant to more advanced search and filter functionality. |
Maybe I didn't express myself properly. By "filtering" I mean setting a search query and showing only the results matching that query, as in the example below: I don't think the |
I guess we get to the point where it's more of a design UX question than implementation question. So far the If neither component does what you want to do, it's something that should be brought up in design (possibly Vanilla Working Group). |
|
a7c6ae3
to
cb3b51b
Compare
I agree that As for the functionality itself, it seems that the fact that there actually is |
Good point. I will test this specifically and get back to you with the result. |
@bartaz I tested the behaviour in I'm not sure this is a good approach to test it, what do you think? Should I add an |
I'm afraid that adding that in by default will actually prevent ENTER from triggering submit of a form when it's needed. The only problematic scenario may be if someone has both |
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 from code point of view.
I'm not 100% sure if blur by default is a desired behaviour (what if there is some validation and you should stay in the search to fix the value?). But I guess we can verify in practice if that creates any issues. |
What about changing the condition to:
Would that be a good solution? |
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
cb3b51b
to
5e4c27e
Compare
@@ -91,6 +91,13 @@ const SearchBox = React.forwardRef<HTMLInputElement, Props>( | |||
onSearch && onSearch(); | |||
}; | |||
|
|||
const onKeyDown = (e: KeyboardEvent<HTMLInputElement>) => { | |||
if (e.key === "Enter" && internalRef.current.checkValidity()) { |
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.
This should stop blur when the input contains an invalid value (#1065 (comment))
🎉 This PR is included in version 0.51.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Done
SearchBox
trigger search on Enter keydown, and blur the input field.QA
Storybook
To see rendered examples of all react-components, run:
QA in your project
from
react-components
run:Install the resulting tarball in your project with:
QA steps
SearchBox
examples in StorybookPercy steps
This should not produce visual changes in Percy.