Customize the appearance of date range selection in Angular Datepicker

My approach involves using dateClass to highlight a specific time range on the calendar. This range is not selectable; rather, I simply identify the start and end dates and then proceed to highlight the range between them when the calendar is opened.

Here is my TypeScript code snippet:

 RangeClass: MatCalendarCellClassFunction<Moment> = (cellDate, view) => {
        if (view === "month") {
            const date = cellDate.toDate();
            return date >= mystart && date <= myend ? "range-class" : "";
        }

        return "";
    };

For styling, here is the CSS used for the highlighted range:

.range-class {
  background: white;
  border: 3px solid orange;
}

When it comes to implementation in HTML, I utilize the following code with Angular Material:

<mat-datepicker [dateClass]="RangeClass" #picker></mat-datepicker>

In terms of visual representation, this is how the highlighted range appears: 1

However, I am interested in changing the selection style to something similar to either of these examples: 2 or 3

I am seeking guidance on how to achieve this new selection style. Can you help me with this?

Answer №1

Custom Style Set 1

.mat-calendar-body-selected {
  background-color: black;
  color: #fff;
}
.mat-calendar-body-in-range::before {
  background: #cccccc;
}

Check out the customized style on StackBlitz


Personalized Style Set 2

.mat-calendar-body-in-range .mat-calendar-body-cell-content {
  border: 3px solid orange;
  border-radius: 0;
  border-left-width: 0;
  border-right-width: 0;
}

.mat-calendar-body-range-end > .mat-calendar-body-selected {
  background-color: transparent;
  border: 3px solid orange;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-left-width: 0;
  border-top-right-radius: 50%;
  border-bottom-right-radius: 50%;
}
.mat-calendar-body-range-start > .mat-calendar-body-selected {
  background-color: transparent;
  border: 3px solid orange;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-top-left-radius: 50%;
  border-bottom-left-radius: 50%;
  border-right-width: 0;
}

View the personalized design on StackBlitz

The second set may require some adjustments to suit your needs, but the main structure is there!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular service tested using the put method in a test scenario

Currently, I am delving into test cases using Jasmin and karma to enhance my skills. One interesting project involves creating an Angular service that updates records in a database. While I have experience creating test cases, I must admit that testing met ...

Sticky header in an Angular Material table

Using Angular 7 with Angular material design templates, my current result looks like this: https://i.sstatic.net/G4W78.jpg However, I am aiming for a result similar to the following - with a scrollbar under the sticky header. https://i.sstatic.net/WgjVh ...

Flex box causing Bootstrap5 responsive table to overflow

Need help with fixing overflow issue in a fixed-width div used as a left sidebar. The main content renders correctly except for tables with many columns, causing overflow before the scroll bar appears. How can this be resolved? Various layout attempts hav ...

How to dynamically change the background color of a table based on row values in PHP

I'm working on a PHP table where I want each line to change color based on the value in the first column. For example, if the first column has a value of 1, the line should be red; if it's 2, then blue; and so on. <table> <tr> &l ...

What is the best way to align headings directly above their own bottom border?

Is there a way to make a heading align perfectly with its bottom border? Can negative padding achieve this effect, or should I use underline instead? Perhaps positioning it at the top border of the element below is an option. Thank you! h1 { font: bol ...

Utilize CSS transition to smoothly reveal a hidden div with a fading effect

I am trying to create a hover effect where a caption displayed over an image fades in with a background color change. I have attempted to use transitions but they do not seem to work for block elements. For the code and JSFiddle, please visit this link. ...

Display all pages in the DataTables plugin while utilizing responsive tables and additional features

I am struggling to combine the responsive and fixed header attributes of my current function with the "Show All" list feature, similar to what is demonstrated in this example: https://datatables.net/examples/advanced_init/length_menu.html I need assistanc ...

Increase the padding on the left side of a background image

UPDATE: Solution discovered at this link thanks to Mr. Alien I am attempting to create a heading that resembles the following Title ------------------------------------------------- I have an image that I intend to use as a backdrop for it. However, I& ...

Choose the initial p tag that includes an image, based on the content of another div

I am trying to figure out how to manipulate the code on my website: <div class="the-post-thumbnail"> <img src="" alt="" width="" height="" /> </div> <div class="post-body"> <p><img src="" alt="" width="" height="" ...

Toggle visibility of div element with a button press

Here is the div I have: <div class="margin-bottom hidden-xs"></div> This specific div is initially hidden on a small window size due to the bootstrap 'hidden-xs' class. However, I want it to be shown or hidden when the user clicks o ...

Picture goes missing from slideshow

I am currently using a CSS + Javascript slideshow on my website, inspired by an example from the W3Schools website. Here is the code I have adapted for my web application: $(document).ready(function() { var slideIndex = 1; function showSlides(n) { ...

Struggling with syntax errors while attempting to use ngIf to dynamically switch images in Angular 8

As a newcomer to the Angular world, I'm facing challenges when it comes to displaying different images based on ngx-translate methods. For instance, if the user selects English from the language dropdown, the image with English text should be displaye ...

What is the best way to loop through all mat-checkboxes in Angular 5?

Is there a way for me to automatically have check-1, check-2, and check-3 all checked when I click on check-all? <form> <mat-checkbox type="checkbox" class="select_all"> Check all </mat-checkbox> <br> < ...

Overriding default styles in an Angular component to customize the Bootstrap navbar

Is there a way to alter the color of the app's navbar when a specific page is accessed? The navbar is set in the app.component.html file, and I am attempting to customize it in a component's css file. app.component.html <nav class="navbar na ...

When using the jQuery datepicker on dynamically generated input fields, the selected date automatically updates the first input field

I am currently integrating date inputs with attached datepicker functionality. The issue I am facing is that when I select a date in the first input and proceed to pick another date in the second or subsequent inputs, the last selected date appears in the ...

Tips on prefixing Bootstrap 4 classes to prevent conflicts with CSS classes

Recently, I've been focusing on creating small applications for websites. The websites hosting these apps may or may not use a css framework. To prevent any potential conflicts, I have decided to add a unique prefix to all Bootstrap classes. For insta ...

What is the best way to obtain a reference to an instance of my Angular 2 directive?

Angular 2 rc 5 was written using typescript 1.9 I am trying to access the instance of my attribute directive. Although I am using ViewChild, which typically works with components, it is giving me a handle to the element containing the directive. template ...

Why is my element still occupying space even though it has been hidden with a display of none?

Currently, I'm working on a dropdown navigation menu where one of the list items causes space issues when the display property is set to none. Specifically, the 'Book A Table' item isn't meant to be visible in the center div when the sc ...

Issue with rollover button function in Firefox and Internet Explorer when attempting to submit

I have created a rollover submit button using HTML and JavaScript: <input type="image" id="join" name="join" src="images/join.png" value="join"> My JS code implements the rollover/hover effect: <script type="text/javascript" charset="utf-8"> ...

My goal is to develop a web scraping tool that can extract HTML content from an Angular-based website

Currently, I am developing a Web scraper specifically for an Angular website. To accomplish this task, I have been utilizing the HttpClient class. However, rather than retrieving the expected HTML tags within the body tag of the page, I am encountering &l ...