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

[TextField] Fix position of loading spinner when there is no clear button visible #11466

Merged
merged 2 commits into from
Jan 18, 2024
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
6 changes: 6 additions & 0 deletions .changeset/metal-fireants-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@shopify/polaris': patch
'polaris.shopify.com': patch
---

[TextField] Fixed positional issue of loading indicator when no clear button is present
6 changes: 6 additions & 0 deletions polaris-react/src/components/TextField/TextField.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ $spinner-icon-size: 12px;
visibility: visible;
opacity: 1;
}

// stylelint-disable-next-line -- needed to remove extra margin between loading indicator and clear button when visible
.Loading:has(+ .ClearButton) {
margin-right: 0;
}
}

&:not(:focus-within) {
Expand Down Expand Up @@ -447,6 +452,7 @@ $spinner-icon-size: 12px;
.Loading {
// stylelint-disable-next-line -- Needed to render the spinner above the Backdrop
z-index: var(--pc-text-field-contents);
margin-right: var(--p-space-300);

svg {
display: block;
Expand Down
22 changes: 20 additions & 2 deletions polaris-react/src/components/TextField/TextField.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,6 @@ export function WithAutoSizeAndOtherElements() {

const handleChange = useCallback((newValue) => setValue(newValue), []);

const handleTextFieldChange = useCallback((value) => setValue(value), []);

const handleClearButtonClick = useCallback(() => setValue(''), []);

return (
Expand All @@ -1048,3 +1046,23 @@ export function WithAutoSizeAndOtherElements() {
/>
);
}

export function WithLoading() {
const [value, setValue] = useState('Jaded Pixel');

const handleChange = useCallback((newValue) => setValue(newValue), []);

const handleClearButtonClick = useCallback(() => setValue(''), []);

return (
<TextField
label="Store name"
value={value}
onChange={handleChange}
autoComplete="off"
clearButton
onClearButtonClick={handleClearButtonClick}
loading
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ examples:
- fileName: text-field-with-auto-size-and-dynamic-suffix.tsx
title: With auto size and dynamic suffix
description: Use to only show the suffix when the text field has a value.
- fileName: text-field-with-loading.tsx
title: With loading
description: Use to indicate that the text field is in a loading state.
previewImg: /images/components/selection-and-input/text-field.png
---

Expand Down
28 changes: 28 additions & 0 deletions polaris.shopify.com/pages/examples/text-field-with-loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {TextField} from '@shopify/polaris';
import {useState, useCallback} from 'react';
import {withPolarisExample} from '../../src/components/PolarisExampleWrapper';

function LoadingExample() {
const [value, setValue] = useState('');

const handleChange = useCallback(
(newValue: string) => setValue(newValue),
[],
);

const handleClearButtonClick = useCallback(() => setValue(''), []);

return (
<TextField
label="Store name"
value={value}
onChange={handleChange}
autoComplete="off"
clearButton
onClearButtonClick={handleClearButtonClick}
loading
/>
);
}

export default withPolarisExample(LoadingExample);
Loading