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

Add custom search field support to ComboboxControl #68821

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

Infinite-Null
Copy link
Contributor

Closes: #68760

What?

Added a searchField prop to ComboboxControl that allows specifying which option field should be used for filtering suggestions.

Why?

Currently, ComboboxControl only uses the label field to filter matching suggestions, which limits its flexibility. There are cases where users might want to search through other fields like codes, IDs, or alternate names.

This enhancement allows developers to specify which field should be used for searching, making the component more versatile while maintaining backward compatibility by defaulting to the label field.

Testing Instructions

Testing Instructions

  1. Create or open any component that uses ComboboxControl
  2. Add an array of options with multiple fields, for example:
const options = [
  {
    value: 'us',
    label: 'United States',
    code: 'USA'
  },
  {
    value: 'uk',
    label: 'United Kingdom',
    code: 'GBR'
  }
];
  1. Set up the ComboboxControl with the new searchField prop:
<ComboboxControl
  options={options}
  searchField="code"
/>
  1. Type 'USA' or 'GBR' in the combobox input
  2. Verify that options are filtered based on the code field instead of the label
  3. Try removing the searchField prop and verify it falls back to searching by label

Screencast

Code for combobox:

<ComboboxControl
	__next40pxDefaultSize
	__nextHasNoMarginBottom
	options={ [
		{
		 value: 'dollor',
		 label: '$',
		 code: 'usd',
		},
		{
		 value: 'rupee',
		 label: '₹',
		 code: 'inr',
		},
	] }
	searchField="code"
/>
Screen.Recording.2025-01-22.at.12.26.25.PM.mov

Added a searchField prop to ComboboxControl that allows developers to specify
which field to use when filtering suggestions. This enabled searching through
fields other than just the label, making the component more flexible for
different use cases.
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Infinite-Null <[email protected]>
Co-authored-by: picocodes <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Mamaduka Mamaduka added [Type] Enhancement A suggestion for improvement. [Feature] UI Components Impacts or related to the UI component system [Package] Components /packages/components labels Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] UI Components Impacts or related to the UI component system [Package] Components /packages/components [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Combobox set key to use when calculating matching suggestions
2 participants