Skip to content

Commit a6a8db6

Browse files
author
Kubit
committed
Add onRightIconClick to InputSearch
1 parent 57d9311 commit a6a8db6

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

src/components/inputSearch/__tests__/inputSearch.test.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const mockProps = {
3535
handleOpenOptions: jest.fn(),
3636
handleValueSelected: jest.fn(),
3737
handleClickInputSearch: jest.fn(),
38+
handleIconClick: jest.fn(),
3839
onClick: jest.fn(),
3940
onIconClick: jest.fn(),
4041
onInputPopoverIconClick: jest.fn(),
@@ -133,14 +134,13 @@ describe('New Input Search Component', () => {
133134
expect(inputSearch).toHaveFocus();
134135
});
135136

136-
it('Should click input icon', async () => {
137-
const onFocus = jest.fn();
138-
renderProvider(<InputSearch {...mockProps} onFocus={onFocus} />);
137+
it('Should click on input icon', () => {
138+
renderProvider(<InputSearch {...mockProps} />);
139+
140+
const inputIcon = screen.getByLabelText('Open Info');
141+
fireEvent.click(inputIcon);
139142

140-
const triggerButton = screen.getByRole('button', { name: 'Open Info' });
141-
fireEvent.click(triggerButton);
142-
fireEvent.click(triggerButton);
143-
expect(mockProps.rightIcon.onClick).toHaveBeenCalledTimes(2);
143+
expect(mockProps.rightIcon.onClick).toHaveBeenCalled();
144144
});
145145

146146
it('Should render loading and valueSelected', async () => {

src/components/inputSearch/inputSearch.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const InputSearchComponent = React.forwardRef(
6161
handleChangeInputSearch,
6262
handleClickInputSearch,
6363
handleIconClick,
64+
handleRightIconClick,
6465
handleInputPopoverIconClick,
6566
handleOpenOptions,
6667
handleValueSelected,
@@ -84,6 +85,7 @@ const InputSearchComponent = React.forwardRef(
8485
regex,
8586
onClick,
8687
onIconClick: props.icon?.onClick,
88+
onRightIconClick: props.rightIcon?.onClick,
8789
executeInternalOpenOptions,
8890
onInputPopoverIconClick,
8991
elementsToShow,
@@ -126,6 +128,7 @@ const InputSearchComponent = React.forwardRef(
126128
open={openOptions}
127129
optionList={optionsFiltered}
128130
regex={regex}
131+
rightIcon={{ ...props.rightIcon, onClick: handleRightIconClick }}
129132
searchText={searchText}
130133
state={state}
131134
styles={styles}

src/components/inputSearch/stories/inputSearch.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const commonArgs: IInputSearch = {
4242
secondaryLabel: labelSecondary(themeSelected),
4343
additionalInfo: additionalInfoAction(themeSelected),
4444
label: { content: 'label', requiredSymbol: '*' },
45-
icon: { icon: ICONS.ICON_PLACEHOLDER, altText: 'alternative' },
45+
rightIcon: { icon: ICONS.ICON_PLACEHOLDER, altText: 'alternative' },
4646
placeholder: 'Select an option',
4747
closeIcon: { icon: ICONS.ICON_CLOSE },
4848
value: 'option5',

src/components/inputSearch/types/inputSearch.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ type propsToOmitInputStandalone =
132132
| 'variant'
133133
| 'styles'
134134
| 'inputId'
135-
| 'icon'
136135
| 'error'
137136
| 'disabled'
138137
| 'textCounter'
@@ -174,7 +173,6 @@ export interface IInputSearchStandAlone extends Omit<IInputStandAlone, propsToOm
174173
// actionBottomSheet
175174
sublabel?: OptionSublabelType;
176175
closeIcon?: IElementOrIcon;
177-
icon?: IElementOrIcon;
178176
// input popover
179177
/**
180178
* @deprecated `inputPopoverIcon` will be removed. Use `popoverRightIcon` instead

0 commit comments

Comments
 (0)