Skip to content

Select input component #1736

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

Merged
merged 32 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
520a056
adds Select component and stories
mperrotti Dec 14, 2021
917423c
adds tests
mperrotti Dec 14, 2021
ffa2183
styling fix for Firefox
mperrotti Dec 14, 2021
3bcebcb
adds docs
mperrotti Dec 14, 2021
0f77d9d
adds changeset
mperrotti Dec 14, 2021
16b5f6a
appease the linter
mperrotti Dec 14, 2021
bc06aba
Update src/Select.tsx
mperrotti Dec 15, 2021
7379950
Merge branch 'main' into mp/select-input
mperrotti Dec 15, 2021
9b81e50
Merge branch 'main' of github.com:primer/react into mp/select-input
mperrotti Dec 16, 2021
8fe1d20
addresses PR feedback
mperrotti Dec 16, 2021
7329286
Merge branch 'mp/select-input' of github.com:primer/react into mp/sel…
mperrotti Dec 16, 2021
5303d0d
Merge branch 'main' into mp/select-input
mperrotti Dec 16, 2021
95c3be8
Merge branch 'main' into mp/select-input
mperrotti Dec 16, 2021
ccc3d8c
Merge branch 'main' into mp/select-input
mperrotti Dec 17, 2021
fde3e76
addresses more PR feedback
mperrotti Dec 17, 2021
88a65c9
adds props table to select
mperrotti Dec 17, 2021
5ccc2f2
Merge branch 'mp/select-input' of github.com:primer/react into mp/sel…
mperrotti Dec 17, 2021
5cc9867
Merge branch 'main' into mp/select-input
mperrotti Dec 17, 2021
6e4df1a
fix deployment failure
mperrotti Dec 17, 2021
6a04106
Merge branch 'mp/select-input' of github.com:primer/react into mp/sel…
mperrotti Dec 17, 2021
9ff8321
fixes docs build
mperrotti Dec 17, 2021
a90a58d
change ternary to AND operator
mperrotti Dec 17, 2021
c6eb710
adds comopnentId to docs frontmatter
mperrotti Dec 17, 2021
8b659c7
Merge branch 'main' into mp/select-input
mperrotti Dec 17, 2021
96909d7
Merge branch 'main' into mp/select-input
mperrotti Jan 10, 2022
e7c5d91
Merge branch 'main' into mp/select-input
mperrotti Jan 10, 2022
ee76cb3
Merge branch 'main' of github.com:primer/react into mp/select-input
mperrotti Jan 10, 2022
4b84d8d
adds Select as a possible InputField child
mperrotti Jan 10, 2022
003e353
Merge branch 'mp/select-input' of github.com:primer/react into mp/sel…
mperrotti Jan 10, 2022
86ab778
updates package-lock.json
mperrotti Jan 11, 2022
77832b4
Merge branch 'main' of github.com:primer/react into mp/select-input
mperrotti Jan 11, 2022
fa45ce6
docs fixes
mperrotti Jan 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adds props table to select
  • Loading branch information
mperrotti committed Dec 17, 2021
commit 88a65c98338de4b51dc847b6aa6d77fc2071a061
31 changes: 30 additions & 1 deletion docs/content/Select.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,36 @@ import PropsTable from '../src/props-table'

### Select

The `Select` component accepts the same props as a native HTML [`<select>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select) except for `multiple` and `size`.
<PropsTable>
<PropsTableRow
name="block"
type="boolean"
defaultValue="false"
description={<>Creates a full width input element</>}
/>
<PropsTableRow
name="contrast"
type="boolean"
defaultValue="false"
description="Changes background color to a higher contrast color"
/>
<PropsTableRow
name="size"
type="'small' | 'medium' | 'large'"
description="Creates a smaller or larger input than the default."
/>
<PropsTableRow name="validationStatus" type="'warning' | 'error'" description="Style the input to match the status" />
<tr>
<Box as="td" colSpan={4} fontSize={1} verticalAlign="top">
Additional props are passed to the <InlineCode>&lt;select&gt;</InlineCode> element. See{' '}
<Link href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select#attributes">MDN</Link> for a list of
props accepted by the <InlineCode>&lt;select&gt;</InlineCode> element.

<br /> The <InlineCode>multiple</InlineCode> prop is not accepted.
</Box>

</tr>
</PropsTable>

### Select.OptGroup

Expand Down
8 changes: 6 additions & 2 deletions src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import styled from 'styled-components'
import {get} from './constants'
import TextInputWrapper, {StyledWrapperProps} from './_TextInputWrapper'

type SelectProps = Omit<React.HTMLProps<HTMLSelectElement> & StyledWrapperProps, 'multiple' | 'size' | 'hasIcon' | 'as'>
type SelectProps = Omit<
Omit<React.HTMLProps<HTMLSelectElement>, 'size'> & StyledWrapperProps,
'multiple' | 'hasLeadingVisual' | 'hasTrailingVisual' | 'as'
>

const StyledSelect = styled.select`
appearance: none;
Expand Down Expand Up @@ -38,11 +41,12 @@ const ArrowIndicator = styled(ArrowIndicatorSVG)`
`

const Select = React.forwardRef<HTMLSelectElement, SelectProps>(
({children, disabled, placeholder, required, ref: _propsRef, ...rest}: SelectProps, ref) => (
({children, disabled, placeholder, size, required, ref: _propsRef, ...rest}: SelectProps, ref) => (
<TextInputWrapper
sx={{
position: 'relative'
}}
size={size}
>
<StyledSelect
ref={ref}
Expand Down