Skip to content
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

Merged
merged 6 commits into from
Feb 22, 2024

Conversation

wjames111
Copy link
Contributor

@wjames111 wjames111 commented Feb 2, 2024

Description

Search needs x to clear on Contacts and Tasks. Ticket #MPDX-7837

Checklist:

  • I have given my PR a title with the format "MPDX-(JIRA#) (summary sentence max 80 chars)"
  • I have applied the appropriate labels. (Add the label "On Staging" to get the branch automatically merged into staging.)
  • I have requested a review from another person on the project

@wjames111 wjames111 added the On Staging Will be merged to the staging branch by Github Actions label Feb 2, 2024
@wjames111 wjames111 changed the title Adds type seach to base search text field. Adds type attribute to base search text field. Feb 2, 2024
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-869.d3dytjb8adxkk5.amplifyapp.com

@wjames111 wjames111 changed the title Adds type attribute to base search text field. [MPDX-7837] Adds type attribute to base search text field. Feb 12, 2024
@canac canac self-requested a review February 13, 2024 21:13
Copy link
Contributor

@canac canac left a 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

Copy link
Contributor

@canac canac left a 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 && (
Copy link
Contributor

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 === ''.

Copy link
Contributor Author

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.

@canac
Copy link
Contributor

canac commented Feb 14, 2024

@wjames111 It would also be great to add a simple test case for the new functionality.

@wjames111 wjames111 changed the title [MPDX-7837] Adds type attribute to base search text field. [MPDX-7837] Adds close adornment to base search text field. Feb 14, 2024
@wjames111
Copy link
Contributor Author

wjames111 commented Feb 14, 2024

@wjames111 It would also be great to add a simple test case for the new functionality.

@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.

Copy link
Contributor

@canac canac left a 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}
Copy link
Contributor

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');
Copy link
Contributor

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.

Copy link
Contributor Author

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));
Copy link
Contributor

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('');
Copy link
Contributor

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.

Copy link
Contributor

@canac canac left a 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.

src/components/common/SearchBox/SearchBox.test.tsx Outdated Show resolved Hide resolved
Co-authored-by: Caleb Cox <canac@users.noreply.github.com>
Copy link
Contributor

@dr-bizz dr-bizz left a 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.

src/components/common/SearchBox/SearchBox.tsx Show resolved Hide resolved
Copy link
Contributor

@dr-bizz dr-bizz left a 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.

@wjames111 wjames111 added On Staging Will be merged to the staging branch by Github Actions and removed On Staging Will be merged to the staging branch by Github Actions labels Feb 22, 2024
@wjames111
Copy link
Contributor Author

This has been added to Staging manually. Still showing a merge conflict for some reason.

@wjames111 wjames111 merged commit 5f96e71 into main Feb 22, 2024
17 of 19 checks passed
@wjames111 wjames111 deleted the 7837-clear-search-button branch February 22, 2024 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
On Staging Will be merged to the staging branch by Github Actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants