[LG-5942]: Add customContent field to Combobox #3505
Conversation
🦋 Changeset detectedLatest commit: 9146e03 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Size Change: +41 B (0%) Total Size: 1.84 MB
ℹ️ View Unchanged
|
| }); | ||
|
|
||
| test('Option aria-label falls back to displayName text content', () => { | ||
| test('Option aria-label falls back to displayName', () => { |
There was a problem hiding this comment.
removed the previous unit test
| ref={optionRef} | ||
| highlighted={isFocused} | ||
| disabled={disabled} | ||
| aria-label={ariaLabel || getNodeTextContent(displayName) || value} |
There was a problem hiding this comment.
removed this function since displayName is now string!
| chromatic: { disableSnapshot: true }, | ||
| }; | ||
|
|
||
| export const WithCustomContent = () => { |
There was a problem hiding this comment.
added a new Story!
| ### Minor Changes | ||
|
|
||
| - aac0fd8: `ComboboxOption` now accepts a `ReactNode` for the `displayName` prop, enabling custom content like badges. Also refactored internal styles for better organization. | ||
| - aac0fd8: `ComboboxOption` now accepts a `customContent` prop (ReactNode) for rendering custom option content, while `displayName` remains a string for filtering, chips, and internal logic. Also refactored internal styles for better organization. |
There was a problem hiding this comment.
we shouldn't be retroactively changing the changelog.
Can you just mention in your changeset that you're adding a prop to fix what this was supposed to do?
| expect(optionEl).toHaveTextContent('New Feature'); | ||
| expect(optionEl).toHaveTextContent('New'); |
There was a problem hiding this comment.
Can we have the badge use different text? (or remove the text "New" from the display name?)
| expect(optionEl).toHaveAttribute('aria-label', 'New Feature'); | ||
| }); | ||
|
|
||
| test('New flow: option with customContent can be selected', () => { |
There was a problem hiding this comment.
Can we assert that "when an element with customContent is selected, the combobox should only render the displayName"
| * When undefined, this is set to `value` | ||
| */ | ||
| displayName?: ReactNode; | ||
| displayName?: string; |
There was a problem hiding this comment.
I think we can keep this as a ReactNode. That way this will only be a minor change
There was a problem hiding this comment.
Will file a followup ticket!
There was a problem hiding this comment.
Would love it if we can make the update in this PR
There was a problem hiding this comment.
Made the change! Will file a follow up ticket on the leafygreen team once this gets merged.
| --- | ||
| '@leafygreen-ui/combobox': major | ||
| --- | ||
|
|
||
| Added customContent field to render React.Node |
There was a problem hiding this comment.
- If we keep
displayName: ReactNodethis can just beminor - Can we add more details to this changeset?
b5d5fb1 to
d746f9e
Compare
d746f9e to
16a7cb4
Compare
16a7cb4 to
aa69286
Compare
97108d1 to
9146e03
Compare
|
Coverage after merging jt/LG-5942-FixCombobox into main will be
Coverage Report for Changed Files
|
|||||||||||||||||||||||||||||||
|
Filed a ticket to follow up on fixing the displayName prop situation https://jira.mongodb.org/browse/LG-5968 @TheSonOfThomp @adamrasheed |
✍️ Proposed changes
Context
We need a way to render a custom Node on Combobox. Slack conversation: https://mongodb.slack.com/archives/CFFA5BS79/p1767382709151629
We originally made a change to make displayNode a React.Node but it does not work. The root cause is because Combobox relies on
displayNameto track component state, so changing its type breaks that behavior.Solution
To support custom rendering, instead pass an optional custom field to each option. In the
ComboboxOption’s render function, check for this custom field and render it when present; otherwise, fall back to rendering the legacy displayName string. The new field is calledCustomContentIt follows the same pattern that Material UI uses: https://github.com/mui/material-ui/blob/10517bb1681da5a4fdbe0d6b7f4ca1e801066e98/packages/mui-material/src/Autocomplete/Autocomplete.js#L649 so should be industry standard.Also, I kept the change in https://github.com/mongodb/leafygreen-ui/pull/3434/changes that made
displayNamea ReactNode. Will file a follow up ticket on leafygreen to fix this. This will make it a minor release!Risk
Should be very low risk since
CustomContentis an optional prop.🎟️ Jira ticket: LG-5942
✅ Checklist
For bug fixes, new features & breaking changes
pnpm changesetand documented my changes🧪 How to test changes
Added unit tests.
Verified that this new field works as intended downstream on MMS
The New label is custom component added as part of
customContentScreen.Recording.2026-01-30.at.8.11.21.PM.mov