@@ -589,7 +589,24 @@ function dateChanged(input: unknown) {
589589
590590function emitInput (value : Date | null ) {
591591 if (value) {
592- // Clamp value within min and max bounds
592+ if (props .allowedDates ) {
593+ // With validation of allowedDates, we have to just return early without emitting
594+ // since there's no logic we can apply to clamp the date to a valid date.
595+ if (
596+ Array .isArray (props .allowedDates ) &&
597+ ! props .allowedDates .includes (startOfDay (value))
598+ ) {
599+ error .value .push (" The selected date is not allowed." );
600+ return ;
601+ } else if (
602+ typeof props .allowedDates == " function" &&
603+ ! props .allowedDates (value)
604+ ) {
605+ error .value .push (" The selected date is not allowed." );
606+ return ;
607+ }
608+ }
609+
593610 if (props .min && value .valueOf () < props .min .valueOf ()) {
594611 value = props .min ;
595612 }
@@ -598,13 +615,6 @@ function emitInput(value: Date | null) {
598615 value = props .max ;
599616 }
600617
601- if (! isDateAllowed (value)) {
602- // With validation of allowedDates, we have to just return early without emitting
603- // since there's no logic we can apply to clamp the date to a valid date.
604- error .value .push (" The selected date is not allowed." );
605- return ;
606- }
607-
608618 if (props .step ) {
609619 const stepMs = props .step * 60 * 1000 ;
610620 let newTime = Math .round (value .valueOf () / stepMs) * stepMs;
@@ -627,35 +637,6 @@ function emitInput(value: Date | null) {
627637 }
628638}
629639
630- function isDateAllowed (date : Date ) {
631- if (! date) return false ;
632-
633- const minDate = props .min ? startOfDay (props .min ) : null ;
634- const maxDate = props .max ? endOfDay (props .max ) : null ;
635-
636- // Check min and max constraints
637- if (minDate && date < minDate) return false ;
638- if (maxDate && date > maxDate) return false ;
639-
640- // Check allowedDates array or function
641- if (props .allowedDates ) {
642- if (
643- Array .isArray (props .allowedDates ) &&
644- ! props .allowedDates .some (
645- (allowedDate ) =>
646- startOfDay (allowedDate).getTime () === startOfDay (date).getTime ()
647- )
648- ) {
649- return false ;
650- }
651- if (typeof props .allowedDates === " function" && ! props .allowedDates (date)) {
652- return false ;
653- }
654- }
655-
656- return true ;
657- }
658-
659640function setToday () {
660641 dateChanged (new Date ());
661642}
0 commit comments