Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions js/src/date-range-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,11 @@ class DateRangePicker extends BaseComponent {
todayButtonEl.classList.add(...this._getButtonClasses(this._config.todayButtonClasses))
todayButtonEl.type = 'button'
todayButtonEl.textContent = this._config.todayButton

if (isDateDisabled(new Date(), this._config.minDate, this._config.maxDate, this._config.disabledDates)) {
todayButtonEl.disabled = true
}

todayButtonEl.addEventListener('click', () => {
const date = new Date()
this._calendarDate = date
Expand Down
29 changes: 29 additions & 0 deletions js/tests/unit/date-range-picker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,35 @@
expect(dateRangePicker._endDate.toDateString()).toBe(today.toDateString())
})

it('should disable today button when today is a disabled date', () => {
fixtureEl.innerHTML = '<div></div>'
const div = fixtureEl.querySelector('div')
const yesterday = new Date()
yesterday.setDate(yesterday.getDate() - 1)
const dateRangePicker = new DateRangePicker(div, { // eslint-disable-line no-unused-vars
footer: true,
todayButton: 'Today',
maxDate: yesterday
})

const footer = div.querySelector('.date-picker-footer')
const todayBtn = Array.from(footer.querySelectorAll('button')).find(b => b.innerHTML === 'Today')
expect(todayBtn.disabled).toBeTrue()
})

it('should not disable today button when today is selectable', () => {
fixtureEl.innerHTML = '<div></div>'
const div = fixtureEl.querySelector('div')
const dateRangePicker = new DateRangePicker(div, { // eslint-disable-line no-unused-vars

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note test

Unused variable dateRangePicker.
footer: true,
todayButton: 'Today'
})

const footer = div.querySelector('.date-picker-footer')
const todayBtn = Array.from(footer.querySelectorAll('button')).find(b => b.innerHTML === 'Today')
expect(todayBtn.disabled).toBeFalse()
})

it('should not set end date on today click when range is false', () => {
fixtureEl.innerHTML = '<div></div>'
const div = fixtureEl.querySelector('div')
Expand Down Expand Up @@ -881,7 +910,7 @@
it('should create confirm button when confirmButton is set', () => {
fixtureEl.innerHTML = '<div></div>'
const div = fixtureEl.querySelector('div')
const dateRangePicker = new DateRangePicker(div, { // eslint-disable-line no-unused-vars

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note test

Unused variable dateRangePicker.
footer: true,
confirmButton: 'OK'
})
Expand Down
Loading