-
Notifications
You must be signed in to change notification settings - Fork 1
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
[MPDX-7837] Adds close adornment to base search text field. #869
Conversation
This pull request is automatically being deployed by Amplify Hosting (learn more). |
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.
The clear button works but is browser-dependent and doesn't really match our theme. If Scott is OK with that, then this is good. Otherwise, you could use an input adornment to add an x button that matches the MUI styles better. https://mui.com/material-ui/react-text-field/#input-adornments
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.
Nice! Can you figure out how to keep the width of the input from changing when the close button shows and hides? Maybe giving the <SearchInput>
an explicit width would help.
@@ -55,6 +74,18 @@ export const SearchBox: React.FC<SearchBoxProps> = ({ | |||
)} | |||
</InputAdornment> | |||
), | |||
endAdornment: ( | |||
<InputAdornment position="end"> | |||
{isClearSearchVisible && ( |
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.
Instead of using a separate state variable for this, I would just hide it when currentSearchTerm === ''
.
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.
Nice, yeah that makes better sense.
@wjames111 It would also be great to add a simple test case for the new functionality. |
…s simple test for SearchInput close button.
@canac Sounds good! I added a check for onClick to clear the textbox, and added a width so the textfield doesn't expand. From what I tested the width should be comparable to the size it was before on all screen sizes. Let me know if there's anything else before I mark it ready for QA. |
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.
Great work with the sizing and the tests!
<InputAdornment position="end"> | ||
{currentSearchTerm && ( | ||
<IconButton | ||
onClick={handleClearSearch} |
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.
I think you need to use handleOnChange
here so that onChange
gets called too. Currently, clicking x clears the search input but doesn't update the actual search filter on the page.
@@ -41,6 +41,7 @@ it('triggers onChange', async () => { | |||
); | |||
|
|||
const textbox = getByRole('textbox'); | |||
// const searchInputCloseButton = getByTestId('SearchInputCloseButton'); |
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.
Let's remove this if it's not needed.
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.
Oops, my bad.
@@ -49,4 +50,8 @@ it('triggers onChange', async () => { | |||
await new Promise((resolve) => setTimeout(resolve, 300)); |
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.
Instead of an explicit wait here, you can do await waitFor(() => expect(onChange).toHaveBeenCalledWith(inputText));
|
||
userEvent.click(getByTestId('SearchInputCloseButton')); | ||
|
||
expect(textbox).toHaveValue(''); |
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.
Let's also test that onChange
gets called with ''
to prove that the bug I mentioned below gets fixed.
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.
It looks good! 🎉 I left one suggestion for the test. I would also rebase these commits down to just one at some point before merging. Then you can add the "On Staging" label if you haven't yet and move the ticket over.
Co-authored-by: Caleb Cox <canac@users.noreply.github.com>
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.
Looks great. I just had one comment to make the simplify the code.
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.
Great work! 🔥
You need to merge this branch into staging locally and push it up to staging, then you can retry the staging test on this PR.
Staging is a little broken these days. I'm trying to fix it ATM.
This has been added to Staging manually. Still showing a merge conflict for some reason. |
Description
Search needs x to clear on Contacts and Tasks. Ticket #MPDX-7837
Checklist: