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

Apply sx prop to Select's parent for custom styles #3888

Merged
merged 4 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .changeset/five-crews-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@primer/react': patch
---

Select: Add support for `sx` prop

<!-- Changed components: Select -->
29 changes: 19 additions & 10 deletions src/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import styled from 'styled-components'
import TextInputWrapper, {StyledWrapperProps} from './internal/components/TextInputWrapper'
import {SxProp, merge, BetterSystemStyleObject} from './sx'

export type SelectProps = Omit<
Omit<React.ComponentPropsWithoutRef<'select'>, 'size'> & Omit<StyledWrapperProps, 'variant'>,
Expand Down Expand Up @@ -71,22 +72,30 @@ const ArrowIndicator = styled(ArrowIndicatorSVG)`
`

const Select = React.forwardRef<HTMLSelectElement, SelectProps>(
({block, children, contrast, disabled, placeholder, size, required, validationStatus, ...rest}: SelectProps, ref) => (
(
{block, children, contrast, disabled, placeholder, size, required, validationStatus, sx = {}, ...rest}: SelectProps,
ref,
) => (
<TextInputWrapper
sx={{
overflow: 'hidden',
position: 'relative',
'@media screen and (forced-colors: active)': {
svg: {
fill: disabled ? 'GrayText' : 'FieldText',
},
},
}}
block={block}
contrast={contrast}
disabled={disabled}
size={size}
validationStatus={validationStatus}
sx={
merge(
{
overflow: 'hidden',
position: 'relative',
'@media screen and (forced-colors: active)': {
svg: {
fill: disabled ? 'GrayText' : 'FieldText',
},
},
},
sx as SxProp,
) as BetterSystemStyleObject
}
>
<StyledSelect
ref={ref}
Expand Down
16 changes: 16 additions & 0 deletions src/Select/Select.features.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,19 @@ export const Large = () => (
</FormControl>
</Box>
)

export const WithCustomStyling = () => (
<Box as="form">
<FormControl>
<FormControl.Label>Default label</FormControl.Label>
<Select sx={{borderRadius: '12px', border: '1px dashed #000000'}}>
<Select.Option value="one">Choice one</Select.Option>
<Select.Option value="two">Choice two</Select.Option>
<Select.Option value="three">Choice three</Select.Option>
<Select.Option value="four">Choice four</Select.Option>
<Select.Option value="five">Choice five</Select.Option>
<Select.Option value="six">Choice six</Select.Option>
</Select>
</FormControl>
</Box>
)
Loading