Skip to content

feat(MultiSelect): Allow ReactNode to be used as checkbox label#1398

Open
ethanashaw wants to merge 2 commits into
mainfrom
feat/multiselect-reactnode-label
Open

feat(MultiSelect): Allow ReactNode to be used as checkbox label#1398
ethanashaw wants to merge 2 commits into
mainfrom
feat/multiselect-reactnode-label

Conversation

@ethanashaw

Copy link
Copy Markdown
Contributor

Done

  • Add a node prop to MultiSelectItem which overrides the label prop for the checkbox label. The label will still be used for alphabetical sorting and showing the list of selected items. This prop is intended to show additional information about the item beyond just its name.

QA

Pinging @canonical/react-library-maintainers for a review.

Storybook

To see rendered examples of all react-components, run:

yarn start

QA in your project

from react-components run:

yarn build
npm pack

Install the resulting tarball in your project with:

yarn add <path-to-tarball>

Percy steps

  • Added a informational label to some items in the default story.

Copilot AI review requested due to automatic review settings July 15, 2026 17:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR extends MultiSelect item rendering so a consumer can provide a richer checkbox label (via a ReactNode) while still keeping the plain-string label for sorting and displaying selected items.

Changes:

  • Added an optional node?: ReactNode to MultiSelectItem.
  • Updated dropdown checkbox rendering to prefer item.node over item.label.
  • Adjusted Storybook example and dropdown item styling to accommodate wider/custom label content.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/components/MultiSelect/MultiSelect.tsx Adds node to MultiSelectItem and uses it as the checkbox label when present.
src/components/MultiSelect/MultiSelect.stories.tsx Demonstrates the new node capability in the condensed story.
src/components/MultiSelect/MultiSelect.scss Ensures dropdown items/checkboxes can expand to full width for richer label layouts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

...Array.from({ length: 26 }, (_, i) => ({
label: `${String.fromCharCode(i + 65)}`,
value: `${String.fromCharCode(i + 65)}`,
node: <span style={{ display: "inline flex", justifyContent: "space-between", textIndent: 0, width: "100%" }}><span>{String.fromCharCode(i + 65)}</span><span className="u-text--muted">20 instances</span></span>
Comment on lines 192 to 196
<CheckboxInput
disabled={disabledItemValues.has(item.value)}
label={item.label}
label={item.node ?? item.label}
checked={selectedItemValues.has(item.value)}
value={item.value}
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.

2 participants