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

feat: add hideClearButton Prop to SearchInput Component #2433

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
labelPosition: 'top',
helpText: undefined,
autoCapitalize: undefined,
hideClearButton: false,
},
tags: ['autodocs'],
argTypes: {
Expand Down Expand Up @@ -184,6 +185,14 @@
table: {
category: propsCategory.KEYBOARD_PROPS,
},
},
hideClearButton: {

Check failure on line 189 in packages/blade/src/components/Input/SearchInput/SearchInput.stories.tsx

View workflow job for this annotation

GitHub Actions / Validate Source Code

Replace `·hideClearButton:·{·` with `hideClearButton:·{`
control: {
type: 'boolean',
},
table: {
category: propsCategory.TRAILING_VISUAL_PROPS,
},
},
...getStyledPropsArgTypes(),
},
Expand Down Expand Up @@ -256,6 +265,11 @@
export const Default = SearchInputTemplate.bind({});
Default.storyName = 'Default';

export const SearchInputWithClearButtonHidden = SearchInputTemplate.bind({});
SearchInputWithClearButtonHidden.storyName = 'SearchInput with Clear Button Hidden';
SearchInputWithClearButtonHidden.args = {
hideClearButton: true, // Set the new prop to true
yadavshubham01 marked this conversation as resolved.
Show resolved Hide resolved
};
export const SearchInputHelpText = SearchInputTemplate.bind({});
SearchInputHelpText.storyName = 'SearchInput with Help Text';
SearchInputHelpText.args = {
Expand Down
13 changes: 11 additions & 2 deletions packages/blade/src/components/Input/SearchInput/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
* @default true
*/
showSearchIcon?: boolean;
/**

Check failure on line 57 in packages/blade/src/components/Input/SearchInput/SearchInput.tsx

View workflow job for this annotation

GitHub Actions / Validate Source Code

Delete `·`
* Toggle the visibility of the clear button.
*
* @default false
*/
hideClearButton?: boolean; // New prop
yadavshubham01 marked this conversation as resolved.
Show resolved Hide resolved
} & StyledPropsBlade;

/*
Expand Down Expand Up @@ -85,7 +91,9 @@
};

type SearchInputProps = (SearchInputPropsWithA11yLabel | SearchInputPropsWithLabel) &
SearchInputCommonProps;
SearchInputCommonProps & {
hideClearButton?: boolean; // Add a line to include the new prop
yadavshubham01 marked this conversation as resolved.
Show resolved Hide resolved
}

Check failure on line 96 in packages/blade/src/components/Input/SearchInput/SearchInput.tsx

View workflow job for this annotation

GitHub Actions / Validate Source Code

Insert `;`

// need to do this to tell TS to infer type as SearchInput of React Native and make it believe that `ref.current.clear()` exists
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -116,6 +124,7 @@
testID,
size = 'medium',
showSearchIcon = true,
hideClearButton = false,
...styledProps
},
ref,
Expand All @@ -140,7 +149,7 @@
return <Spinner accessibilityLabel="Loading Content" color="primary" />;
}

if (shouldShowClearButton) {
if (!hideClearButton && shouldShowClearButton) {
return (
<IconButton
size="medium"
Expand Down
Loading