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
5 changes: 5 additions & 0 deletions .changeset/witty-cheetahs-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@razorpay/blade': patch
---

feat: add hideClearButton Prop to SearchInput Component
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export default {
labelPosition: 'top',
helpText: undefined,
autoCapitalize: undefined,
hideClearButton: false,
},
tags: ['autodocs'],
argTypes: {
Expand Down Expand Up @@ -185,6 +186,14 @@ export default {
category: propsCategory.KEYBOARD_PROPS,
},
},
hideClearButton: {
control: {
type: 'boolean',
},
table: {
category: propsCategory.TRAILING_VISUAL_PROPS,
},
},
...getStyledPropsArgTypes(),
},
parameters: {
Expand Down Expand Up @@ -256,6 +265,11 @@ const SearchInputTemplate: StoryFn<typeof SearchInputComponent> = (args) => {
export const Default = SearchInputTemplate.bind({});
Default.storyName = 'Default';

export const SearchInputWithClearButtonHidden = SearchInputTemplate.bind({});
SearchInputWithClearButtonHidden.storyName = 'SearchInput with Clear Button Hidden';
SearchInputWithClearButtonHidden.args = {
hideClearButton: true,
};
export const SearchInputHelpText = SearchInputTemplate.bind({});
SearchInputHelpText.storyName = 'SearchInput with Help Text';
SearchInputHelpText.args = {
Expand Down
15 changes: 13 additions & 2 deletions packages/blade/src/components/Input/SearchInput/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ type SearchInputCommonProps = Pick<
* @default true
*/
showSearchIcon?: boolean;
/**
* Toggle the visibility of the clear button.
*
* @default false
*/
hideClearButton?: boolean;
} & StyledPropsBlade;

/*
Expand Down Expand Up @@ -90,7 +96,9 @@ type SearchInputPropsWithLabel = {
};

type SearchInputProps = (SearchInputPropsWithA11yLabel | SearchInputPropsWithLabel) &
SearchInputCommonProps;
SearchInputCommonProps & {
hideClearButton?: boolean;
};

// 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 @@ -121,6 +129,9 @@ const _SearchInput: React.ForwardRefRenderFunction<BladeElementRef, SearchInputP
testID,
size = 'medium',
showSearchIcon = true,

hideClearButton = false,

...rest
},
ref,
Expand All @@ -145,7 +156,7 @@ const _SearchInput: React.ForwardRefRenderFunction<BladeElementRef, SearchInputP
return <Spinner accessibilityLabel="Loading Content" color="primary" />;
}

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