Skip to content

Conversation

Steven7926
Copy link

@Steven7926 Steven7926 commented Jun 24, 2025

Summary

Related Issues or PRs

Closes #3201

How To Test

  1. Use the ComboBox and in the options passed to it, include a render function that returns the JSX to use for the option.
const options = Object.entries(fruits).map(([key, value]) => ({
  value: key,
  label: value,
  render: () => {
    return (
      <div className="padding-2 border border-base-lighter radius-md bg-white">
        <div className="font-sans-md text-bold">
          {value}
        </div>
        <div className="font-sans-sm text-base">
          Category: Fruit
        </div>
      </div>
    )
  }
}))
  1. Pass the options as the options prop to the ComboBox
  2. Click on the ComboBox and notice the options are rendered using the custom JSX you passed.

@Steven7926 Steven7926 requested review from a team as code owners June 24, 2025 14:18
@brandonlenz
Copy link
Contributor

When a maintainer has time to review and consider these changes, some things to evaluate:

  1. At some point <option> tags could only contain strings. Looks like that's no longer the case, but only for modern browsers
  2. The USWDS implementation only uses strings, so this is a case of balancing flexibility with potential footguns for consumers
  3. Consider the impacts on filtering. One of the core features of the combobox is to filter options by label against default or custom regex. It will be important for consumers to follow the USWDS guidance, if they're now able to render options that don't match their labels:

    Use option strings familiar to users. The combo box filters by matching strings. Include option text that includes familiar strings or spellings (for example, if using the combobox with a state list, include the postal abbreviation in the option text: District of Columbia (DC)).

I bet we'll want to document somewhere the details about filtering so that consumers don't get confused if their custom rendered content doesn't filter neatly if not tied closely to the label prop that they pass in

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.

[feat] Allow ComboBox to return JSX in its drop down options
2 participants