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

Components: introduce Combobox expandOnFocus property #61705

Merged
merged 8 commits into from
May 17, 2024

Conversation

retrofox
Copy link
Contributor

What?

This property introduces the expandOnFocus property to the Combobox control component.

Why?

Sometimes, auto-expanding the combo box dropdown is not a desired behavior and could even be considered intrusive.
For instance, AriaKit combobox never auto-expands the dropdown in the focus event.

Screen.Recording.2024-05-16.at.09.25.26.mov

The dropdown opens only when the user types in the input field or clicks on it.

Note: it doesn't change the current behavior to ensure backward compatibilities, which we would consider it.

How?

  • It adds the onClick property to the <TokenInput /> component, since it's mandatory to differetiate the onFocus and the onClick event in the <ComboboxControl /> component context
  • When focusing the element, it sets isExpanded as true only when the expandOnFocus property is true as well.

Testing Instructions

  1. Run storybook
  2. Compare the ComboboxControl stories
  3. Confirm that Not Expand On Focus does not auto-expand the dropdown when the user focuses on the input element. It's required to type or click on it to open the dropdown:
Screen.Recording.2024-05-16.at.09.21.47.mov

Testing Instructions for Keyboard

Screenshots or screencast

@retrofox retrofox requested a review from mirka May 16, 2024 08:33
@retrofox retrofox self-assigned this May 16, 2024
@retrofox retrofox requested a review from ajitbohra as a code owner May 16, 2024 08:33
@retrofox retrofox added the [Package] Components /packages/components label May 16, 2024
Copy link

github-actions bot commented May 16, 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: retrofox <retrofox@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>

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

@retrofox retrofox requested review from mikejolley and tyxla May 16, 2024 08:34
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.

Interesting! The APG doesn't suggest a standard expansion logic, and the possible conditions it suggests include some quite particular custom logic. So my understanding is that, ideally, a consumer should be able to control the expansion behavior with much more precision, rather than just blunt conditions like "is focused" or "was clicked". This should be easy to support once we rewrite a v2 with Ariakit.

That said, the enhancement in this PR is small enough, so I don't see why not 👍

packages/components/src/form-token-field/token-input.tsx Outdated Show resolved Hide resolved
packages/components/CHANGELOG.md Outdated Show resolved Hide resolved
packages/components/src/combobox-control/types.ts Outdated Show resolved Hide resolved
@retrofox retrofox force-pushed the update/combobox-introduce-expand-on-focus branch from 4ff4ca4 to 23fd776 Compare May 17, 2024 07:44
@retrofox retrofox merged commit 1dccb4d into trunk May 17, 2024
62 checks passed
@retrofox retrofox deleted the update/combobox-introduce-expand-on-focus branch May 17, 2024 08:43
@github-actions github-actions bot added this to the Gutenberg 18.5 milestone May 17, 2024
bph pushed a commit to bph/gutenberg that referenced this pull request May 27, 2024
)

Co-authored-by: retrofox <retrofox@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
@bph bph added the [Type] Enhancement A suggestion for improvement. label Jun 3, 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] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants