Skip to content

Commit be8f9b6

Browse files
authored
Combobox Control: Add placeholder attribute (#65254)
* Combobox Control: Add placeholder attribute * Remove placeholder from default story * Change placeholder type description and add it to README * Add CHANGELOG entry
1 parent 99fefd7 commit be8f9b6

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

packages/components/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
### New Features
1616

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

1920
### Enhancements
2021

packages/components/src/combobox-control/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ If the control is clicked, the dropdown will expand regardless of this prop.
111111
- Required: No
112112
- Default: `true`
113113

114+
### placeholder
115+
116+
If passed, the combobox input will show a placeholder string if no values are present.
117+
118+
- Type: `string`
119+
- Required: No
120+
114121
#### __experimentalRenderItem
115122

116123
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).

packages/components/src/combobox-control/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ function ComboboxControl( props: ComboboxControlProps ) {
129129
},
130130
__experimentalRenderItem,
131131
expandOnFocus = true,
132+
placeholder,
132133
} = useDeprecated36pxDefaultSizeProp( props );
133134

134135
const [ value, setValue ] = useControlledValue( {
@@ -340,6 +341,7 @@ function ComboboxControl( props: ComboboxControlProps ) {
340341
className="components-combobox-control__input"
341342
instanceId={ instanceId }
342343
ref={ inputContainer }
344+
placeholder={ placeholder }
343345
value={ isExpanded ? inputValue : currentLabel }
344346
onFocus={ onFocus }
345347
onBlur={ onBlur }

packages/components/src/combobox-control/types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,8 @@ export type ComboboxControlProps = Pick<
8282
* The current value of the control.
8383
*/
8484
value?: string | null;
85+
/**
86+
* If passed, the combobox input will show a placeholder string if no values are present.
87+
*/
88+
placeholder?: string;
8589
};

0 commit comments

Comments
 (0)