Skip to content

Commit 37ce4aa

Browse files
authored
Revert TextInputWithWrapper changes to remove sx and styled-system (#6846)
1 parent b3310b5 commit 37ce4aa

File tree

15 files changed

+144
-114
lines changed

15 files changed

+144
-114
lines changed

.changeset/silly-parks-give.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': patch
3+
---
4+
5+
Adds `sx` prop back to TextInput

e2e/components/TextInput.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,24 @@ test.describe('TextInput', () => {
219219
}
220220
})
221221

222+
test.describe('Dev: With Sx', () => {
223+
for (const theme of themes) {
224+
test.describe(theme, () => {
225+
test('default @vrt', async ({page}) => {
226+
await visit(page, {
227+
id: 'components-textinput-dev--with-sx',
228+
globals: {
229+
colorScheme: theme,
230+
},
231+
})
232+
233+
// Default state
234+
expect(await page.screenshot()).toMatchSnapshot(`TextInput.Dev.WithSx.${theme}.png`)
235+
})
236+
})
237+
}
238+
})
239+
222240
test.describe('Dev: With CSS', () => {
223241
for (const theme of themes) {
224242
test.describe(theme, () => {
@@ -236,4 +254,22 @@ test.describe('TextInput', () => {
236254
})
237255
}
238256
})
257+
258+
test.describe('Dev: With Sx and CSS', () => {
259+
for (const theme of themes) {
260+
test.describe(theme, () => {
261+
test('default @vrt', async ({page}) => {
262+
await visit(page, {
263+
id: 'components-textinput-dev--with-sx-and-css',
264+
globals: {
265+
colorScheme: theme,
266+
},
267+
})
268+
269+
// Default state
270+
expect(await page.screenshot()).toMatchSnapshot(`TextInput.Dev.WithSxAndCSS.${theme}.png`)
271+
})
272+
})
273+
}
274+
})
239275
})

packages/react/src/SelectPanel/SelectPanel.module.css

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@
5252
color: var(--fgColor-muted);
5353
}
5454

55-
.FilterInputWrapper {
56-
margin: var(--base-size-8);
57-
width: auto;
58-
}
59-
6055
.Notice {
6156
margin-top: var(--base-size-4);
6257
margin-right: var(--base-size-8);
@@ -235,3 +230,7 @@
235230
inset: 0;
236231
background-color: var(--overlay-backdrop-bgColor);
237232
}
233+
234+
.TextInput {
235+
margin: var(--base-size-8);
236+
}

packages/react/src/SelectPanel/SelectPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ function Panel({
648648

649649
const extendedTextInputProps: Partial<TextInputProps> = useMemo(() => {
650650
return {
651-
className: classes.FilterInputWrapper,
651+
className: classes.TextInput,
652652
contrast: true,
653653
leadingVisual: SearchIcon,
654654
'aria-label': inputLabel,

packages/react/src/TextInput/TextInput.dev.stories.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,21 @@ export const WithCSS = () => (
1818
</FormControl>
1919
</form>
2020
)
21+
22+
export const WithSx = () => (
23+
<form>
24+
<FormControl>
25+
<FormControl.Label>Default label</FormControl.Label>
26+
<TextInput sx={{borderColor: 'red'}} />
27+
</FormControl>
28+
</form>
29+
)
30+
31+
export const WithSxAndCSS = () => (
32+
<form>
33+
<FormControl>
34+
<FormControl.Label>Default label</FormControl.Label>
35+
<TextInput sx={{borderColor: 'red'}} className="testCustomClassnameBorderColor" />
36+
</FormControl>
37+
</form>
38+
)

packages/react/src/TextInput/TextInput.docs.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,27 @@
140140
"deprecated": true,
141141
"description": "(Use size) Creates a smaller or larger input than the default."
142142
},
143+
{
144+
"name": "width",
145+
"type": "string | number | Array<string | number>",
146+
"defaultValue": "",
147+
"deprecated": true,
148+
"description": "(Use sx prop) Set the width of the input"
149+
},
150+
{
151+
"name": "maxWidth",
152+
"type": "string | number | Array<string | number>",
153+
"defaultValue": "",
154+
"deprecated": true,
155+
"description": "(Use sx prop) Set the maximum width of the input"
156+
},
157+
{
158+
"name": "minWidth",
159+
"type": "string | number | Array<string | number>",
160+
"defaultValue": "",
161+
"deprecated": true,
162+
"description": "(Use sx prop) Set the minimum width of the input"
163+
},
143164
{
144165
"name": "icon",
145166
"type": "React.ComponentType",

packages/react/src/TextInput/TextInput.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,20 @@ export type TextInputNonPassthroughProps = {
4040
*/
4141
trailingAction?: React.ReactElement<React.HTMLProps<HTMLButtonElement>>
4242
} & Partial<
43-
Pick<StyledWrapperProps, 'block' | 'contrast' | 'disabled' | 'monospace' | 'variant' | 'size' | 'validationStatus'>
43+
Pick<
44+
StyledWrapperProps,
45+
| 'block'
46+
| 'contrast'
47+
| 'disabled'
48+
| 'monospace'
49+
| 'sx'
50+
| 'width'
51+
| 'maxWidth'
52+
| 'minWidth'
53+
| 'variant'
54+
| 'size'
55+
| 'validationStatus'
56+
>
4457
>
4558

4659
export type TextInputProps = Merge<React.ComponentPropsWithoutRef<'input'>, TextInputNonPassthroughProps>
@@ -62,10 +75,14 @@ const TextInput = React.forwardRef<HTMLInputElement, TextInputProps>(
6275
loaderText = 'Loading',
6376
monospace,
6477
validationStatus,
78+
sx: sxProp,
6579
size: sizeProp,
6680
onFocus,
6781
onBlur,
6882
// start deprecated props
83+
width: widthProp,
84+
minWidth: minWidthProp,
85+
maxWidth: maxWidthProp,
6986
variant: variantProp,
7087
// end deprecated props
7188
type = 'text',
@@ -120,7 +137,11 @@ const TextInput = React.forwardRef<HTMLInputElement, TextInputProps>(
120137
contrast={contrast}
121138
disabled={disabled}
122139
monospace={monospace}
140+
sx={sxProp}
123141
size={sizeProp}
142+
width={widthProp}
143+
minWidth={minWidthProp}
144+
maxWidth={maxWidthProp}
124145
variant={variantProp}
125146
hasLeadingVisual={Boolean(LeadingVisual || showLeadingLoadingIndicator)}
126147
hasTrailingVisual={Boolean(TrailingVisual || showTrailingLoadingIndicator)}

packages/react/src/TextInputWithTokens/TextInputWithTokens.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,17 @@ function TextInputWithTokensInnerComponent<TokenComponentType extends AnyReactCo
8383
className,
8484
block,
8585
disabled,
86+
sx: sxProp,
8687
tokens,
8788
onTokenRemove,
8889
tokenComponent: TokenComponent = Token,
8990
preventTokenWrapping = false,
9091
size = 'xlarge',
9192
hideTokenRemoveButtons = false,
9293
maxHeight,
94+
width: widthProp,
95+
minWidth: minWidthProp,
96+
maxWidth: maxWidthProp,
9397
validationStatus,
9498
variant: variantProp, // deprecated. use `size` instead
9599
visibleTokenCount,
@@ -258,13 +262,17 @@ function TextInputWithTokensInnerComponent<TokenComponentType extends AnyReactCo
258262
disabled={disabled}
259263
hasLeadingVisual={Boolean(LeadingVisual || showLeadingLoadingIndicator)}
260264
hasTrailingVisual={Boolean(TrailingVisual || showTrailingLoadingIndicator)}
265+
width={widthProp}
266+
minWidth={minWidthProp}
267+
maxWidth={maxWidthProp}
261268
size={inputSizeMap[size]}
262269
validationStatus={validationStatus}
263270
variant={variantProp} // deprecated. use `size` prop instead
264271
onClick={focusInput}
265272
data-token-wrapping={Boolean(preventTokenWrapping || maxHeight) || undefined}
266273
className={clsx(className, styles.TextInputWrapper)}
267274
style={maxHeight ? {maxHeight, ...style} : style}
275+
sx={sxProp}
268276
>
269277
{IconComponent && !LeadingVisual && <IconComponent className="TextInput-icon" />}
270278
<TextInputInnerVisualSlot

packages/react/src/Textarea/Textarea.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type {TextareaHTMLAttributes, ReactElement} from 'react'
22
import React from 'react'
33
import {TextInputBaseWrapper} from '../internal/components/TextInputWrapper'
44
import type {FormValidationStatus} from '../utils/types/FormValidationStatus'
5+
import type {SxProp} from '../sx'
56
import classes from './TextArea.module.css'
67

78
export const DEFAULT_TEXTAREA_ROWS = 7
@@ -45,7 +46,8 @@ export type TextareaProps = {
4546
* CSS styles to apply to the Textarea
4647
*/
4748
style?: React.CSSProperties
48-
} & TextareaHTMLAttributes<HTMLTextAreaElement>
49+
} & TextareaHTMLAttributes<HTMLTextAreaElement> &
50+
SxProp
4951

5052
/**
5153
* An accessible, native textarea component that supports validation states.
@@ -56,6 +58,7 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
5658
{
5759
value,
5860
disabled,
61+
sx: sxProp,
5962
required,
6063
validationStatus,
6164
rows = DEFAULT_TEXTAREA_ROWS,
@@ -73,6 +76,7 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
7376
): ReactElement => {
7477
return (
7578
<TextInputBaseWrapper
79+
sx={sxProp}
7680
validationStatus={validationStatus}
7781
disabled={disabled}
7882
block={block}

packages/react/src/internal/components/TextInputWrapper.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import React, {type ComponentProps} from 'react'
2+
import {type ResponsiveValue} from 'styled-system'
3+
import type {SxProp} from '../../sx'
24
import type {FormValidationStatus} from '../../utils/types/FormValidationStatus'
35
import {clsx} from 'clsx'
46

@@ -22,7 +24,13 @@ type StyledTextInputBaseWrapperProps = {
2224
style?: React.CSSProperties
2325
onClick?: React.MouseEventHandler
2426
children?: React.ReactNode
25-
}
27+
/** @deprecated Update `width` using CSS modules or style. */
28+
width?: string | number | ResponsiveValue<string | number>
29+
/** @deprecated Update `min-width` using CSS modules or style. */
30+
minWidth?: string | number | ResponsiveValue<string | number>
31+
/** @deprecated Update `max-width` using CSS modules or style. */
32+
maxWidth?: string | number | ResponsiveValue<string | number>
33+
} & SxProp
2634

2735
type StyledTextInputWrapperProps = {
2836
hasLeadingVisual?: boolean
@@ -33,6 +41,7 @@ export const TextInputBaseWrapper = React.forwardRef<HTMLElement, StyledTextInpu
3341
function TextInputBaseWrapper(
3442
{
3543
className,
44+
style,
3645
variant,
3746
size,
3847
isInputFocused,
@@ -42,6 +51,9 @@ export const TextInputBaseWrapper = React.forwardRef<HTMLElement, StyledTextInpu
4251
contrast,
4352
monospace,
4453
block,
54+
width,
55+
minWidth,
56+
maxWidth,
4557
...restProps
4658
},
4759
forwardRef,
@@ -60,6 +72,11 @@ export const TextInputBaseWrapper = React.forwardRef<HTMLElement, StyledTextInpu
6072
data-trailing-action={hasTrailingAction || undefined}
6173
data-validation={validationStatus || undefined}
6274
data-variant={variant || undefined}
75+
style={
76+
typeof width === 'string' || typeof minWidth === 'string' || typeof maxWidth === 'string'
77+
? {width, maxWidth, minWidth, ...style}
78+
: style
79+
}
6380
{...restProps}
6481
/>
6582
)

0 commit comments

Comments
 (0)