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

feat(multiselect): new All option for multiselect #16236

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

Gururajj77
Copy link
Contributor

@Gururajj77 Gururajj77 commented Apr 22, 2024

Closes #16117

Select All feature for multiselect

Changelog

New

  • All option created

Changed

  • changes in the logic for multiselect and selection.js

@Gururajj77 Gururajj77 changed the title Multiselect feat feat(multiselect): new All option for multiselect Apr 22, 2024
Copy link

netlify bot commented Apr 24, 2024

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 6efeca5
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/6644756633d46e00085efb6b
😎 Deploy Preview https://deploy-preview-16236--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Gururajj77 Gururajj77 marked this pull request as ready for review April 25, 2024 09:19
@Gururajj77 Gururajj77 requested a review from a team as a code owner April 25, 2024 09:19
Copy link
Contributor

@guidari guidari left a comment

Choose a reason for hiding this comment

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

Hey @Gururajj77 and @preetibansalui
Awesome new functionality! it is working perfect 🚀
Just a couple things I noticed

@@ -226,6 +227,8 @@ export interface MultiSelectProps<ItemType>
*/
items: ItemType[];

itemsWithSelectAll: ItemType[];
Copy link
Contributor

Choose a reason for hiding this comment

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

Add to MultiSelect.propTypes and also would good to insert a description, so when the user reads the Overview page it has more context.

/**
* to Show/Hide All option
*/
selectAll?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Add to MultiSelect.propTypes

@Gururajj77 Gururajj77 requested a review from a team as a code owner May 3, 2024 10:20
@Gururajj77 Gururajj77 requested a review from a team as a code owner May 7, 2024 09:35
@tay1orjones tay1orjones removed the request for review from tw15egan May 8, 2024 20:08
Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

Generally looks pretty good! I have some questions about fully-controlled usage and if or why itemsWithSelectAll is required. I'd think that selectAll would be enough to toggle the feature in the component without any additional props.

packages/react/src/components/MultiSelect/MultiSelect.tsx Outdated Show resolved Hide resolved
packages/react/src/components/MultiSelect/MultiSelect.tsx Outdated Show resolved Hide resolved
Comment on lines 403 to 405
const itemsWithSelectAll = selectAll
? [selectAllOption, ...filteredItems]
: filteredItems;
Copy link
Member

Choose a reason for hiding this comment

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

How does this work when the component is controlled via selectedItems? Does the user get the selectAllOption in the items returned through onChange? Should they get that back? How would someone using the controlled component check the select all, or mark it indeterminate? Do they need to or does it happen automatically?

It might be worth adding a controlled multiselect select-all example to storybook to discover the answers to some of these things, if we need to make some workarounds, and/or what to document in storybook.

If there are unavoidable prop conflicts, like selectAll just plain doesn't work with the component in a controlled state, then ideally we'd flag this with a warning in the dev console.

e.g.: "MultiSelect's selectAll prop does not work when in a controlled state using selectItems"

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi Taylor, Please find the response:

Does the user get the selectAllOption in the items returned through onChange?
Yes user will get selectAllOption in the items returned through onChange.

Should they get that back?
It's the part of Items now.

How would someone using the controlled component check the select all, or mark it indeterminate? Do they need to or does it happen automatically?
If they are using controlled component, they won't have access to selectAll or indeterminate state. To enable these things user has to enable 'hasSelectAll' as true.

If there are unavoidable prop conflicts, like selectAll just plain doesn't work with the component in a controlled state, then ideally we'd flag this with a warning in the dev console.
If we are adding the prop 'hasSelectAll' prop in controlled state, it will work simply as the default one. Only issue is we can have conflict of logics, for eg - the current controlled component is selecting disabled items as well while we are not.

While writing these responses, I found that we have to disable select All functionality in case of controlled state. User can either use selectedItems or hasSelectAll prop. We will add a console warning as suggested.

Comment on lines 676 to 678
const selectedItemsWithoutSelectAll = selectedItems.filter(
(item: any) => item.id !== 'select-all-option'
);
Copy link
Member

Choose a reason for hiding this comment

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

Is there are more reliable way to determine this? Thinking about how some consumers might already be rolling their own version of this feature and using this same id. It might be unavoidable, but thought I'd ask what you think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no we are using a new property in the selectAll object, called as selectAllFlag which just a boolean so that we don't mess with id being same as user's data.

@@ -580,5 +557,34 @@ describe('MultiSelect', () => {
`${prefix}--list-box__wrapper--slug`
);
});

it('should select all options when selectAll prop is true', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Along the same lines as the questions about controlled state - adding a test for how this is used with fully controlled selectedItems would be awesome. Select all, select none, indeterminate, etc.

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

Hey just wanted to comment what we chatted about on the side - I'm still a bit concerned around the lack of compatibility with the component being fully controlled through selectedItems. The prop warning is a decent stopgap measure but I think we should also mark it as experimental. This way, if/when we get feedback that hasSelectAll needs to work with selectedItems we can make the necessary changes without having to do a breaking change.

Once marked experimental I think this is good to merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MultiSelect (select all option): dev implementation
4 participants