Skip to content

Commit

Permalink
Disable days past maxDate (#4415)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasSlama authored Jul 23, 2024
1 parent 0351ab2 commit 8d97d12
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-singers-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@toptal/picasso-calendar': patch
---

- fix issue with days past maxDate are not disabled
1 change: 0 additions & 1 deletion packages/base/Calendar/src/Calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ export const Calendar = forwardRef<HTMLDivElement, Props>(function Calendar(
onSelect={range ? handleRangeChange : handleSingleDateChange}
fromDate={minDate}
fromYear={minDate?.getFullYear()}
toYear={maxDate?.getFullYear()}
onMonthChange={month => setNavigationMonth(month)}
toDate={maxDate}
numberOfMonths={shouldRenderMultipleMonths ? numberOfMonths : 1}
Expand Down
26 changes: 25 additions & 1 deletion packages/base/Calendar/src/Calendar/test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import { render } from '@toptal/picasso-test-utils'
import { fireEvent, render } from '@toptal/picasso-test-utils'
import { describe, expect, it } from '@jest/globals'

import { Calendar } from './Calendar'

Expand Down Expand Up @@ -40,4 +41,27 @@ describe('Calendar', () => {
expect(monthHeader).toBeInTheDocument()
})
})

describe('when maxDate is set', () => {
it('will not trigger onChange when we click on disabled button', () => {
const minDate = new Date(2024, 6, 1)
const maxDate = new Date(2024, 6, 10)
const value = new Date(2024, 6, 2)
const onChange = jest.fn()

const { getByTestId } = render(
<Calendar
minDate={minDate}
maxDate={maxDate}
value={value}
onChange={onChange}
/>
)

const disabledButton = getByTestId('day-button-11')

fireEvent.click(disabledButton)
expect(onChange).not.toHaveBeenCalled()
})
})
})

0 comments on commit 8d97d12

Please sign in to comment.