Skip to content

feat: add disabled dates and weekdays to DatePicker - #9862

Merged
web-padawan merged 4 commits into
mainfrom
feat/date-picker-disable-dates
Aug 11, 2026
Merged

web-padawan merged 4 commits into
mainfrom
feat/date-picker-disable-dates

Conversation

@web-padawan

@web-padawan web-padawan commented Aug 10, 2026 •

Copy link
Copy Markdown
Member

Date Picker could only restrict selection with min and max, so a continuous range. Applications often need to block individual dates, such as public holidays or days that are already fully booked, and recurring weekdays, such as weekends.

This adds the two static constraints:

datePicker.setDisabledDates(List.of(LocalDate.of(2026, 12, 24), LocalDate.of(2026, 12, 25)));
datePicker.setDisabledWeekdays(Set.of(DayOfWeek.SATURDAY, DayOfWeek.SUNDAY));

Disabled dates render as disabled in the overlay and cannot be selected, and entering one by hand marks the field invalid with DatePickerI18n.setDisabledDateErrorMessage(...).

Changes

Both constraints are evaluated in the browser through the web component's isDateDisabled property, so neither costs a server round trip. The rules are pushed to the connector as [year, month, day] triples with a zero-based month, and as ISO weekday numbers, which are the encodings the web component already uses — so the connector parses nothing.

The trade-off is that the set is sent to the browser in full every time the configuration is updated, including on every attach. The Javadoc says so and points to the upcoming provider for large or changing sets. onAttach skips the update entirely when nothing is configured, so components that do not use the feature send nothing.

The weekday check uses the web component's createDate helper rather than new Date(year, month, day), which maps years below 100 into the 20th century and would report the wrong weekday for them.

The new validation runs after the min and max checks, so a date that is both out of range and disabled still reports the min/max message.

Scope

This PR covers the two static constraints only. Separate PRs follow for:

  • a date metadata provider, mapped onto the web component's dateMetadataProvider, for rules that need the server and for custom part names
  • TestBench element additions and integration tests
  • the same API on Date Time Picker

Part of vaadin/platform#2867


🤖 Generated with Claude Code

Static disabled-date rules are evaluated in the browser through the web
component's isDateDisabled property, so they cost no server round trip.
They are pushed to the connector as [year, month, day] triples with a
zero-based month, and as ISO weekday numbers, matching the encodings the
web component already uses.

The weekday check uses the web component's createDate helper rather than
the Date constructor, which maps years below 100 into the 20th century.

First step of the disabled dates feature. The date metadata provider and
DateTimePicker support follow separately.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@web-padawan
web-padawan marked this pull request as ready for review August 10, 2026 14:50

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes — left 3 comments.

Finding
🧹 The clearCache parameter, pendingCacheClear field, and clearCache JS call are dead code — no caller ever passes true.
⚡ The isDateDisabled closure always does both the date-key lookup and a Date allocation per cell, even when only one of the two sets is configured.
🧹 requestDateMetadataUpdate re-implements the exact debounce structure of the existing requestI18nUpdate.

The clearCache parameter, the pendingCacheClear field and the client
call they guarded had no caller that passed true, so the path could
never run. They belong with the date metadata provider that needs them
and come back together with it.

The connector now runs only the checks that are actually configured.
The web component calls isDateDisabled for every calendar cell on every
render, so with only disabled dates set no Date is allocated per cell,
and with only disabled weekdays set no key string is built.

The i18n and date metadata updates now share one scheduling helper
instead of repeating the same coalescing logic.
Both setters described how the constraint is applied in the browser and
pointed at a date metadata provider that this version does not have yet.
The first is an implementation detail, the second is a reference to an
API that does not exist, so both are dropped.

The null element behavior was only mentioned in prose inside @PARAM. It
is now documented with @throws, which is what the tests assert.
@web-padawan
web-padawan removed the request for review from vursen August 11, 2026 12:51
@sonarqubecloud

Copy link
Copy Markdown

@web-padawan
web-padawan added this pull request to the merge queue Aug 11, 2026
Merged via the queue into main with commit a75f39a Aug 11, 2026
17 checks passed
@web-padawan
web-padawan deleted the feat/date-picker-disable-dates branch August 11, 2026 13:05
@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 25.3.0-alpha9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants