Skip to content

Commit

Permalink
Add support for custom popover props to CustomSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Feb 21, 2024
1 parent 1317cb9 commit 41243b8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Enhancements

- `CustomSelectControlV2`: Support custom popover props.([#57780](https://github.com/WordPress/gutenberg/pull/57780)).

## 26.0.1 (2024-02-13)

### Bug Fix
Expand Down
6 changes: 6 additions & 0 deletions packages/components/src/custom-select-control-v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ A function that receives the new value of the input.
- Required: no
##### `popoverProps`: `Object`
Optional props passed to the Ariakit Select Popover.
- Required: no
##### `renderSelectedValue`: `( selectValue: string | string[] ) => React.ReactNode`
Can be used to render select UI with custom styled values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,18 @@ function _CustomSelect( props: _CustomSelectProps & CustomSelectStore ) {
children,
hideLabelFromVision = false,
label,
popoverProps,
store,
...restProps
} = props;

const selectPopoverProps = {
gutter: 12,
sameWidth: true,
...popoverProps,
store,
};

return (
<>
{ hideLabelFromVision ? ( // TODO: Replace with BaseControl
Expand All @@ -110,7 +118,7 @@ function _CustomSelect( props: _CustomSelectProps & CustomSelectStore ) {
</Styled.SelectLabel>
) }
<CustomSelectButton { ...restProps } store={ store } />
<Styled.SelectPopover gutter={ 12 } store={ store } sameWidth>
<Styled.SelectPopover { ...selectPopoverProps }>
<CustomSelectContext.Provider value={ { store } }>
{ children }
</CustomSelectContext.Provider>
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/custom-select-control-v2/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export type _CustomSelectProps = {
* Accessible label for the control.
*/
label: string;
/**
* Optional props passed to the Ariakit Select Popover.
*/
popoverProps?: Ariakit.SelectPopoverProps;
};

export type CustomSelectProps = _CustomSelectProps &
Expand Down

0 comments on commit 41243b8

Please sign in to comment.