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

Ensure options with value undefined are selected #1672

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

acelaya
Copy link
Contributor

@acelaya acelaya commented Aug 21, 2024

Fix an existing issue in MultiSelect, where options with value undefined, which special purpose is to clear the selection entirely, setting an empty array, are never marked as selected.

Additionally, when this type of option is selected, the listbox is automatically closed regardless of how it is selected (by clicking on it or by clicking on its checkbox). This is because this option will never be selectable together with other options, so it doesn't really make sense to keep it open.

Because of the point above, we should probably consider a different look-and-feel for this type of option, but I'm deferring that.

clear-option-fix-2024-08-21_11.54.59.mp4

@acelaya
Copy link
Contributor Author

acelaya commented Aug 21, 2024

Using <Option value={undefined} /> is not entirely intuitive, so we may want to move to a more idiomatic approach with a more clear API.

This draft proposes an alternative approach to do that #1671, that we can merge later after the main issue is solved.

@acelaya acelaya mentioned this pull request Aug 21, 2024
1 task
// In multi-select, clear selection for nullish values
if (!value) {
// In multi-select, clear selection for `undefined` values
if (value === undefined) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Being more explicit on what is the "special" value.

Copy link
Member

@robertknight robertknight left a comment

Choose a reason for hiding this comment

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

Can you add a test case for the new behavior. Otherwise this looks good.

@acelaya acelaya force-pushed the fix-multi-select-undefined-options branch from f834f8b to 0b32fde Compare August 21, 2024 12:34
@acelaya
Copy link
Contributor Author

acelaya commented Aug 21, 2024

Can you add a test case for the new behavior.

Done

@acelaya acelaya requested a review from robertknight August 21, 2024 12:34
Copy link

codecov bot commented Aug 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (cb89a41) to head (0b32fde).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1672   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           61        61           
  Lines         1061      1067    +6     
  Branches       413       415    +2     
=========================================
+ Hits          1061      1067    +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@acelaya acelaya merged commit 436937e into main Aug 21, 2024
4 checks passed
@acelaya acelaya deleted the fix-multi-select-undefined-options branch August 21, 2024 12:46
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.

2 participants