angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.24k stars 6.7k forks source link

bug(material-date-fns-adapter): MatDateFnsAdapter not imported into standalone dialog component #28041

Open Catscratch opened 8 months ago

Catscratch commented 8 months ago

Is this a regression?

The previous version in which this bug was not present was

No response

Description

I'm not sure if it is a bug or just how it works atm, but when using a MatDatepicker with MatDateFnsModule it will not find the DateAdapter when using this in a standalone dialog component. (it's working in all other standalone components which are not a dialog).

If I add the MatDateFnsAdapter to the imports of the component which opens the dialog, everything is fine. But with standalone components I usually expect the imports in the component that really needs it.

I prepared a StackBlitz example.

Reproduction

StackBlitz link: https://stackblitz.com/edit/stackblitz-starters-35ebyd?file=src%2Fmain.ts Steps to reproduce:

  1. Wait for the dev server to load
  2. Click "Open Dialog"
  3. Click on the calendar icon in the input field
  4. See the console log

Expected Behavior

No error message should appear on the console and the datepicker should open.

Actual Behavior

Datepicker does not open because of the console error.

Environment

crisbeto commented 8 months ago

We haven't really reworked the date adapters for standalone yet, but you can get it to work like this: https://stackblitz.com/edit/stackblitz-starters-cokrru?file=src%2Fdialog%2Fdialog.component.ts

Catscratch commented 8 months ago

Thanks for your reply. That's at least a workaround. We solved it (for now) by importing the MatDateFnsModule in the main.ts which will make it available for the whole application, but of course, it's not really standalone anymore.

But it will work, at least until the data adapters are updated to work with standalone components.