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

ComboboxControl and FormTokenField: enhance components with custom render callback for options #42597

Merged
merged 19 commits into from
Aug 10, 2022
Merged

ComboboxControl and FormTokenField: enhance components with custom render callback for options #42597

merged 19 commits into from
Aug 10, 2022

Conversation

manzoorwanijk
Copy link
Member

@manzoorwanijk manzoorwanijk commented Jul 21, 2022

What?

This PR

  • Adds an optional render callback to the SuggestionsList and ComboboxControl components in order to allow the consumer to control how an option is rendered inside SuggestionsList for a combobox or any other consumer of SuggestionsList
  • Adds a corresponding story to ComboboxControl to demonstrate the new behavior

Why?

In many use cases of combobox, we need to show more detail to the user for an option in the list apart from just the label. More details help users identify the correct option from the list when there are plenty of them available with similar labels.

How?

  • It first adds an optional (thus full backward compatible) prop renderSuggestion to SuggestionsList component.
  • If renderSuggestion is passed, it will be given preference and the suggestion will be passed to it to allow it to render the suggestion.
  • It also adds renderOption prop to ComboboxControl which in turn gets passed to SuggestionsList above.

Testing Instructions

  • Checkout the branch
  • Run npm run storybook:dev
  • Check combobox story in Storybook
  • Confirm that the existing story behaves as before i.e. it is backward compatible
  • Confirm that With Render Option story shows more details in the options for combobox like Age, Country.

Screenshots or screencast

Screenshot 2022-07-21 at 5 49 24 PM


@manzoorwanijk manzoorwanijk requested a review from ajitbohra as a code owner July 21, 2022 12:20
@ciampo ciampo requested review from mirka, ciampo and chad1008 July 21, 2022 15:35
@ciampo ciampo added [Type] Enhancement A suggestion for improvement. [Feature] UI Components Impacts or related to the UI component system [Package] Components /packages/components labels Jul 21, 2022
Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

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

Hey @manzoorwanijk , thank you for the contribution!

The code changes are clear, and I definitely understand the need for this change.

The only reservation that I currently have is around API design. We're currently in the process of investigating how to best refactor CustomSelectControl using ariakit, and we'll very likely apply the same treatment to ComboboxControl and related. Therefore, I'm going to take some additional time to understand if introducing the renderSuggestion prop is compatible with those potential changes.

Apart from that, here's a few additional notes from this first round of review:

  • Should we add the same prop to the FormTokenField components?
  • We should add documentation about this prop to the ComboboxControl README (and potentially FormTokenField, in case)
  • We should add a CHANGELOG entry

@manzoorwanijk
Copy link
Member Author

  • Should we add the same prop to the FormTokenField components?
  • We should add documentation about this prop to the ComboboxControl README (and potentially FormTokenField, in case)
  • We should add a CHANGELOG entry

@ciampo Thank you for the feedback. I agree with your suggestions. I have made the changes accordingly.

Co-authored-by: Renzo Canepa <rcanepag@gmail.com>
Copy link
Contributor

@rcanepa rcanepa left a comment

Choose a reason for hiding this comment

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

LGTM now.

I don't see any regression anymore, and the new renderOption prop works as expected.

@ciampo
Copy link
Contributor

ciampo commented Jul 27, 2022

I would request that we wait before merging, as explained in an earlier comment.

Since the changes in this PR would be making changes to the public APIs of a few components, we'd like to make sure that these changes are compatible with the future changes that we are planning for these exact components, as introducing breaking changes is something that we try to avoid as much as possible for the @wordpress/components package.

Does the proposed changes have a high priority ? I'm asking because I'm quite busy these days and I need to juggle priorities in my queues.

@manzoorwanijk
Copy link
Member Author

I would request that we wait before merging, as explained in an earlier comment.

I am not sure what it's supposed to look like in the future.

Does the proposed changes have a high priority?

Yes, we have a need for this change in order to use the component inside wp-admin for Jetpack.

@ciampo
Copy link
Contributor

ciampo commented Jul 28, 2022

I am not sure what it's supposed to look like in the future.

That's ok, it's the job of the components squad (mainly @mirka and myself) to understand that.

Yes, we have a need for this change in order to use the component inside wp-admin for Jetpack.

I'll try to prioritize this task, then. Thank you!

Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

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

Sorry for the delay in answering, and thank you for your patience!

TL;DR: let's rename renderProp to __experimentalRenderItem on both components. I believe @mirka also had some further feedback to leave, so let's wait for that too.


More details:

After discussing the matter with @mirka , we analysed the main options that we have in terms of API surface for CustomSelectControl (and, similarly, ComboboxControl and ForkTokenField). While it's still early for us to commit "officially", we decided to explore the last approach highlighted in this comment:

  • it is the most similar to the current approach, and therefore the least disruptive
  • since we don't want to fully commit yet, let's add an __experimental prefix in front (as we continue the work on CustomSelectControl, we will either stabilize these props, or remove them in favor of a different approach)
  • in order to have the highest flexibility, we may want to use two separate props (depending on the component):
    • one for rendering each option in the dropdown (called __experimentalRenderItem)
    • another one for rendering the selected value(s) that are shown also when the component is "closed" (called __experimentalRenderValue)
  • as we stabilize these props, we may need to make some changes / expand what the options prop is capable of (e.g accept option groups, how to pass custom additional data), which may result into potential breaking changes (and therefore I would recommend that you follow the work on these components closely to avoid any disruption)

Question: in the current state of this PR, would you expect to be able to find the items by searching for their country / age as well ? The potential need for matching the search string against all data fields (and not just the value)

@manzoorwanijk
Copy link
Member Author

TL;DR: let's rename renderProp to __experimentalRenderItem on both components. I believe @mirka also had some further feedback to leave, so let's wait for that too.

Thank you for the feedback @ciampo . I have made the changes and used __experimentalRenderItem for all the components involved to make the usage consistent.

in order to have the highest flexibility, we may want to use two separate props (depending on the component):

  • one for rendering each option in the dropdown (called __experimentalRenderItem)
  • another one for rendering the selected value(s) that are shown also when the component is "closed" (called __experimentalRenderValue)

I am not sure if __experimentalRenderValue will work as expected because it will affect the current value of the input being entered by user while searching for the options.

Question: in the current state of this PR, would you expect to be able to find the items by searching for their country / age as well ? The potential need for matching the search string against all data fields (and not just the value)

No, that's not currently possible. Maybe in some future iteration, we can do that.

@manzoorwanijk manzoorwanijk requested a review from ciampo August 3, 2022 07:13
@manzoorwanijk manzoorwanijk requested a review from mirka August 4, 2022 05:28
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.

Thanks for the quick turnaround! The changes are good on my end. Once Marco gives the final 👍 we're good to go.

@ciampo ciampo changed the title Enhance ComboboxControl and SuggestionsList components with custom render callback for options ComboboxControl and FormTokenField: enhance components with custom render callback for options Aug 9, 2022
Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

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

LGTM 🚀 Feel free to merge once the few remaining pieces of feedback are addressed!

I am not sure if __experimentalRenderValue will work as expected because it will affect the current value of the input being entered by user while searching for the options.

I though what we could still use the results of __experimentalRenderValue while the search input is not focused, but that would required completely replacing the input element with a custom component showing the selected value(s).

Let's leave it for now, and re-evaluate once we work on the overhaul of these components. Another thing that I'd like to do is to "normalize" the shape of options (for ComboboxControl) and suggestions (for FormTokenField) to have the same "type", and to make it clean that, whatever that type it, it's going to be the same type that __experimentalRenderItem and __experimentalRenderValue expect

Question: in the current state of this PR, would you expect to be able to find the items by searching for their country / age as well ? The potential need for matching the search string against all data fields (and not just the value)

No, that's not currently possible. Maybe in some future iteration, we can do that.

Apologies in case my question got misunderstood — I was asking mostly to understand your expectations as a user of the component. I'm not expecting that this PR introduces that functionality — we're still at the phase where we're evaluating what data should be "searchable" to the user. It's not trivial since, with the introduction of the render props, the component doesn't really know what data is shown to the user (and therefore what the user may deem "searchable")

@manzoorwanijk
Copy link
Member Author

I was asking mostly to understand your expectations as a user of the component.

Yes, in the future, it would be great to have the values being searchable by anything that is rendered in the suggestions list.

@manzoorwanijk
Copy link
Member Author

Feel free to merge once the few remaining pieces of feedback are addressed!

Thank you for the feedback @ciampo. I have addressed all the feedback. Feel free to merge it when ready. I am not authorized to merge PRs here.

@talldan talldan merged commit 8568104 into WordPress:trunk Aug 10, 2022
@github-actions github-actions bot added this to the Gutenberg 13.9 milestone Aug 10, 2022
@manzoorwanijk manzoorwanijk deleted the add/render-cb-to-suggestions-list branch August 11, 2022 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] UI Components Impacts or related to the UI component system [Package] Components /packages/components [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants