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

WB-1779: Add startIcon prop to Combobox #2364

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

WB-1779: Add startIcon prop to Combobox #2364

wants to merge 6 commits into from

Conversation

jandrade
Copy link
Member

@jandrade jandrade commented Nov 18, 2024

Summary:

Adds a new startIcon prop (optional) to the Combobox component. This prop
will allow to optinally add an icon to the left of the input field.

This use case will be helpful for the AI tools case where we want to use a
search icon.

Issue: https://khanacademy.atlassian.net/browse/WB-1779

Test plan:

Verify that the Start icon docs make sense and that the example works as
expected.

/?path=/docs/packages-dropdown-combobox--docs#start%20icon

Screenshot 2024-11-18 at 3 21 00 PM

@jandrade jandrade self-assigned this Nov 18, 2024
Copy link

changeset-bot bot commented Nov 18, 2024

🦋 Changeset detected

Latest commit: 76790a9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@khanacademy/wonder-blocks-dropdown Minor
@khanacademy/wonder-blocks-birthday-picker Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@khan-actions-bot khan-actions-bot requested a review from a team November 18, 2024 20:21
@khan-actions-bot
Copy link
Contributor

Gerald

Required Reviewers
  • @Khan/wonder-blocks for changes to .changeset/old-pears-fix.md, __docs__/wonder-blocks-dropdown/combobox.stories.tsx, packages/wonder-blocks-dropdown/src/components/combobox.tsx, packages/wonder-blocks-dropdown/src/components/__tests__/combobox.test.tsx

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

Copy link
Contributor

github-actions bot commented Nov 18, 2024

npm Snapshot: Published

🎉 Good news!! We've packaged up the latest commit from this PR (b047234) and published all packages with changesets to npm.

You can install the packages in webapp by running:

./services/static/dev/tools/deploy_wonder_blocks.js --tag="PR2364"

Packages can also be installed manually by running:

yarn add @khanacademy/wonder-blocks-<package-name>@PR2364

Copy link
Contributor

github-actions bot commented Nov 18, 2024

Size Change: +153 B (+0.15%)

Total Size: 101 kB

Filename Size Change
packages/wonder-blocks-dropdown/dist/es/index.js 18.4 kB +153 B (+0.84%)
ℹ️ View Unchanged
Filename Size
packages/wonder-blocks-accordion/dist/es/index.js 3.78 kB
packages/wonder-blocks-banner/dist/es/index.js 1.53 kB
packages/wonder-blocks-birthday-picker/dist/es/index.js 1.77 kB
packages/wonder-blocks-breadcrumbs/dist/es/index.js 887 B
packages/wonder-blocks-button/dist/es/index.js 4.04 kB
packages/wonder-blocks-cell/dist/es/index.js 2.01 kB
packages/wonder-blocks-clickable/dist/es/index.js 3.06 kB
packages/wonder-blocks-core/dist/es/index.js 3.44 kB
packages/wonder-blocks-data/dist/es/index.js 6.24 kB
packages/wonder-blocks-form/dist/es/index.js 6.28 kB
packages/wonder-blocks-grid/dist/es/index.js 1.36 kB
packages/wonder-blocks-i18n/dist/es/index.js 4.76 kB
packages/wonder-blocks-icon-button/dist/es/index.js 3 kB
packages/wonder-blocks-icon/dist/es/index.js 871 B
packages/wonder-blocks-labeled-field/dist/es/index.js 72 B
packages/wonder-blocks-layout/dist/es/index.js 1.82 kB
packages/wonder-blocks-link/dist/es/index.js 2.28 kB
packages/wonder-blocks-modal/dist/es/index.js 5.36 kB
packages/wonder-blocks-pill/dist/es/index.js 1.65 kB
packages/wonder-blocks-popover/dist/es/index.js 4.87 kB
packages/wonder-blocks-progress-spinner/dist/es/index.js 1.52 kB
packages/wonder-blocks-search-field/dist/es/index.js 1.3 kB
packages/wonder-blocks-switch/dist/es/index.js 1.94 kB
packages/wonder-blocks-testing-core/dist/es/index.js 3.74 kB
packages/wonder-blocks-testing/dist/es/index.js 1.07 kB
packages/wonder-blocks-theming/dist/es/index.js 693 B
packages/wonder-blocks-timing/dist/es/index.js 1.8 kB
packages/wonder-blocks-tokens/dist/es/index.js 2.36 kB
packages/wonder-blocks-toolbar/dist/es/index.js 905 B
packages/wonder-blocks-tooltip/dist/es/index.js 7.08 kB
packages/wonder-blocks-typography/dist/es/index.js 1.23 kB

compressed-size-action

Copy link
Contributor

github-actions bot commented Nov 18, 2024

A new build was pushed to Chromatic! 🚀

https://5e1bf4b385e3fb0020b7073c-eejlmdwnxz.chromatic.com/

Chromatic results:

Metric Total
Captured snapshots 91
Tests with visual changes 0
Total stories 504
Inherited (not captured) snapshots [TurboSnap] 279
Tests on the build 370

Copy link
Member

@beaesguerra beaesguerra left a comment

Choose a reason for hiding this comment

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

Changes look good, I noticed the prop docs needed to be updated though!

I also have some questions/things we can consider (doesn't have to be part of this PR!):

  1. I was also working on a similar magnifying icon in the SearchField component in PR SearchField: Add validation props and refine states #2363! I noticed the styling in the code component looked a bit different from the Figma component so I updated the styles while I was there 😄 . Since both Combobox and SearchField use TextField, it would be great if we could consolidate how the start icon gets rendered! There were several considerations for styling the icon like the disabled and light props. One idea on how we could consolidate the styling would be to add a startIcon prop to TextField and it could provide the color, sizing, spacing. This could be useful for TextField on its own too! What do you think?

    • I was also wondering if a endIcon prop would also be useful for things like the Chevron icon, though it is an icon button so maybe the prop should support icon buttons too. Another use case would be the clear icon button in SearchField, or a show/hide icon button on a password field! The Combobox can potentially have 2 end icon buttons though for the clear and expand buttons, so perhaps it would take a React.Node instead of limiting it to Icon/IconButton!
  2. For the combobox, would it be helpful for users to always have the magnifying glass icon there by default so there is a hint that they can type to search? Then teams can customize the icon for specific use cases if needed!

@@ -132,6 +133,14 @@ type Props = {
*/
// TODO(WB-1740): Add support to `inline` and `both` values.
autoComplete?: "none" | "list" | undefined;

/**
* The icon (wrapped by a button) that allows opening the listbox widget
Copy link
Member

Choose a reason for hiding this comment

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

I think the prop docs need to be updated for startIcon!

Copy link
Member Author

Choose a reason for hiding this comment

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

oh oops, changing it! (I copy pasted from the impl. spec so I'm going to update it there as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed! btw I also modified the new story to include both the default and disabled state.

I'm thinking about creating an All Variants story to capture all the Combobox styles, but I'd do it in a separate PR. wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

That sounds good to me!

@jandrade
Copy link
Member Author

I also have some questions/things we can consider (doesn't have to be part of this PR!):

  1. I was also working on a similar magnifying icon in the SearchField component in PR SearchField: Add validation props and refine states #2363! I noticed the styling in the code component looked a bit different from the Figma component so I updated the styles while I was there 😄 . Since both Combobox and SearchField use TextField, it would be great if we could consolidate how the start icon gets rendered! There were several considerations for styling the icon like the disabled and light props. One idea on how we could consolidate the styling would be to add a startIcon prop to TextField and it could provide the color, sizing, spacing. This could be useful for TextField on its own too! What do you think?

    • I was also wondering if a endIcon prop would also be useful for things like the Chevron icon, though it is an icon button so maybe the prop should support icon buttons too. Another use case would be the clear icon button in SearchField, or a show/hide icon button on a password field! The Combobox can potentially have 2 end icon buttons though for the clear and expand buttons, so perhaps it would take a React.Node instead of limiting it to Icon/IconButton!
  2. For the combobox, would it be helpful for users to always have the magnifying glass icon there by default so there is a hint that they can type to search? Then teams can customize the icon for specific use cases if needed!

@beaesguerra Good points, here are my thoughts:

  1. a. The disabled case makes a lot of sense. As for light, I think I are going to use it less, specially with the new experience coming later. One thing that I have been noticing in WB is that historically we have tend to allow passing PhosphorIcon instances as it provides more flexibility to implement different styles, and that's part of why I used that approach here. That means that the user can provide more control over color, sizing, spacing and even styling. I like the idea of centralizing that in TextField, but the only thing that gets me thinking is current usage, as I'm not sure if our form fields are using icons currently (specially text fields). This would be a great subject to bring to our WB cubby meeting to see what designers think. As for the API, how do you envision startIcon would work?

1.b. The original goal was to include endIcon with Combobox as well, but I decided to drop it to try to be consistent with the chevron icon button and prevent introducing any possible a11y issues by giving too much flexibility to that icon button. I think that in the end icon case, we should enforce our comboboxes to always look the same way (similar to what we do with other dropdowns like SingleSelect and MultiSelect).

  1. I'd suggest to not use that icon by default as I think it could be confusing when the combobox it is in its selected state (for both single and multiple selection), and instead allowing to include it for very specific cases. For context on this API, I added this magnifying icon as a specific request for one of the TX flows: https://www.khanacademy.org/teacher/khanmigo-tools/lesson-plan?platform=KhanAcademy.

@khan-actions-bot khan-actions-bot requested a review from a team November 19, 2024 20:03
@beaesguerra
Copy link
Member

1a. As for light, I think I are going to use it less, specially with the new experience coming later.

👍 That simplifies things, great!

1a. As for the API, how do you envision startIcon would work?

startIcon in TextField would work similar to startIcon in Combobox in this PR! TextField would inject the color/size props into the PhosphorIcon. If we wanted it to be more flexible (ie. any svg can be passed in), we could inject styles to it, though I'm not sure how we could pass in aphrodite styles if the provided element isn't compatible with aphrodite 🤔 I like the approach of it expecting a PhosphorIcon!

1.b. Oops I should've clarified! I was thinking about an endIcon prop for TextField since both SearchField and Combobox included things at the end of the field! We can see though if there's a need for this in TextField since this is lower priority :) I agree that Combobox doesn't need to have this flexibility since it should always have the expansion/clear buttons!

I'd suggest to not use that icon by default as I think it could be confusing when the combobox it is in its selected state (for both single and multiple selection), and instead allowing to include it for very specific cases. For context on this API, I added this magnifying icon as a specific request for one of the TX flows: https://www.khanacademy.org/teacher/khanmigo-tools/lesson-plan?platform=KhanAcademy.

Got it, thanks for the context! Something else I'm thinking about is if there are things we can do to make sure icon usage is consistent! For example, when I updated SearchField, I updated it to use the bold icon to have it match Figma more closely (previously it was regular, similar to what's in Combobox in this PR! Let me know if I should change it back). This is also probably a bigger question related to how we use the design system in Figma too! Let me know if anyone has thoughts on this :) we can also solve for this later in the upcoming work!

Copy link
Member

@beaesguerra beaesguerra 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, left some minor comments! Thanks for the discussion RE: icons in TextField! As discussed in the cubby meeting, we can solve for that later and see if we need it :)

}

const startIconElement = React.cloneElement(startIcon, {
...startIcon.props,
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: (no changes necessary) What do you think about providing a default size and color if the color and size props aren't defined on the startIcon? That way, teams could pass in the PhosphorIcon without having to worry about what color and size to provide, and they can if they need to override it!

Copy link
Member Author

Choose a reason for hiding this comment

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

Love it!

/**
* Start icon styles
*/
iconDisabled: {
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think this isn't used!

},
args: {
children: items,
startIcon: (
Copy link
Member

Choose a reason for hiding this comment

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

Let's consolidate on the magnifying icon styling! In SearchField, I updated the following to match the design more closely:

  • size=small
  • color=semanticColor.icon.primary
  • use the bold icon instead @phosphor-icons/core/bold/magnifying-glass-bold.svg

Let me know though if we prefer to stick with the existing styles, I can update SearchField to change it back to how it was! (I was assuming Figma was the source of truth for styling, but that may not be the case!)

Copy link
Member Author

@jandrade jandrade Nov 20, 2024

Choose a reason for hiding this comment

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

Sounds great! I hope GH includes the 💯 emoji in their msg reactions at some point.

To clarify after our last convo, size would be small right? (medium was for the dismiss icon).

Copy link
Member

Choose a reason for hiding this comment

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

The magnifying glass PhosphorIcon size will be small!

The clear/dismiss IconButton size is also small and the x icon is the regular icon weight!

They're both "small", but the PhosphorIcon renders a 16x16 icon and IconButton renders a 24x24 icon!

Copy link
Member

@marcysutton marcysutton left a comment

Choose a reason for hiding this comment

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

This is looking great, @jandrade! Nice work!

Copy link
Member

@beaesguerra beaesguerra left a comment

Choose a reason for hiding this comment

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

Looks great! 🚀

<Combobox
{...args}
startIcon={
<PhosphorIcon icon={magnifyingGlassIcon} size="small" />
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: We can remove size="small" here so we can confirm that the default size is being applied!

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! I'll fix it before landing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants