Skip to content

Commit

Permalink
Textfield add variant prop (#10036)
Browse files Browse the repository at this point in the history
<!--
  ☝️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'`
  • Loading branch information
kyledurand committed Aug 18, 2023
1 parent 28f4165 commit 359614c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .changeset/rotten-comics-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@shopify/polaris': major
---

Replaced `borderless` prop with `variant` on TextField

Migration: `npx @shopify/polaris-migrator react-rename-component-prop <path> --componentName="TextField" --from="borderless" --to="variant" --newValue="borderless"`
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function SearchField({
clearButton
onClearButtonClick={handleClear}
disabled={disabled}
borderless={borderlessQueryField}
variant={borderlessQueryField ? 'borderless' : undefined}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ export function All() {
label="Borderless"
value="Value"
onChange={() => {}}
borderless
variant="borderless"
autoComplete="off"
/>
</FormLayout.Group>
Expand Down
10 changes: 6 additions & 4 deletions polaris-react/src/components/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ interface NonMutuallyExclusiveProps {
requiredIndicator?: boolean;
/** Indicates whether or not a monospaced font should be used */
monospaced?: boolean;
/** Visual styling options for the TextField
* @default 'inherit'
*/
variant?: 'inherit' | 'borderless';
/** Callback fired when clear button is clicked */
onClearButtonClick?(id: string): void;
/** Callback fired when value is changed */
Expand All @@ -171,8 +175,6 @@ interface NonMutuallyExclusiveProps {
onFocus?: (event?: React.FocusEvent) => void;
/** Callback fired when input is blurred */
onBlur?(event?: React.FocusEvent): void;
/** Removes the border around the input. Used in the IndexFilters component. */
borderless?: boolean;
}

export type MutuallyExclusiveSelectionProps =
Expand Down Expand Up @@ -233,12 +235,12 @@ export function TextField({
monospaced,
selectTextOnFocus,
suggestion,
variant = 'inherit',
onClearButtonClick,
onChange,
onSpinnerChange,
onFocus,
onBlur,
borderless,
}: TextFieldProps) {
const i18n = useI18n();
const [height, setHeight] = useState<number | null>(null);
Expand Down Expand Up @@ -290,7 +292,7 @@ export function TextField({
error && styles.error,
multiline && styles.multiline,
focus && !disabled && styles.focus,
borderless && styles.borderless,
variant !== 'inherit' && styles[variant],
);

const inputType = type === 'currency' ? 'text' : type;
Expand Down
30 changes: 30 additions & 0 deletions polaris-react/src/components/TextField/tests/TextField.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2277,6 +2277,36 @@ describe('<TextField />', () => {
expect(currentSelection).toStrictEqual(expectedSelection);
});
});

it('adds a borderless className when borderless prop is passed', () => {
const textField = mountWithApp(
<TextField
label="TextField"
onChange={noop}
autoComplete="off"
variant="borderless"
/>,
);

expect(textField).toContainReactComponent('div', {
className: expect.stringContaining(styles.borderless),
});
});

it('adds a borderless className when variant=`borderless` prop is passed', () => {
const textField = mountWithApp(
<TextField
label="TextField"
onChange={noop}
autoComplete="off"
variant="borderless"
/>,
);

expect(textField).toContainReactComponent('div', {
className: expect.stringContaining(styles.borderless),
});
});
});

function noop() {}

0 comments on commit 359614c

Please sign in to comment.