Skip to content
Closed
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 @@ -73,6 +73,7 @@ export default {
labelPosition: 'top',
helpText: undefined,
autoCapitalize: undefined,
hideClearButton: false,
},
tags: ['autodocs'],
argTypes: {
Expand Down Expand Up @@ -198,6 +199,14 @@ export default {
category: propsCategory.KEYBOARD_PROPS,
},
},
hideClearButton: {
control: {
type: 'boolean',
},
table: {
category: propsCategory.TRAILING_VISUAL_PROPS,
},
},
...getStyledPropsArgTypes(),
},
parameters: {
Expand Down Expand Up @@ -269,6 +278,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
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 @@ -64,6 +64,12 @@ type SearchInputCommonProps = Pick<
* @default true
*/
showSearchIcon?: boolean;
/**
* Toggle the visibility of the clear button.
*
* @default false
*/
hideClearButton?: boolean;
/**
* Optional trailing to be shown at the end of the input.
*/
Expand Down Expand Up @@ -99,7 +105,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 @@ -132,6 +140,7 @@ const _SearchInput: React.ForwardRefRenderFunction<BladeElementRef, SearchInputP
testID,
size = 'medium',
showSearchIcon = true,
hideClearButton = false,
trailing,
...rest
},
Expand Down Expand Up @@ -236,7 +245,7 @@ const _SearchInput: React.ForwardRefRenderFunction<BladeElementRef, SearchInputP
return <Spinner accessibilityLabel="Loading Content" color="primary" />;
}

if (shouldShowClearButton && trailingDropdown) {
if (!hideClearButton && shouldShowClearButton && trailingDropdown) {
return (
<BaseBox display="flex" gap="spacing.3">
{renderClearButton()} <Divider orientation="vertical" />
Expand Down