Skip to content

Commit 9ab233c

Browse files
authored
Merge branch 'main' into sid/avatar-add-common-props
2 parents a04460d + f4e1de6 commit 9ab233c

File tree

4 files changed

+45
-30
lines changed

4 files changed

+45
-30
lines changed

.changeset/cuddly-rice-march.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/components': major
3+
---
4+
5+
Removed system props support from `<TextInput>` and fixed its type definition.

docs/content/TextInput.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,11 @@ TextInput is a form component to add default styling to the native text input.
1111
```jsx live
1212
<TextInput aria-label="Zipcode" name="zipcode" placeholder="Zipcode" autoComplete="postal-code" />
1313

14-
<TextInput sx={{ml: 4}} aria-label="City" name="city" placeholder="City" contrast />
14+
<TextInput sx={{ml: 4}} aria-label="City" name="city" placeholder="City" contrast />
1515

1616
<TextInput sx={{ml: 4}} icon={SearchIcon} aria-label="Zipcode" name="zipcode" placeholder="Find user" autoComplete="postal-code" />
1717
```
1818

19-
## System props
20-
21-
<Note variant="warning">
22-
23-
System props are deprecated in all components except [Box](/Box). Please use the [`sx` prop](/overriding-styles) instead.
24-
25-
</Note>
26-
27-
TextInput components get `COMMON` system props. Read our [System Props](/system-props) doc page for a full list of available props.
28-
2919
## Component props
3020

3121
Native `<input>` attributes are forwarded to the underlying React `input` component and are not listed below.

src/TextInput.tsx

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import {omit, pick} from '@styled-system/props'
21
import classnames from 'classnames'
32
import React from 'react'
43
import styled, {css} from 'styled-components'
54
import {maxWidth, MaxWidthProps, minWidth, MinWidthProps, variant, width, WidthProps} from 'styled-system'
6-
import {COMMON, get, SystemCommonProps} from './constants'
5+
import {get} from './constants'
76
import sx, {SxProp} from './sx'
87
import {ComponentProps} from './utils/types'
98

@@ -43,8 +42,7 @@ type StyledWrapperProps = {
4342
block?: boolean
4443
contrast?: boolean
4544
variant?: 'small' | 'large'
46-
} & SystemCommonProps &
47-
WidthProps &
45+
} & WidthProps &
4846
MinWidthProps &
4947
MaxWidthProps &
5048
SxProp
@@ -113,38 +111,60 @@ const Wrapper = styled.span<StyledWrapperProps>`
113111
@media (min-width: ${get('breakpoints.1')}) {
114112
font-size: ${get('fontSizes.1')};
115113
}
116-
${COMMON}
117114
${width}
118115
${minWidth}
119116
${maxWidth}
120117
${sizeVariants}
121118
${sx};
122119
`
123120

124-
type TextInputInternalProps = {
125-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
126-
as?: any // This is a band-aid fix until we have better type support for the `as` prop
121+
// Props that are not passed through to Input:
122+
type NonPassthroughProps = {
123+
className?: string
127124
icon?: React.ComponentType<{className?: string}>
128-
} & ComponentProps<typeof Wrapper> &
129-
ComponentProps<typeof Input>
125+
} & Pick<
126+
ComponentProps<typeof Wrapper>,
127+
'block' | 'contrast' | 'disabled' | 'sx' | 'theme' | 'width' | 'maxWidth' | 'minWidth' | 'variant'
128+
>
129+
130+
type TextInputInternalProps = NonPassthroughProps &
131+
// Note: using ComponentProps instead of ComponentPropsWithoutRef here would cause a type issue where `css` is a required prop.
132+
Omit<React.ComponentPropsWithoutRef<typeof Input>, keyof NonPassthroughProps>
130133

131134
// using forwardRef is important so that other components (ex. SelectMenu) can autofocus the input
132135
const TextInput = React.forwardRef<HTMLInputElement, TextInputInternalProps>(
133-
({icon: IconComponent, contrast, className, block, disabled, theme, sx: sxProp, ...rest}, ref) => {
136+
(
137+
{
138+
icon: IconComponent,
139+
block,
140+
className,
141+
contrast,
142+
disabled,
143+
sx: sxProp,
144+
theme,
145+
width: widthProp,
146+
minWidth: minWidthProp,
147+
maxWidth: maxWidthProp,
148+
variant: variantProp,
149+
...inputProps
150+
},
151+
ref
152+
) => {
134153
// this class is necessary to style FilterSearch, plz no touchy!
135154
const wrapperClasses = classnames(className, 'TextInput-wrapper')
136-
const wrapperProps = pick(rest)
137-
const inputProps = omit(rest)
138155
return (
139156
<Wrapper
140-
className={wrapperClasses}
141-
hasIcon={!!IconComponent}
142157
block={block}
143-
theme={theme}
144-
disabled={disabled}
158+
className={wrapperClasses}
145159
contrast={contrast}
160+
disabled={disabled}
161+
hasIcon={!!IconComponent}
146162
sx={sxProp}
147-
{...wrapperProps}
163+
theme={theme}
164+
width={widthProp}
165+
minWidth={minWidthProp}
166+
maxWidth={maxWidthProp}
167+
variant={variantProp}
148168
>
149169
{IconComponent && <IconComponent className="TextInput-icon" />}
150170
<Input ref={ref} disabled={disabled} {...inputProps} />

src/stories/DropdownMenu.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function FavoriteColorStory(): JSX.Element {
3636
return (
3737
<>
3838
<h1>Favorite Color</h1>
39-
<TextInput placeholder="Input for focus testing" mb={2} />
39+
<TextInput placeholder="Input for focus testing" sx={{mb: 2}} />
4040
<div id="favorite-color-label">Please select your favorite color:</div>
4141
<DropdownMenu
4242
renderAnchor={({children, 'aria-labelledby': ariaLabelledBy, ...anchorProps}) => (

0 commit comments

Comments
 (0)