Skip to content

Commit

Permalink
Combobox Control: Add placeholder attribute (#65254)
Browse files Browse the repository at this point in the history
* Combobox Control: Add placeholder attribute

* Remove placeholder from default story

* Change placeholder type description and add it to README

* Add CHANGELOG entry
  • Loading branch information
zaguiini committed Sep 17, 2024
1 parent 99fefd7 commit be8f9b6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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 }
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;
};

0 comments on commit be8f9b6

Please sign in to comment.