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

Combobox Control: Add placeholder attribute #65254

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
### New Features

- `Composite`: add stable version of the component ([#63569](https://github.com/WordPress/gutenberg/pull/63569)).
- `ComboboxControl`: add support for `placeholder` attribute ([#65254](https://github.com/WordPress/gutenberg/pull/65254)).

### Enhancements

Expand Down
7 changes: 7 additions & 0 deletions packages/components/src/combobox-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ If the control is clicked, the dropdown will expand regardless of this prop.
- Required: No
- Default: `true`

### placeholder

If passed, the combobox input will show a placeholder string if no values are present.

- Type: `string`
- Required: No

#### __experimentalRenderItem

Custom renderer invoked for each option in the suggestion list. The render prop receives as its argument an object containing, under the `item` key, the single option's data (directly from the array of data passed to the `options` prop).
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/combobox-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ function ComboboxControl( props: ComboboxControlProps ) {
},
__experimentalRenderItem,
expandOnFocus = true,
placeholder,
} = useDeprecated36pxDefaultSizeProp( props );

const [ value, setValue ] = useControlledValue( {
Expand Down Expand Up @@ -340,6 +341,7 @@ function ComboboxControl( props: ComboboxControlProps ) {
className="components-combobox-control__input"
instanceId={ instanceId }
ref={ inputContainer }
placeholder={ placeholder }
zaguiini marked this conversation as resolved.
Show resolved Hide resolved
value={ isExpanded ? inputValue : currentLabel }
onFocus={ onFocus }
onBlur={ onBlur }
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/combobox-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,8 @@ export type ComboboxControlProps = Pick<
* The current value of the control.
*/
value?: string | null;
/**
* If passed, the combobox input will show a placeholder string if no values are present.
*/
placeholder?: string;
zaguiini marked this conversation as resolved.
Show resolved Hide resolved
};
Loading