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

CustomSelectControl: Refactor to use Ariakit store state for current value #67815

Merged
merged 5 commits into from
Dec 12, 2024

Conversation

yogeshbhutkar
Copy link
Contributor

@yogeshbhutkar yogeshbhutkar commented Dec 11, 2024

Fixes: #67759

What?

This PR fixes a bug where the Button component's description fails to update correctly when uncontrolled.

How?

The implementation replaces store.getState() with Ariakit.useStoreState(store) to accurately retrieve the current value, ensuring the description updates as expected.

Testing Instructions

  1. Add the below code snippet to the storybook.
export const Uncontrolled = {
	args: {
		...Default.args,
	},
};
  1. In DevTools, checkout out the accessibility panel for the main combobox button. The button description will now update after changing the selected options.

Screencast

Before:

custom-select-control-before-720p.mov

After:

Custom Select Control After

@yogeshbhutkar
Copy link
Contributor Author

This PR also works well with the previously raised issue #67721 and takes a different approach as mentioned in #67733.

Screen.Recording.2024-12-11.at.2.11.44.PM.mov

@yogeshbhutkar yogeshbhutkar marked this pull request as ready for review December 11, 2024 08:46
Copy link

github-actions bot commented Dec 11, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: yogeshbhutkar <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: mirka <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Components /packages/components labels Dec 11, 2024
@Mamaduka Mamaduka requested a review from a team December 11, 2024 08:56
Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @yogeshbhutkar! I can confirm that this fixes the issue.

Let's add a changelog entry. I think this is a good merge.

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirming this looks good and works well. Happy to ship once we have a CHANGELOG entry as @Mamaduka suggested.

Copy link
Member

@mirka mirka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh great, nice clean fix! Thank you 🙌

@yogeshbhutkar
Copy link
Contributor Author

Added changelog entry.

CC: @Mamaduka

@@ -46,6 +46,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` for optimistic updates ([#67815](https://github.com/WordPress/gutenberg/pull/67815))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `CustomSelectControl`: use `useStoreState` to get `currentValue` for optimistic updates ([#67815](https://github.com/WordPress/gutenberg/pull/67815))
- `CustomSelectControl`: Use `useStoreState` to get `currentValue` and avoid stale values ([#67815](https://github.com/WordPress/gutenberg/pull/67815)).

A minor suggestion. The optimistic updates refer to a different pattern, especially after the React 19 release.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion @Mamaduka. Fixed in the latest commit 🚀.

@Mamaduka Mamaduka merged commit 1168fa5 into WordPress:trunk Dec 12, 2024
62 of 63 checks passed
@github-actions github-actions bot added this to the Gutenberg 20.0 milestone Dec 12, 2024
yogeshbhutkar added a commit to yogeshbhutkar/gutenberg that referenced this pull request Dec 18, 2024
…value (WordPress#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Components /packages/components [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CustomSelectControl: Button description doesn't update correctly when uncontrolled
4 participants