Skip to content
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
1 change: 1 addition & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
- Fixed a bug in `Banner` where loading state wasn't getting passed to `primaryAction` ([#4338](https://github.com/Shopify/polaris-react/pull/4338))
- Fixed `Popover` not correctly positioning itself ([#4357](https://github.com/Shopify/polaris-react/pull/4357))
- Fixed a bug `TextField` where Safari would render the incorrect text color ([#4344](https://github.com/Shopify/polaris-react/pull/4344))
- Fixed screen readers reading out the clear button in `TextField` when there is no input ([#4369](https://github.com/Shopify/polaris-react/pull/4369))
- Fix bug in Safari where `Button` text is gray instead of white after changing state from disabled to enabled ([#4270](https://github.com/Shopify/polaris-react/pull/4270))
- Bring back borders on the `IndexTable` sticky cells ([#4150](https://github.com/Shopify/polaris-react/pull/4150))
- Adjust `IndexTable` sticky z-index to avoid collisions with focused `TextField` ([#4150](https://github.com/Shopify/polaris-react/pull/4150))
Expand Down
4 changes: 0 additions & 4 deletions src/components/TextField/TextField.scss
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,6 @@ $stacking-order: (
&:disabled {
cursor: default;
}

&.ClearButton-hidden {
@include visually-hidden;
}
Comment on lines -235 to -237
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we need to hide the button rather than remove it? We could always add aria-hidden if so.

}

.Spinner {
Expand Down
32 changes: 15 additions & 17 deletions src/components/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,24 +274,22 @@ export function TextField({
}

const clearButtonVisible = normalizedValue !== '';
const clearButtonClassName = classNames(
styles.ClearButton,
!clearButtonVisible && styles['ClearButton-hidden'],
);

const clearButtonMarkup = clearButton ? (
<button
type="button"
testID="clearButton"
className={clearButtonClassName}
onClick={handleClearButtonPress}
disabled={disabled}
tabIndex={clearButtonVisible ? 0 : -1}
>
<VisuallyHidden>{i18n.translate('Polaris.Common.clear')}</VisuallyHidden>
<Icon source={CircleCancelMinor} color="base" />
</button>
) : null;
const clearButtonMarkup =
clearButtonVisible && clearButton ? (
<button
type="button"
testID="clearButton"
className={styles.ClearButton}
onClick={handleClearButtonPress}
disabled={disabled}
>
<VisuallyHidden>
{i18n.translate('Polaris.Common.clear')}
</VisuallyHidden>
<Icon source={CircleCancelMinor} color="base" />
</button>
) : null;

const handleNumberChange = useCallback(
(steps: number) => {
Expand Down
10 changes: 5 additions & 5 deletions src/components/TextField/tests/TextField.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1068,8 +1068,8 @@ describe('<TextField />', () => {
expect(findByTestID(textField, 'clearButton').exists()).toBeTruthy();
});

it('renders a visually hidden clear button in inputs without a value', () => {
const textField = mountWithAppProvider(
it('does not render a clear button in inputs without a value', () => {
const textField = mountWithApp(
<TextField
id="MyTextField"
label="TextField"
Expand All @@ -1079,9 +1079,9 @@ describe('<TextField />', () => {
/>,
);

const clearButton = findByTestID(textField, 'clearButton');
expect(clearButton.hasClass('ClearButton-hidden')).toBeTruthy();
expect(clearButton.prop('tabIndex')).toBe(-1);
expect(textField).not.toContainReactComponent('button', {
testID: 'clearButton',
});
});

it('calls onClearButtonClicked() with an id when the clear button is clicked', () => {
Expand Down