Skip to content

Commit

Permalink
CustomSelectControl: Refactor to use Ariakit store state for current …
Browse files Browse the repository at this point in the history
…value (#67815)


Co-authored-by: yogeshbhutkar <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: mirka <[email protected]>
  • Loading branch information
5 people authored Dec 12, 2024
1 parent 795e9c2 commit 1168fa5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

- `ResizableBox`: Make drag handles focusable ([#67305](https://github.com/WordPress/gutenberg/pull/67305)).
- `CustomSelectControl`: Update correctly when `showSelectedHint` is enabled ([#67733](https://github.com/WordPress/gutenberg/pull/67733)).
- `CustomSelectControl`: Use `useStoreState` to get `currentValue` and avoid stale values ([#67815](https://github.com/WordPress/gutenberg/pull/67815)).

## 28.13.0 (2024-11-27)

Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/custom-select-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,16 @@ function CustomSelectControl< T extends CustomSelectOption >(
);
} );

const { value: currentValue } = store.getState();
const currentValue = Ariakit.useStoreState( store, 'value' );

const renderSelectedValueHint = () => {
const selectedOptionHint = options
?.map( applyOptionDeprecations )
?.find( ( { name } ) => store.getState().value === name )?.hint;
?.find( ( { name } ) => currentValue === name )?.hint;

return (
<Styled.SelectedExperimentalHintWrapper>
{ store.getState().value }
{ currentValue }
{ selectedOptionHint && (
<Styled.SelectedExperimentalHintItem
// Keeping the classname for legacy reasons
Expand Down

0 comments on commit 1168fa5

Please sign in to comment.