Skip to content

Commit 7a18543

Browse files
author
Kubit
committed
Fic right iconClick on InputDate component
1 parent 0a3b37e commit 7a18543

File tree

4 files changed

+9
-22
lines changed

4 files changed

+9
-22
lines changed

src/components/inputDate/hooks/__tests__/useInputDate.test.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,6 @@ describe('useInputDate Hook', () => {
6767
});
6868
expect(onChange).toHaveBeenCalledTimes(1);
6969
});
70-
it('handleShowCalendar - call onCalendarOpen', () => {
71-
const onCalendarOpen = jest.fn();
72-
const format = 'DD-MM-YYYY';
73-
const minDate = new Date('01-01-2000');
74-
const { result } = renderHookProvider(() => useInputDate({ format, minDate, onCalendarOpen }));
75-
76-
act(() => {
77-
result.current.handleShowCalendar();
78-
});
79-
expect(onCalendarOpen).toHaveBeenCalledTimes(1);
80-
});
8170
it('handleChangeInternalValidate with range value- call onChange', () => {
8271
const onChange = jest.fn();
8372
const format = 'DD-MM-YYYY';

src/components/inputDate/hooks/useInputDate.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ type ReturnType = ReturnTypeInputHook & {
4444
// functions
4545
handleClickInput: React.MouseEventHandler<HTMLInputElement>;
4646
handlePickCalendarDate: (newDate: Date[]) => void;
47-
handleShowCalendar: () => void;
4847
handleOpenCalendar: (open: boolean) => void;
4948
handleChangeInternalValidate: ChangeEventHandler<HTMLInputElement>;
5049
handleWrapperBlur: FocusEventHandler<HTMLDivElement>;
@@ -229,12 +228,6 @@ export const useInputDate = ({
229228
);
230229

231230
// Methods
232-
// Click on the icon to show the calendar
233-
const handleShowCalendar = () => {
234-
setCalendarOpen(!calendarOpen);
235-
props.onCalendarOpen?.(!calendarOpen);
236-
};
237-
238231
// Popover control calendar
239232
const handleOpenCalendar = (open: boolean): void => {
240233
setCalendarOpen(open);
@@ -509,7 +502,6 @@ export const useInputDate = ({
509502
calendarOpen,
510503
handleClickInput,
511504
handlePickCalendarDate,
512-
handleShowCalendar,
513505
handleOpenCalendar,
514506
handleChangeInternalValidate,
515507
value,

src/components/inputDate/inputDate.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ const InputDateComponent = React.forwardRef(
6565
calendarOpen,
6666
handleClickInput,
6767
handlePickCalendarDate,
68-
handleShowCalendar,
6968
handleOpenCalendar,
7069
value,
7170
state,
@@ -122,7 +121,13 @@ const InputDateComponent = React.forwardRef(
122121
calendarOpen={calendarOpen}
123122
dateFormatted={dateFormatted}
124123
hasRange={hasRange}
125-
icon={{ ...props.icon, onClick: handleShowCalendar }}
124+
icon={{
125+
...props.icon,
126+
onClick: event => {
127+
handleOpenCalendar(!calendarOpen);
128+
props.icon?.onClick?.(event);
129+
},
130+
}}
126131
informationAssociatedValue={informationAssociatedValue}
127132
mask={mask}
128133
maskType={maskType}
@@ -136,7 +141,7 @@ const InputDateComponent = React.forwardRef(
136141
rightIcon={{
137142
...props.rightIcon,
138143
onClick: event => {
139-
handleShowCalendar();
144+
handleOpenCalendar(!calendarOpen);
140145
props.rightIcon?.onClick?.(event);
141146
},
142147
}}

src/components/inputDate/inputDateStandAlone.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const InputDateStandAloneComponent = (
4444
variant={props.inputVariant ?? props.styles?.[props.state]?.inputVariant}
4545
/>
4646
<PopoverCalendar
47+
ref={ref}
4748
calendar={props.calendar}
4849
calendarOpen={props.calendarOpen}
4950
closeIcon={props.closeIcon}

0 commit comments

Comments
 (0)