Skip to content

Commit

Permalink
chore (ui-react): propagate isDisabled to Clear button in SearchField (
Browse files Browse the repository at this point in the history
…#3708)

Co-authored-by: Ioana Brooks <68251134+ioanabrooks@users.noreply.github.com>
Co-authored-by: Scott Rees <6165315+reesscot@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 21, 2023
1 parent 2b95560 commit 9551c52
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-yaks-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/ui-react': patch
---

Clear button is removed for disabled SearchField
2 changes: 1 addition & 1 deletion packages/react/src/primitives/SearchField/SearchField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const SearchFieldPrimitive: Primitive<SearchFieldProps, 'input'> = (
<FieldClearButton
ariaLabel={clearButtonLabel}
excludeFromTabOrder
isVisible={strHasLength(composedValue)}
isVisible={!isDisabled && strHasLength(composedValue)}
onClick={onClearHandler}
size={size}
variation="link"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const testId = 'SearchFieldTestId';
const searchQuery = 'Amplify UI components';

describe('SearchField component', () => {
const ControlledSearchField = () => {
const ControlledSearchField = ({ isDisabled = false }) => {
const [value, setValue] = React.useState('');
const onChange: React.ChangeEventHandler<HTMLInputElement> = (event) => {
setValue(event.target.value);
Expand All @@ -28,6 +28,7 @@ describe('SearchField component', () => {
onChange={onChange}
onClear={onClear}
value={value}
isDisabled={isDisabled}
/>
);
};
Expand Down Expand Up @@ -225,5 +226,13 @@ describe('SearchField component', () => {
const clearButton = await screen.findByLabelText(clearButtonLabel);
expect(clearButton).toHaveAttribute('aria-label', clearButtonLabel);
});

it('should remove clear button when input is disabled', async () => {
render(<ControlledSearchField isDisabled />);

const clearButton = screen.queryByLabelText(clearButtonLabel);

expect(clearButton).toBeNull();
});
});
});

0 comments on commit 9551c52

Please sign in to comment.