Skip to content

Commit 5a3202d

Browse files
committed
feat(*): add logic to disable Today button when it is not selectable
1 parent 4b577a0 commit 5a3202d

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

projects/picker/src/lib/date-time/calendar.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
</button>
4141
@if (currentView === DateView.MONTH && showTodayButton) {
4242
<button
43+
[disabled]="!isTodayAllowed"
4344
(click)="jumpToToday()"
4445
class="owl-dt-control owl-dt-control-button owl-dt-control-today-button"
4546
type="button">

projects/picker/src/lib/date-time/calendar.component.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,29 @@ export class OwlCalendarComponent<T> implements AfterContentInit, AfterViewCheck
189189
});
190190
}
191191

192+
public get isTodayAllowed(): boolean {
193+
if (!this.dateTimeAdapter) {
194+
return false;
195+
}
196+
const now = this.dateTimeAdapter.now();
197+
// Normalize 'today' to the start of the day, how minDate and maxDate are stored
198+
const today = this.dateTimeAdapter.createDate(
199+
this.dateTimeAdapter.getYear(now),
200+
this.dateTimeAdapter.getMonth(now),
201+
this.dateTimeAdapter.getDate(now)
202+
);
203+
204+
if (this.minDate && this.dateTimeAdapter.compare(today, this.minDate) < 0) {
205+
return false;
206+
}
207+
208+
if (this.maxDate && this.dateTimeAdapter.compare(today, this.maxDate) > 0) {
209+
return false;
210+
}
211+
212+
return true;
213+
}
214+
192215
/**
193216
* Date filter for the month and year view
194217
*/

projects/picker/src/sass/picker.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,15 @@ $theme-color: #3f51b5;
532532
&:hover {
533533
background-color: rgba(0, 0, 0, 0.12);
534534
}
535+
536+
&:disabled {
537+
color: rgb(0 0 0 / 0.4);
538+
cursor: default;
539+
540+
&:hover {
541+
background-color: transparent;
542+
}
543+
}
535544
}
536545

537546
.owl-dt-control-arrow-button {

0 commit comments

Comments
 (0)