Skip to content

Commit 359614c

Browse files
authored
Textfield add variant prop (#10036)
<!-- ☝️How to write a good PR title: - Prefix it with [ComponentName] (if applicable), for example: [Button] - Start with a verb, for example: Add, Delete, Improve, Fix… - Give as much context as necessary and as little as possible - Prefix it with [WIP] while it’s a work in progress --> ### WHY are these changes introduced? Fixes #10033 <!-- Context about the problem that’s being addressed. --> ### WHAT is this pull request doing? Deprecates `borderless` prop in favor of `variant='borderless'`
1 parent 28f4165 commit 359614c

File tree

5 files changed

+45
-6
lines changed

5 files changed

+45
-6
lines changed

.changeset/rotten-comics-think.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@shopify/polaris': major
3+
---
4+
5+
Replaced `borderless` prop with `variant` on TextField
6+
7+
Migration: `npx @shopify/polaris-migrator react-rename-component-prop <path> --componentName="TextField" --from="borderless" --to="variant" --newValue="borderless"`

polaris-react/src/components/Filters/components/SearchField/SearchField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export function SearchField({
105105
clearButton
106106
onClearButtonClick={handleClear}
107107
disabled={disabled}
108-
borderless={borderlessQueryField}
108+
variant={borderlessQueryField ? 'borderless' : undefined}
109109
/>
110110
);
111111
}

polaris-react/src/components/TextField/TextField.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ export function All() {
738738
label="Borderless"
739739
value="Value"
740740
onChange={() => {}}
741-
borderless
741+
variant="borderless"
742742
autoComplete="off"
743743
/>
744744
</FormLayout.Group>

polaris-react/src/components/TextField/TextField.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ interface NonMutuallyExclusiveProps {
161161
requiredIndicator?: boolean;
162162
/** Indicates whether or not a monospaced font should be used */
163163
monospaced?: boolean;
164+
/** Visual styling options for the TextField
165+
* @default 'inherit'
166+
*/
167+
variant?: 'inherit' | 'borderless';
164168
/** Callback fired when clear button is clicked */
165169
onClearButtonClick?(id: string): void;
166170
/** Callback fired when value is changed */
@@ -171,8 +175,6 @@ interface NonMutuallyExclusiveProps {
171175
onFocus?: (event?: React.FocusEvent) => void;
172176
/** Callback fired when input is blurred */
173177
onBlur?(event?: React.FocusEvent): void;
174-
/** Removes the border around the input. Used in the IndexFilters component. */
175-
borderless?: boolean;
176178
}
177179

178180
export type MutuallyExclusiveSelectionProps =
@@ -233,12 +235,12 @@ export function TextField({
233235
monospaced,
234236
selectTextOnFocus,
235237
suggestion,
238+
variant = 'inherit',
236239
onClearButtonClick,
237240
onChange,
238241
onSpinnerChange,
239242
onFocus,
240243
onBlur,
241-
borderless,
242244
}: TextFieldProps) {
243245
const i18n = useI18n();
244246
const [height, setHeight] = useState<number | null>(null);
@@ -290,7 +292,7 @@ export function TextField({
290292
error && styles.error,
291293
multiline && styles.multiline,
292294
focus && !disabled && styles.focus,
293-
borderless && styles.borderless,
295+
variant !== 'inherit' && styles[variant],
294296
);
295297

296298
const inputType = type === 'currency' ? 'text' : type;

polaris-react/src/components/TextField/tests/TextField.test.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,6 +2277,36 @@ describe('<TextField />', () => {
22772277
expect(currentSelection).toStrictEqual(expectedSelection);
22782278
});
22792279
});
2280+
2281+
it('adds a borderless className when borderless prop is passed', () => {
2282+
const textField = mountWithApp(
2283+
<TextField
2284+
label="TextField"
2285+
onChange={noop}
2286+
autoComplete="off"
2287+
variant="borderless"
2288+
/>,
2289+
);
2290+
2291+
expect(textField).toContainReactComponent('div', {
2292+
className: expect.stringContaining(styles.borderless),
2293+
});
2294+
});
2295+
2296+
it('adds a borderless className when variant=`borderless` prop is passed', () => {
2297+
const textField = mountWithApp(
2298+
<TextField
2299+
label="TextField"
2300+
onChange={noop}
2301+
autoComplete="off"
2302+
variant="borderless"
2303+
/>,
2304+
);
2305+
2306+
expect(textField).toContainReactComponent('div', {
2307+
className: expect.stringContaining(styles.borderless),
2308+
});
2309+
});
22802310
});
22812311

22822312
function noop() {}

0 commit comments

Comments
 (0)