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 V2: prevent keyboard event propagation in legacy wrapper #62907

Merged

Conversation

ciampo
Copy link
Contributor

@ciampo ciampo commented Jun 27, 2024

What?

Part of #55023

Prevent keyboard events propagation from the select popover in CustomSelectControlV2 legacy wrapper

Why?

To align the behavior of the V2 legacy wrapper to the V1 version of the component. Here's more context to why the V1 stops event propagation.

Note

I personally think that this behaviour is non-standard and shouldn't be retained for the V2 (non-legacy) version of the component.

How?

  • Introduced a way for the internal V2 implementation to know whether its consumer is "legacy" or not
  • when in "legacy" mode, stopped keydown event propagation on the select dropdown
  • restored legacy V2 unit tests that make sure that the V2 legacy wrapper behaves like the V1 component

Tip

The "legacy" flag introduced in this PR can be further explored to trigger more differences in behaviour and styles as we further define specs of the V2 (non-legacy) version.

Testing Instructions

  • Make sure that the un-skipped unit test for the V2 legacy wrapper passes
  • In Storybook:
    1. Load the default Storybook example for the V2 legacy wrapper
    2. Open the select dropdown and press the "S" key — the "Small" element should be highlighted, but the Storybook sidebar should not toggle its opened/closed state
    3. The same should be true when testing the V1 version of the component
    4. Do the same on the trunk version of Storybook for the V2 legacy wrapper, and notice how the sidebar toggles between opened and closed

@ciampo ciampo force-pushed the fix/custom-select-control-v2-popover-keyboard-propagation branch from 922ef7f to e2c7d63 Compare June 27, 2024 07:48
@ciampo ciampo self-assigned this Jun 27, 2024
@ciampo ciampo marked this pull request as ready for review June 27, 2024 07:57
@ciampo ciampo requested a review from ajitbohra as a code owner June 27, 2024 07:57
@ciampo ciampo added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components labels Jun 27, 2024
Copy link

github-actions bot commented Jun 27, 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: ciampo <mciampini@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>

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

@ciampo ciampo requested a review from a team June 27, 2024 07:57
@ciampo ciampo force-pushed the fix/custom-select-control-v2-popover-keyboard-propagation branch from e2c7d63 to 6ecbde2 Compare June 27, 2024 09:51
@@ -70,9 +79,7 @@ export type _CustomSelectProps = CustomSelectButtonProps & {
label: string;
};

export type CustomSelectProps = _CustomSelectProps &
CustomSelectButtonProps &
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed CustomSelectButtonProps since it's already part of _CustomSelectProps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mirka — just making sure that you see this change, since you refactored these types last

Copy link
Member

Choose a reason for hiding this comment

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

Good catch, thanks 🙏

Comment on lines +53 to +58
export type _CustomSelectInternalProps = {
/**
* True if the consumer is emulating the legacy component behavior and look
*/
isLegacy?: boolean;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I needed a way to allow the internal implementation to expose a isLegacy flag, without forwarding it to the public API of the V2 component. Not sure if we think there's a better way to do that? @mirka

Copy link
Member

Choose a reason for hiding this comment

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

Can't think of a better way, TBH.

What a bummer that we have to do it with hacks like this. It's an indication that the legacy adapter approach has probably too many downsides and won't be a recommended one in the future.

Copy link
Contributor Author

@ciampo ciampo Jul 1, 2024

Choose a reason for hiding this comment

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

The legacy adapted approach definitely has its pros and cons.

It may not be worth keeping a common underlying implementation for V1 and V2 if we then have to abstract it and complicate it with extra props and exceptions. Let's keep it as-is for now and look back at it once V2 legacy wrapper has shipped and we look at V2

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.

Looks good and tests well 👍

Maybe it's just another sign that the adapter approach wasn't the best idea. Something to learn from for future refactors.

Comment on lines +53 to +58
export type _CustomSelectInternalProps = {
/**
* True if the consumer is emulating the legacy component behavior and look
*/
isLegacy?: boolean;
};
Copy link
Member

Choose a reason for hiding this comment

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

Can't think of a better way, TBH.

What a bummer that we have to do it with hacks like this. It's an indication that the legacy adapter approach has probably too many downsides and won't be a recommended one in the future.

@ciampo ciampo merged commit 0097372 into trunk Jul 1, 2024
66 checks passed
@ciampo ciampo deleted the fix/custom-select-control-v2-popover-keyboard-propagation branch July 1, 2024 16:24
@github-actions github-actions bot added this to the Gutenberg 18.8 milestone Jul 1, 2024
carstingaxion pushed a commit to carstingaxion/gutenberg that referenced this pull request Jul 18, 2024
…ess#62907)

* Add `isLegacy` prop to internal implementation

* Stop keyboard event propagation for legacy V2

* Enable skipped test for V2 legacy

* Add comment

* CHANGELOG

* Fix types

---

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[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.

3 participants