-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature(datepicker): Built-in support for styling today's date in calendar #1470
Comments
You can do it on your side even today by providing a custom template for a day cell. I don't think we need another API as the one in place makes it possible to cover your use case and many others. |
Check the "Custom day view" demo: https://ng-bootstrap.github.io/#/components/datepicker |
The point is that this is a pretty generic use case, not that it isn't currently possible. I'd be willing to bet that your average user would be interested in having this feature built in rather than having to write it themselves. Many other datepickers include this feature by default so I suspect this is the case. I'm well aware of the documentation that you've linked and I've already written this functionality for myself. |
OK, I see. We might revisit this feature request post 1.0 but it won't happen before we cut 1.0 stable. |
Awesome. I appreciate that. I just didn't want it to get lost since I'm sure it will pop up again sooner or later. |
+1 👍 Thanks for looking into this when you have time. |
The problem here is that you can't detect current date automatically since application might use timezone different from browser's. |
Seems redundant to me as you can always compare with
I'd say we should at least add the custom css class |
The same could be said about using the isDisabled function to check if a date is disabled, but a 'disabled' property is still included in the day template context.
While I initially proposed both I do want to mention that by going the CSS class route you lose a lot of customization options. I don't have a specific example in mind but by going with a CSS class you're pretty much limiting yourself to CSS solutions. That is - styling the day (color/font/etc) based on if it is today's date. What you couldn't do is change the DOM with separate templates for each. This, for example, wouldn't be possible
I don't know if anybody wants to do this or why. It doesn't match my uses - just wanted to point it out in case someone gripes in the future. Either option is still better than what I'm doing in my production code. |
@adammedford thanks for the example, I agree it is better to have both. My point was you can always do this: <ng-template #customDay let-date>
<span class="custom-day">
<ng-container *ngIf='isToday(date); else notTodayTemplate'>
{{ date.day }}
</ng-container
<ng-template #notTodayTemplate>
It is not today.
</ng-template>
</span>
</ng-template>
We could pass many things to the template (ex. why not By the way since So I'd still go for the |
Thanks @maxokorokov! I wasn't aware of that change in 3.3.0.
For what it's worth, my initial reasoning for opening this issue was that I have a couple of applications that have dozens of datepickers (some the same, others with variations.) Some of them only use a custom day template to highlight the day. It would be nice if I didn't have to duplicate that template across those - the CSS covers this. Others are more complicated than just styling. For those I didn't want to duplicate the isToday() logic, although in retrospect a 'isToday' pipe would have been a good solution. Anybody with those needs I'd point in that direction. I like the CSS approach because it will satisfy the vast majority of those with minimal intervention. My thinking was that to apply a class to today's date - you already have to have an isToday available internally. |
Adds a custom CSS class `.ngb-dp-today` on a cell with today's date and a custom `today: boolean` field in the day template context Fixes ng-bootstrap#1470
Adds a custom CSS class `.ngb-dp-today` on a cell with today's date and a custom `today: boolean` field in the day template context Fixes #1470
My users want to see today's date in the calendar.
This is a simple enough feature to write myself but I think its use case is generic enough to justify adding it to the default behavior. My primary pain point is that I have written several components that wrap this date picker to augment its configuration under different circumstances and this is just one more piece of logic that I have to duplicate to a certain extent.
Either:
The text was updated successfully, but these errors were encountered: