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

DropdownMenuV2: fix active and focus-visible item glitches #64942

Merged
merged 3 commits into from
Sep 2, 2024

Conversation

ciampo
Copy link
Contributor

@ciampo ciampo commented Aug 30, 2024

What?

Alternative fix to #64873

Alternative solution to remove "flash of unwanted styles" when navigating DropdownMenuV2 items using the keyboard.

Why?

Because flashing styles don't provide a great UX.

How?

Implement workaround suggested in ariakit/ariakit#4083 (comment)

Testing Instructions

Same as in #64873

@ciampo ciampo self-assigned this Aug 30, 2024
@ciampo ciampo requested a review from a team August 30, 2024 17:12
@ciampo ciampo added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components labels Aug 30, 2024
@ciampo ciampo marked this pull request as ready for review August 30, 2024 17:12
@ciampo ciampo requested a review from ajitbohra as a code owner August 30, 2024 17:12
Copy link

github-actions bot commented Aug 30, 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>
Co-authored-by: diegohaz <hazdiego@git.wordpress.org>

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

@ciampo
Copy link
Contributor Author

ciampo commented Aug 30, 2024

This is just a different approach. IMO:

  • Pros
    • Our styles continue to rely on the data-focus-visible selector and any logic that it represents
    • The workaround was proposed by the library author (@diegohaz )
  • Cons
    • The current fix is CSS based (potentially more performant) and only a couple of lines of code

@diegohaz
Copy link
Member

  • The current fix is CSS based (potentially more performant) and only a couple of lines of code

That's fine since WordPress does that only for composite items receiving actual DOM focus (virtualFocus is false). Otherwise, the native :focus-visible is not applied to composite items managed by aria-activedescendant.

@ciampo
Copy link
Contributor Author

ciampo commented Aug 31, 2024

Just to make sure I understand, you suggest using this workaround instead of using CSS :focus-visible, right?

@diegohaz
Copy link
Member

diegohaz commented Aug 31, 2024

No, I think WordPress can keep the current solution until it needs to work with composite items with virtual focus.

If there are plans to introduce these components soon and they will also have distinct styles for active-item vs. focus-visible, then yes, the workaround in this PR is better.

@ciampo
Copy link
Contributor Author

ciampo commented Aug 31, 2024

Got it!

Since we do have one instance using virtual focus, and we're planning on exposing that prop for consumers of the component, then I guess we should switch to the solution proposed in this PR

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.

Fix makes sense and tests well 👍

I assume your plan is to remove once the fix lands (it's already been approved) and released and we update to that release?

@ciampo ciampo force-pushed the fix/dropdown-menu-v2/active-focus-glitches branch from 2b116ee to 0807805 Compare September 2, 2024 11:46
@ciampo ciampo enabled auto-merge (squash) September 2, 2024 11:47
@ciampo ciampo merged commit 52832f5 into trunk Sep 2, 2024
61 checks passed
@ciampo ciampo deleted the fix/dropdown-menu-v2/active-focus-glitches branch September 2, 2024 12:20
@github-actions github-actions bot added this to the Gutenberg 19.2 milestone Sep 2, 2024
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