diff --git a/__test__/components/DatePickerMobile.test.tsx b/__test__/components/DatePickerMobile.test.tsx index b1bfc36..2e1acda 100644 --- a/__test__/components/DatePickerMobile.test.tsx +++ b/__test__/components/DatePickerMobile.test.tsx @@ -30,6 +30,7 @@ jest.mock('@linagora/twake-mui', () => { }) const scrollIntoViewMock = jest.fn() +// eslint-disable-next-line @typescript-eslint/unbound-method const originalScrollIntoView = window.HTMLElement.prototype.scrollIntoView beforeAll(() => { @@ -63,20 +64,27 @@ describe('DatePickerMobile', () => { const setup = async ( initialDate: Date ): Promise< - RenderResult & { calendarApi: CalendarApi; onDateChange: jest.Mock } + RenderResult & { + calendarApi: CalendarApi + onDateChange: jest.Mock + onCloseDatePicker: jest.Mock + } > => { const calendarApi = makeCalendarApi(initialDate) const onDateChange = jest.fn() + const onCloseDatePicker = jest.fn() + const renderResult = await act(() => render( ) ) - return { ...renderResult, calendarApi, onDateChange } + return { ...renderResult, calendarApi, onDateChange, onCloseDatePicker } } const expectNavigatedDate = ( @@ -160,6 +168,7 @@ describe('DatePickerMobile', () => { calendarRef={{ current: calendarApi }} currentDate={newDate} onDateChange={onDateChange} + onCloseDatePicker={jest.fn()} // Need to pass dummy fn for required prop /> ) }) diff --git a/src/components/Menubar/MobileMenuBar.tsx b/src/components/Menubar/MobileMenuBar.tsx index 59e83b0..5116353 100644 --- a/src/components/Menubar/MobileMenuBar.tsx +++ b/src/components/Menubar/MobileMenuBar.tsx @@ -36,6 +36,16 @@ export const MobileMenubar: React.FC = ({ const monthName = t(`months.standalone.${monthIndex}`) const dateLabel = `${monthName} ${year}` + const onToggleDatePicker = (): void => { + setOpenDatePicker(prev => { + const newState = !prev + setTimeout(() => { + calendarRef.current?.updateSize?.() + }, 0) + return newState + }) + } + return ( <>
@@ -53,13 +63,13 @@ export const MobileMenubar: React.FC = ({ setOpenDatePicker(prev => !prev)} + onClick={onToggleDatePicker} > {dateLabel} setOpenDatePicker(prev => !prev)} + onClick={onToggleDatePicker} aria-label={ openDatePicker ? t('menubar.hideDatePicker') @@ -89,6 +99,7 @@ export const MobileMenubar: React.FC = ({ calendarRef={calendarRef} currentDate={currentDate} onDateChange={onDateChange} + onCloseDatePicker={() => setOpenDatePicker(false)} /> ) : null} diff --git a/src/components/Menubar/components/DatePickerMobile.tsx b/src/components/Menubar/components/DatePickerMobile.tsx index 04a95ef..331f59b 100644 --- a/src/components/Menubar/components/DatePickerMobile.tsx +++ b/src/components/Menubar/components/DatePickerMobile.tsx @@ -13,12 +13,14 @@ export type DatePickerMobileProps = { calendarRef: React.RefObject currentDate: Date onDateChange?: (date: Date) => void + onCloseDatePicker: () => void } export const DatePickerMobile: React.FC = ({ calendarRef, currentDate, - onDateChange + onDateChange, + onCloseDatePicker }) => { const { t, lang } = useI18n() const theme = useTheme() @@ -40,6 +42,12 @@ export const DatePickerMobile: React.FC = ({ onChangeDate(dayjs(new Date(year, monthIndex, clampedDay))) } + const handlePickDate = (newDate: PickerValue): void => { + onChangeDate(newDate) + onCloseDatePicker() + calendarRef.current?.updateSize?.() + } + return ( = ({ > null, actionBar: () => null }} - sx={{ width: '100%', marginTop: '10px' }} + sx={{ + width: '100%', + marginTop: '10px' + }} slotProps={{ toolbar: { hidden: true }, layout: {