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

Components: ComboboxControl Item should support disabled option #60969

Closed
retrofox opened this issue Apr 22, 2024 · 0 comments · Fixed by #61294
Closed

Components: ComboboxControl Item should support disabled option #60969

retrofox opened this issue Apr 22, 2024 · 0 comments · Fixed by #61294
Assignees
Labels
[Package] Components /packages/components

Comments

@retrofox
Copy link
Contributor

retrofox commented Apr 22, 2024

Considering the disabled option is supported natively by the <select> HTML component for their children, it should similarly be supported by the <ComboboxControl /> Item component.

Here is an example of the disabled option for the regular <select> HTML element.

Item API

Once this implementation:

  • it would be possible to disable the item by passing the disabled property:
  • Item is not disabled as default
import { ComboboxControl } from '@wordpress/components';
import { useState } from '@wordpress/element';

const options = [
	{
		value: 'small',
		label: 'Small',
	},
	{
		value: 'normal',
		label: 'Normal',
		disabled: true,
	},
	{
		value: 'large',
		label: 'Large',
		disabled: false,
	},
];

function MyComboboxControl() {
	const [ fontSize, setFontSize ] = useState();
	const [ filteredOptions, setFilteredOptions ] = useState( options );
	return (
		<ComboboxControl
			label="Font Size"
			value={ fontSize }
			onChange={ setFontSize }
			options={ filteredOptions }
			onFilterValueChange={ ( inputValue ) =>
				setFilteredOptions(
					options.filter( ( option ) =>
						option.label
							.toLowerCase()
							.startsWith( inputValue.toLowerCase() )
					)
				)
			}
		/>
	);
}
@retrofox retrofox added the [Package] Components /packages/components label Apr 22, 2024
@retrofox retrofox self-assigned this Apr 22, 2024
@retrofox retrofox changed the title Components: ComboboxControl should support disabled option Apr 22, 2024
@retrofox retrofox linked a pull request May 2, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components
1 participant