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

CustomSelect: Add WordPressComponentsProps #56998

Merged
merged 3 commits into from
Dec 14, 2023
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 @@ -25,6 +25,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
Loading