Skip to content

Commit

Permalink
Clean up types
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka committed Aug 2, 2024
1 parent ec359ad commit 2c01c7d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
9 changes: 8 additions & 1 deletion packages/components/src/select-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ In most cases, it is preferable to use the `FormTokenField` or `CheckboxControl`

#### options

An array of objects containing the following properties:
An array of objects containing the following properties, as well as any other `option` element attributes:

- `label`: (string) The label to be shown to the user.
- `value`: (string) The internal value used to choose the selected value. This is also the value passed to onChange when the option is selected.
Expand All @@ -214,6 +214,13 @@ If multiple is false the value received is a single value with the new selected
- Type: `function`
- Required: Yes

#### value

The value of the selected option. If `multiple` is true, the `value` should be an array with the values of the selected options.

- Type: `String|String[]`
- Required: No

#### variant

The style variant of the control.
Expand Down
24 changes: 20 additions & 4 deletions packages/components/src/select-control/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import type { ChangeEvent, FocusEvent, ReactNode } from 'react';
import type { ChangeEvent, ReactNode } from 'react';

/**
* Internal dependencies
Expand All @@ -22,8 +22,11 @@ type SelectControlBaseProps = Pick<
| 'suffix'
> &
Pick< BaseControlProps, 'help' | '__nextHasNoMarginBottom' > & {
onBlur?: ( event: FocusEvent< HTMLSelectElement > ) => void;
onFocus?: ( event: FocusEvent< HTMLSelectElement > ) => void;
/**
* An array of option property objects to be rendered,
* each with a `label` and `value` property, as well as any other
* `<option>` attributes.
*/
options?: ( {
/**
* The label to be shown to the user.
Expand All @@ -34,7 +37,10 @@ type SelectControlBaseProps = Pick<
* This is also the value passed to `onChange` when the option is selected.
*/
value: string;
} & Omit< React.ComponentProps< 'option' >, 'label' | 'value' > )[];
} & Omit<
React.OptionHTMLAttributes< HTMLOptionElement >,
'label' | 'value'
> )[];
/**
* As an alternative to the `options` prop, `optgroup`s and `options` can be
* passed in as `children` for more customizability.
Expand All @@ -57,6 +63,11 @@ export type SelectControlSingleSelectionProps = SelectControlBaseProps & {
* @default false
*/
multiple?: false;
/**
* The value of the selected option.
*
* If `multiple` is true, the `value` should be an array with the values of the selected options.
*/
value?: string;
/**
* A function that receives the value of the new option that is being selected as input.
Expand All @@ -79,6 +90,11 @@ export type SelectControlMultipleSelectionProps = SelectControlBaseProps & {
* @default false
*/
multiple: true;
/**
* The value of the selected option.
*
* If `multiple` is true, the `value` should be an array with the values of the selected options.
*/
value?: string[];
/**
* A function that receives the value of the new option that is being selected as input.
Expand Down

0 comments on commit 2c01c7d

Please sign in to comment.