diff --git a/packages/dnb-eufemia/src/components/date-picker/DatePickerCalc.js b/packages/dnb-eufemia/src/components/date-picker/DatePickerCalc.js index a1cc2b84590..e88316e7856 100644 --- a/packages/dnb-eufemia/src/components/date-picker/DatePickerCalc.js +++ b/packages/dnb-eufemia/src/components/date-picker/DatePickerCalc.js @@ -21,6 +21,7 @@ import getDaysInMonth from 'date-fns/getDaysInMonth' import toDate from 'date-fns/toDate' import parseISO from 'date-fns/parseISO' import parse from 'date-fns/parse' +import startOfDay from 'date-fns/startOfDay' import { warn } from '../../shared/component-helper' @@ -171,8 +172,8 @@ const isWithinSelectionCalc = (date, startDate, endDate) => { const isDisabledCalc = (date, minDate, maxDate) => { // isBefore and isAfter return false if comparison date is undefined, which is useful here in case minDate and maxDate aren't supplied return ( - (minDate && isBefore(date, minDate)) || - (maxDate && isAfter(date, maxDate)) + (minDate && isBefore(date, startOfDay(minDate))) || + (maxDate && isAfter(date, startOfDay(maxDate))) ) } export { isDisabledCalc as isDisabled } diff --git a/packages/dnb-eufemia/src/components/date-picker/__tests__/DatePicker.test.tsx b/packages/dnb-eufemia/src/components/date-picker/__tests__/DatePicker.test.tsx index 9dba300a4a6..38515250d46 100644 --- a/packages/dnb-eufemia/src/components/date-picker/__tests__/DatePicker.test.tsx +++ b/packages/dnb-eufemia/src/components/date-picker/__tests__/DatePicker.test.tsx @@ -1528,6 +1528,24 @@ describe('DatePicker component', () => { expect.objectContaining({ target: secondInput }) ) }) + + it('should have todays date enabled in calendar if minDate is today', async () => { + const minDate = new Date() + + render() + + const button = document.querySelector( + '.dnb-input__submit-element > button' + ) + + await userEvent.click(button) + + const todayButton = document.querySelector( + '.dnb-date-picker__day--today > button' + ) + + expect(todayButton).not.toBeDisabled() + }) }) // for the unit calc tests