-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
CustomSelectControl V2: prevent keyboard event propagation in legacy wrapper #62907
Conversation
922ef7f
to
e2c7d63
Compare
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
e2c7d63
to
6ecbde2
Compare
@@ -70,9 +79,7 @@ export type _CustomSelectProps = CustomSelectButtonProps & { | |||
label: string; | |||
}; | |||
|
|||
export type CustomSelectProps = _CustomSelectProps & | |||
CustomSelectButtonProps & |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks 🙏
export type _CustomSelectInternalProps = { | ||
/** | ||
* True if the consumer is emulating the legacy component behavior and look | ||
*/ | ||
isLegacy?: boolean; | ||
}; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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.
export type _CustomSelectInternalProps = { | ||
/** | ||
* True if the consumer is emulating the legacy component behavior and look | ||
*/ | ||
isLegacy?: boolean; | ||
}; |
There was a problem hiding this comment.
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.
…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>
What?
Part of #55023
Prevent keyboard events propagation from the select popover in
CustomSelectControlV2
legacy wrapperWhy?
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?
keydown
event propagation on the select dropdownTip
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
trunk
version of Storybook for the V2 legacy wrapper, and notice how the sidebar toggles between opened and closed