Skip to content

Commit

Permalink
CustomSelect: Add WordPressComponentsProps (#56998)
Browse files Browse the repository at this point in the history
* CustomSelectControl v2: Add WordPressComponentsProps

* Add WordPressComponentProps as button to CustomSelect

* Update changelog
  • Loading branch information
brookewp authored and artemiomorales committed Jan 4, 2024
1 parent 6df1143 commit d370173
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
### Experimental

- `Tabs`: implement new `tabId` prop ([#56883](https://github.com/WordPress/gutenberg/pull/56883)).
- `CustomSelect`: add `WordPressComponentsProps` for more flexibility ([#56998](https://github.com/WordPress/gutenberg/pull/56998))

### Experimental

Expand Down
25 changes: 13 additions & 12 deletions packages/components/src/custom-select-control-v2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
CustomSelectItemProps,
CustomSelectContext as CustomSelectContextType,
} from './types';
import type { WordPressComponentProps } from '../context';

export const CustomSelectContext =
createContext< CustomSelectContextType >( undefined );
Expand All @@ -41,17 +42,16 @@ function defaultRenderSelectedValue( value: CustomSelectProps[ 'value' ] ) {
return value;
}

export function CustomSelect( props: CustomSelectProps ) {
const {
children,
defaultValue,
label,
onChange,
size = 'default',
value,
renderSelectedValue = defaultRenderSelectedValue,
} = props;

export function CustomSelect( {
children,
defaultValue,
label,
onChange,
size = 'default',
value,
renderSelectedValue = defaultRenderSelectedValue,
...props
}: WordPressComponentProps< CustomSelectProps, 'button', false > ) {
const store = Ariakit.useSelectStore( {
setValue: ( nextValue ) => onChange?.( nextValue ),
defaultValue,
Expand All @@ -66,6 +66,7 @@ export function CustomSelect( props: CustomSelectProps ) {
{ label }
</Styled.CustomSelectLabel>
<Styled.CustomSelectButton
{ ...props }
size={ size }
hasCustomRenderProp={ !! renderSelectedValue }
store={ store }
Expand All @@ -85,7 +86,7 @@ export function CustomSelect( props: CustomSelectProps ) {
export function CustomSelectItem( {
children,
...props
}: CustomSelectItemProps ) {
}: WordPressComponentProps< CustomSelectItemProps, 'div', false > ) {
const customSelectContext = useContext( CustomSelectContext );
return (
<Styled.CustomSelectItem
Expand Down

0 comments on commit d370173

Please sign in to comment.