When adjusting the month/year, the Material Date Picker extends beyond its container

Currently, I have an Angular 18 application with a page that includes a material date picker component.

When I open the Date Picker, everything displays correctly. However, when I try to change the month using the left/right arrow or the year, the data content overflows outside the component container.

You can view the issue here.

Here is the configuration I am using:


            "dependencies": {
                "@angular/animations": "^18.1.3",
                "@angular/cdk": "^18.0.0",
                "@angular/common": "^18.1.3",
                "@angular/compiler": "^18.1.3",
                "@angular/core": "^18.1.3",
                "@angular/fire": "^18.0.1",
                ...
            },
        
    

Style declaration in angular.json:


            "styles": [
                "src/styles.scss",
                "@angular/material/prebuilt-themes/indigo-pink.css"
            ],
        
    

styles.css:


            /* Global styles and imports */
            html,
            body {
                height: 100%;
            }
            ...
        
    

My component with date-time-picker:


            <app-titre-page [titre]="'admin.people.ajouter.titre'" [introduction]="'admin.people.ajouter.introduction'"></app-titre-page>
            ...
        
    

CSS:


            .full-width {
                width: 100%;
                max-width: 600px;
                margin: 0 auto;
                box-sizing: border-box;
            }
            ...
        
    

Typescript:


            import { Component, OnInit } from '@angular/core';
            ...
        
    

It seems like there may be a CSS conflict causing the issue, but I'm having trouble identifying the specific problem. Can you offer any insights or suggestions?

Answer №1

Below are the necessary modifications.

  1. Begin by utilizing the new m3 prebuilt styles instead of the outdated m2 styles (Optional).

         "styles": [
           "src/styles.scss",
           "@angular/material/prebuilt-themes/azure-blue.css"
         ],
    
  2. Ensure that the environment providers are added at the app.module level, not in the shared module, as this was causing the issue.

     @NgModule({
       declarations: [
         AppRoutingModule,
         BrowserModule,
         AdministrationModule,
         SharedModule,
       ],
       providers: [ 
         provideHttpClient(withInterceptorsFromDi()),
         provideAnimationsAsync(),
         provideNativeDateAdapter(),
       ]
     })
     export class AppModule { }
    
  3. Additionally, remove the duplicate translate module import and environment providers since they have already been shifted to the root app.module.

Moreover, if you are implementing lazy loading, ensure that the modules are not added at the app.module.ts level to maintain lazy loading functionality.

imports: [
    AppRoutingModule,
    BrowserModule,
    // AdministrationModule, // <- remove this!
    SharedModule  
  ],
  providers: [ ]
})
export class AppModule { }

Github Repository

Answer №2

Consider using the following code snippet:

HTML:

    <mat-form-field class="example-full-width">
          <mat-label>Select a date</mat-label>
          <input matInput [matDatepicker]="picker">
          <mat-hint>DD/MM/YYYY</mat-hint>
          <mat-datepicker-toggle matIconSuffix [for]="picker">
            <mat-icon matDatepickerToggleIcon>keyboard_arrow_down</mat-icon>
          </mat-datepicker-toggle>
          <mat-datepicker #picker></mat-datepicker>
</mat-form-field>

ts file

import {provideNativeDateAdapter} from '@angular/material/core';
import {MatDatepickerModule} from '@angular/material/datepicker';
import {MatFormFieldModule} from '@angular/material/form-field';
import {MatIconModule} from '@angular/material/icon';
import {MatInputModule} from '@angular/material/input';
@Component({
  selector: 'custom-icon-datepicker-example',
  templateUrl: 'custom-icon-datepicker-example.html',
  standalone: true,
  providers: [provideNativeDateAdapter()],
  imports: [MatFormFieldModule, MatInputModule, MatDatepickerModule, MatIconModule],

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

CSS: Adjusting alignment differences between local host and server

I've been working on a webpage with rotating background images, and everything looked perfect on my localhost. But once I uploaded it to the server and viewed it in different browsers, some of the people in the images were not positioned as intended, ...

Can the @font-face src URL be modified?

We have integrated FontAwesome with Bootstrap on our website. However, we encountered an issue when using FA with a custom minifier as it tries to load fonts from a relative path, leading to a 404 error due to the structure of the minified URL. To address ...

Using Typescript to override an abstract method that has a void return type

abstract class Base{ abstract sayHello(): void; } class Child extends Base{ sayHello() { return 123; } } The Abstract method in this code snippet has a return type of void, but the implementation in the Child class returns a number. S ...

Default parameters for the ngMessages directive

I am looking for a way to make modifications to AngularJS Material inputs without having to create a new directive or add attributes everywhere. Is there a way to parameterize all ngMessages directives without the need to add them individually? <md-inp ...

The Material UI button feature neglects to account for custom CSS styles when attempting to override the default settings

Utilizing a custom bootstrap css styles in my react app, I am seeking to enhance the default material ui components with the bootstrap styles. import React, {useState} from 'react'; import 'cg-bootstrap/core/build/cg-bootstrap-standard.css&a ...

Is it possible to utilize a variable for binding, incorporate it in a condition, and then return the variable, all while

There are times when I bind a variable, use it to check a condition, and then return it based on the result. const val = getAttribute(svgEl, "fill"); if (val) { return convertColorToTgml(val); } const ancestorVal = svgAncestorValue(svgEl, "fill"); if (a ...

Enhancing the appearance of a PHP HTML email

I scoured the web for an answer to this question and all I could find was to include the following: $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; and ...

Move the divs within the overflow container by sliding them, then take out the initial element and append it to the end

Currently, when I utilize .appendTo(".wrapper") as shown in the code below, it eliminates the animation effect. My goal is to have the div on the far left slide out of view, triggering an overflow hidden effect, and then be placed at the end of the slide c ...

Discovering the font-weight attribute in Selenium IDE

Currently, I am working with Selenium IDE and aim to detect when a text element has the 'font-weight:bold' CSS property applied to it using 'verifyAttribute'. The specific CSS locator being used is: css=body.home.es ul#languages li:nt ...

Determine the full location information with the help of Google Maps SDK without the need

My current challenge involves dealing with a list of unformatted and incorrectly written addresses. I am seeking a way to iterate through these flawed strings and generate more organized and accurate addresses using one of the many Google Maps SDKs availa ...

Using the Ngclass function with a pair of objects

Can you include 2 objects in an ngclass function like this? <div class="progress-bar"[ngClass]="getProgressValues(obj.val1,obj.val2)"> </div> I am encountering a JSON error. SyntaxError: JSON.parse: bad control character in string literal at l ...

Building a table using MUI 5 and the powerful Grid component from Material UI

For my project, I decided to utilize the Grid component of Material UI v5 to create a global table component. This choice was made due to the difficulties encountered when trying to modify the border and border radius for the table row and footer elements. ...

Is there a way to perfectly center text both vertically and horizontally to the right side of an image?

I'm working on developing a mobile website using jQuery Mobile and I want to include images in my "collapsible" elements. Here is the code I am using: <div data-role="collapsible" data-collapsed="true"> <h3><img src="image ...

Ways to calculate outcome

I'm fairly new to PHP and have run into an issue regarding displaying the number of results. For example, showing 'There are 200 results'. Thank you in advance. Below is the code I am working with: try { $bdd = new PDO("mysql:host=localho ...

identifying the :hover state of a link that has a distinct ID

If I were to have the code as follows: .nav > li.dropdown.open.active > a:hover and I needed to target the same style for a link 'a' with the unique id #futurebutton, what would be the correct syntax? Would it not be?: .nav > li.d ...

Ways to enlarge image size without compromising the image resolution?

My image is in PNG format or as a blob. It has dimensions of 800px by 600px. However, when I try to resize it using various canvas methods like the one mentioned in this Stack Overflow thread: Resize image, need a good library, it loses quality. I wou ...

instructions on how to showcase a text message within the fontawesome square icon

Can someone help me with styling my code? I want to display a text message inside a square box with dimensions of 1x. <span class="fa-stack fa-5x" style="margin-left:5%"> <i class="fa fa-square-o fa-stack-2x"></i> </span> ...

Unable to resolve TypeScript error: Potential 'undefined' object

Here is the code snippet that I am working with: const queryInput = useRef() const handleSubmit = (e: FormEvent<HTMLFormElement>) => { e.preventDefault() if (queryInput && queryInput.current) { console.log(`queryInput.cur ...

Creating a Curved Border with Clip Path in CSS

Hey there! I'm currently attempting to add a speech bubble at the bottom left using clip-path, but I'm struggling to adjust the pixels just right to achieve the clear and exact look I want. Can someone provide suggestions on how to accomplish thi ...

Is there a way to change the names of bundles created during ng serve in Angular 13?

I am looking to change the names of bundles created after running ng serve in an Angular Application. Currently, the bundles are: vendor.js polyfills.js styles.css styles.js main.js runtime.js I want to rename these ...