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

Select input component #1736

Merged
merged 32 commits into from
Jan 11, 2022
Merged

Select input component #1736

merged 32 commits into from
Jan 11, 2022

Conversation

mperrotti
Copy link
Contributor

@mperrotti mperrotti commented Dec 14, 2021

Adds a styled native <select> input component

Closes https://github.com/github/primer/issues/540

Screenshots

Kapture.2021-12-14.at.15.24.42.mp4

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

@mperrotti mperrotti requested review from a team and siddharthkp December 14, 2021 20:27
@changeset-bot
Copy link

changeset-bot bot commented Dec 14, 2021

🦋 Changeset detected

Latest commit: fa45ce6

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

This PR includes changesets to release 1 package
Name Type
@primer/react Minor

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

@mperrotti mperrotti marked this pull request as draft December 14, 2021 20:27
@github-actions
Copy link
Contributor

github-actions bot commented Dec 14, 2021

size-limit report 📦

Path Size
dist/browser.esm.js 60.42 KB (+0.8% 🔺)
dist/browser.umd.js 60.77 KB (+0.77% 🔺)

@@ -0,0 +1,100 @@
---
title: Select
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm thinking maybe "SelectInput" is a better name. I'd love to hear what other reviewers think.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep! I think so too. It kinda cements it as a Form component and not any fancy menu/overlay interface

Copy link
Contributor

Choose a reason for hiding this comment

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

We only recently decided to avoid using *Input suffix on form components, so I'm in favour of keeping it as Select here. Reason: a) To match the underlying HTML and b) be consistent with other form components like Radio, Checkbox.

@pksjce
Copy link
Collaborator

pksjce commented Dec 15, 2021

There seems to be a clash here 😅

#1731

I'll close mine, as I'm yet to implement optgroups and review yours.

@pksjce pksjce mentioned this pull request Dec 15, 2021
10 tasks
src/Select.tsx Outdated

export default Object.assign(Select, {
Option,
Group
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we name this OptGroup?

Copy link
Contributor

Choose a reason for hiding this comment

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

➕ . Can we call it OptionGroup to avoid the abbreviation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think if we're going to call the parent component Select, OptGroup might make more sense because it's closer to the HTML tag name: <optgroup>

src/Select.tsx Outdated
{...rest}
>
{placeholder ? (
<option value="" disabled={required} selected hidden={required}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need a storybook to show what this looks like?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can see it by using the Controls. Do you think we need something more prominent?

type: 'boolean'
}
},
contrast: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This shouldn't be relevant for this component

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I can remove it and we can always add it later if we decide we want parity with TextInput

}
},
variant: {
name: 'Variant',
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we call this size?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, absolutely. I was waiting for #1661 to merge which deprecates variant and adds size.

@pksjce
Copy link
Collaborator

pksjce commented Dec 15, 2021

Some comments

  1. Should it show required * symbol?
  2. All the dark mode colors seem broken?

Dark mode
image

Dark high contrast
image

Dark color blind
image

storybook: '/react/storybook?path=/story/forms-select--default'
---

import {ComponentChecklist} from '../src/component-checklist'
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't think we need to import this anymore as it's global

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I thought too, but if I don't import it, it doesn't render.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could your /docs node_modules need updating?

src/Select.tsx Outdated

const StyledSelect = styled(TextInputWrapper)<SelectProps>`
appearance: none;
background-image: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0iIzU4NjA2OSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNNC40MjcgOS40MjdsMy4zOTYgMy4zOTZhLjI1MS4yNTEgMCAwMC4zNTQgMGwzLjM5Ni0zLjM5NkEuMjUuMjUgMCAwMDExLjM5NiA5SDQuNjA0YS4yNS4yNSAwIDAwLS4xNzcuNDI3ek00LjQyMyA2LjQ3TDcuODIgMy4wNzJhLjI1LjI1IDAgMDEuMzU0IDBMMTEuNTcgNi40N2EuMjUuMjUgMCAwMS0uMTc3LjQyN0g0LjZhLjI1LjI1IDAgMDEtLjE3Ny0uNDI3eiIgLz48L3N2Zz4=);
Copy link
Contributor

@rezrah rezrah Dec 15, 2021

Choose a reason for hiding this comment

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

Is there a way we can show the icon without using a base64 uri? It's quite expensive on the runtime and AFAIK a new pattern to PRC that could set a slippery precedent. Also, this image in its current form seems incompatible with other colour modes. Worth looking at pulling this in as a composable icon instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those are both great points. I'll investigate alternatives.

background-size: 16px;
padding-right: 20px;
cursor: pointer;

Copy link
Contributor

Choose a reason for hiding this comment

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

worth setting the background-color here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That should be handled in the TextInputWrapper component.

src/Select.tsx Outdated Show resolved Hide resolved
@mperrotti
Copy link
Contributor Author

Should it show required * symbol?

That will be handled by the InputFieldComponent added in #1611

All the dark mode colors seem broken?

That's no good. I'll take a look.

Copy link
Contributor

@rezrah rezrah 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 to go, nice one @mperrotti. Just a heads up, this won't appear on the primer.style/status page until you add comonentId to the front-matter. Might be worth sticking that into this PR or in a follow-up.

@mperrotti mperrotti temporarily deployed to visual-testing January 11, 2022 15:21 Inactive
@mperrotti mperrotti merged commit 82961d4 into main Jan 11, 2022
@mperrotti mperrotti deleted the mp/select-input branch January 11, 2022 15:46
@primer-css primer-css mentioned this pull request Jan 11, 2022
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.

None yet

3 participants