Skip to content
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

[Angular 16] Angular 16.2.1. breaks the styling of the datetimepicker component #372

Open
bastianferch opened this issue Nov 18, 2023 · 2 comments

Comments

@bastianferch
Copy link

Angular 16.2.1. removes the complete styling of the datetimepicker component. In version 16.0.1. everything is working fine.
See this stackoverflow post

@stephen-dirtcreative
Copy link

stephen-dirtcreative commented Nov 20, 2023

It seems the material styles for the date picker don't get injected. If you have a standard mat-datepicker implemented and load that, after viewing it, this component inherits the injected styles and looks correct again.

There seems to be something in material now known as the "Tokens API" and the datepicker was updated to use it between 16.1 and 16.2

See commit: angular/components@c5af860


Not being familiar in depth with material component building, I didn't feel confident trying to figure out a patch for the changes. What I did as a hack to avoid needing to down-level my main material library was to place a standard component on the page where the datetime picker component was used, style it absolute and off screen, hooked it with @ViewChild and forced an open / close of it in the AfterViewInit to "initialize" the missing styles. Something like this:

In the template

  <mat-form-field class="date-time-field" subscriptSizing="dynamic" style="position: absolute; top: -10000px; left: -10000px; visibility: hidden;">
    <input matInput [matDatepicker]="fauxPicker">
    <mat-datepicker-toggle matIconSuffix [for]="fauxPicker"></mat-datepicker-toggle>
    <mat-datepicker #fauxPicker></mat-datepicker>
  </mat-form-field>

In the component TS file (just the relevant bits)

import { ChangeDetectorRef, ViewChild } from '@angular/core'
import { MatDatepicker } from '@angular/material/datepicker'

@Component({ ... })
export class SomeClass implements AfterViewInit {
  @ViewChild('fauxPicker')
  private readonly fauxPicker: MatDatepicker<null>

  public constructor (
    private readonly changeDetectorRef: ChangeDetectorRef,
  ) {}

  public ngAfterViewInit (): void {
    if (this.fauxPicker !== undefined) {
      this.fauxPicker.open()
      this.changeDetectorRef.detectChanges()
      this.fauxPicker.close()
      this.changeDetectorRef.detectChanges()
    }
  }
}

This brings the styles into the view and the ngx datetime picker loads correctly, at least in my scenario.

@AlexElin
Copy link

AlexElin commented Dec 1, 2023

duplicate of #348

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants