Skip to content

SelectMultiple - Change select all and clear all buttons to show when searching #6456

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

Merged
merged 5 commits into from
Nov 2, 2022

Conversation

jcfilben
Copy link
Collaborator

@jcfilben jcfilben commented Oct 26, 2022

What does this PR do?

Adjusts the behavior of SelectMultiple to show 'Select All' and 'Clear All' buttons when searching.

Note: In the original issue it was mentioned that the buttons should be labeled 'Select All Matches' and 'Clear All Matches' when the options are being filtered by a search term. When I tried this the button labels felt too long and they were taking up too much space within the SelectMultiple drop.

This PR also fixes an issue where selected options were bubbling up when searching. Options should only bubble on after the drop is closed an re-opened.

Where should the reviewer start?

What testing has been done on this PR?

How should this be manually tested?

Test with the existing SelectMultiple stories. Open the drop and type in the search. The 'Select All'/'Clear All' button should still be visible.

Do Jest tests follow these best practices?

  • screen is used for querying.
  • The correct query is used. (Refer to this list of queries)
  • userEvent is used in place of fireEvent.
  • asFragment() is used for snapshot testing.

Any background context you want to provide?

What are the relevant issues?

Closes #6444
Closes #6447

Screenshots (if appropriate)

Do the grommet docs need to be updated?

No

Should this PR be mentioned in the release notes?

Yes

Is this change backwards compatible or is it a breaking change?

Backwards compatible

@jcfilben jcfilben requested a review from halocline October 26, 2022 18:49
Copy link
Collaborator

@halocline halocline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a scenario where I :

  • search for "p"
  • Select All selects "Apple", "Grape", and "Raspberry"
  • clear search and search for "z"

Do we show a button here? I don't think so, but just asking to validate our current thinking.


There is a scenario where I :

  • search for "p"
  • Select All selects "Apple", "Grape", and "Raspberry"
  • clear search and search for "w"
  • Select All adds "Strawberry" and "Kiwi" to the existing selection, resulting in 5 options selected
  • clear search and search for "b"

We show "Clear all" instead of "Select all" here. Is that what we want? I think so, but again just surveying edge cases.


Lastly, I think this PR would be a good candidate to improve our test scenario coverage. Can we add a Jest test which executes the second scenario above with assertions throughout?

? `Select all ${options.length} options`
: `${value?.length} options selected. Clear all?`
}
label={showSelectAll ? 'Select All' : 'Clear All'}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If "Select all matches" and "Clear all matches" is too verbose, two alternatives to explore:

  1. "Select matches" and "Clear matches"
  2. <Button size="small" ... /> could be reasonable. May need to implement as theme prop.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matt and I had an offline discussion about this one and agreed it could be handled in a separate issue. Changing to "Select matches" and "Clear matches" is still affecting the width of the drop container. I think the naming is clearer but we may want to look into sizing of the button, how comfortable are we with affecting the drop container width, etc. So I think this work could be handled separately

@jcfilben
Copy link
Collaborator Author

There is a scenario where I :

search for "p"
Select All selects "Apple", "Grape", and "Raspberry"
clear search and search for "z"
Do we show a button here? I don't think so, but just asking to validate our current thinking.

We don't show a button here since no matches were found after searching 'z'.

There is a scenario where I :

search for "p"
Select All selects "Apple", "Grape", and "Raspberry"
clear search and search for "w"
Select All adds "Strawberry" and "Kiwi" to the existing selection, resulting in 5 options selected
clear search and search for "b"
We show "Clear all" instead of "Select all" here. Is that what we want? I think so, but again just surveying edge cases.

Yes, we show 'Clear All' whenever any options are in the search results and selected.

Lastly, I think this PR would be a good candidate to improve our test scenario coverage. Can we add a Jest test which executes the second scenario above with assertions throughout?

Good idea I realized I didn't add a test in my latest commit but I will go back and add a test for this

@jcfilben jcfilben marked this pull request as draft October 28, 2022 22:47
@jcfilben
Copy link
Collaborator Author

Marking as draft, I need to go back and add a unit test

@jcfilben jcfilben marked this pull request as ready for review October 31, 2022 19:25
@jcfilben jcfilben requested a review from halocline October 31, 2022 19:26
@ericsoderberghp ericsoderberghp merged commit 3efc50c into grommet:master Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SelectMultiple - Gap between number of items selected and search box is chnaging SelectMultiple - show 'Select All' button when searching
3 participants