How to keep Angular Material date range picker calendar always open and positioned below input...

Discussão em 'Angular' iniciado por Jobz, Março 3, 2025.

  1. Jobz

    Jobz Guest

    I'm working on an Angular application where I have a specific requirement for a component that uses the Angular Material date range picker. I need the calendar to be always open and displayed directly below the input field that shows the selected date range.

    I've managed to keep the calendar open by overriding the close method in the ngAfterViewInit lifecycle hook:

    ngAfterViewInit() {
    this.surgeryDatepicker.open();
    const originalClose = this.surgeryDatepicker.close.bind(this.surgeryDatepicker);
    this.surgeryDatepicker.close = () => {};
    }


    However, I'm struggling to position the calendar below the input field. The date range picker calendar is displayed as a dialog relative to the body, and my attempts to manually set the top and left position of my container div to align the calendar below the input field have not been successful.

    Here's what I've tried so far:

    • I attempted to get the top and left position of the container div and set those values to the calendar's position.
    • I've looked into the Angular Material documentation for any configuration options that might help with positioning but found none that fit my needs.

    I'm looking for suggestions or approaches to ensure that the date range picker calendar is always visible and positioned right below the input field, regardless of other UI elements or page scrolling.

    Any help or guidance would be greatly appreciated!

    Continue reading...

Compartilhe esta Página