Skip to content

Angular 18 #393

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

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open

Angular 18 #393

wants to merge 18 commits into from

Conversation

GNURub
Copy link

@GNURub GNURub commented Jun 4, 2024

Migration to angular 18

  • Updateded deps
  • ControlFlow
  • Standalone components
  • Removed NgModules
  • Material errors fixed

@Sergiobop
Copy link

Sergiobop commented Jun 7, 2024

One can only hope to get this merged, thanks @GNURub

Edit:
If someone wants to try this: https://www.npmjs.com/package/@ngxmc/datetime-picker
npm install --save @ngxmc/datetime-picker
npm install --save @ngxmc/moment-adapter

@GNURub
Copy link
Author

GNURub commented Jun 10, 2024

I published the branch: https://www.npmjs.com/settings/ngxmc/packages

@scohen-trinity
Copy link

Hey @GNURub, I have been attempting to use your fork for Angular 18 and have been running into some issues with the exposed modules, is there an exposed module for NgxMatDatetimePickerModule?

@GNURub
Copy link
Author

GNURub commented Jun 18, 2024

@scohen-trinity, standalone components:

imports: [
	...,
 	NgxMatDatepickerActions,
    NgxMatDatepickerActions,
    NgxMatDatepickerApply,
    NgxMatDatepickerCancel,
    NgxMatDatepickerInput,
    NgxMatDatepickerToggle,
    NgxMatDatetimepicker,
	...,
],
template:  `<input
                matInput
                [ngxMatDatetimePicker]="event"
                class="hidden"
                formControlName="date"
                [min]="now"
              />
              <ngx-mat-datetime-picker #event>
                <ngx-mat-datepicker-actions>
                  <button mat-button ngxMatDatepickerCancel>Cancel</button>
                  <button
                    mat-raised-button
                    color="primary"
                    ngxMatDatepickerApply
                  >
                    Apply
                  </button>
                </ngx-mat-datepicker-actions>
              </ngx-mat-datetime-picker>`

@scohen-trinity
Copy link

@GNURub thank you for the clarification and I was able to get everything working with the standalone components with one issue with one of the ES Module files, I get this error message:

[vite] error while updating dependencies:
Error: Build failed with 1 error:
error: Cannot create property 'message' on string 'C:\dev\project\node_modules\@ngxmc\datetime-picker\fesm2022\ngxmc-datetime-picker.mjs: Errors found in the template:
<ng-content> element cannot have content. (""disabled ? -1 : tabIndex\"\n  [disabled]=\"disabled\"\n  [disableRipple]=\"disableRipple()\"\n>\n  [ERROR ->]<ng-content select=\"[ngxMatDatepickerToggleIcon]\">\n    <svg\n      class=\"mat-datepicker-toggle-d"): C:\dev\project\node_modules\@ngxmc\datetime-picker\fesm2022\ngxmc-datetime-picker.mjs@5110:1758

I don't think that I added any input to the package and this prevents the project from building, can you help me troubleshoot this?

@GNURub
Copy link
Author

GNURub commented Jun 21, 2024

@scohen-trinity share the pice of code and ng version

@ghost
Copy link

ghost commented Jul 19, 2024

please do merge this branch, there only one library in our project which is waiting for the update to Angular 18.

@Sergiobop
Copy link

Sergiobop commented Jul 25, 2024

Hi @GNURub, i'm trying to give your solution a try but i found some issues:

Issue 1

An unhandled exception occurred: Missing "./lib/core/date-formats" specifier in "@ngxmc/datetime-picker" package

I figured out the problem, was this import:
import { NgxMatDateFormats } from '@ngxmc/datetime-picker/lib/core/date-formats';

I did:

const CUSTOM_DATE_FORMATS: NgxMatDateFormats = {
  parse: {
    dateInput: 'L, LT',
  },
  display: {
    dateInput: 'L, LT',
    monthYearLabel: 'MMM YYYY',
    dateA11yLabel: 'LL',
    monthYearA11yLabel: 'MMMM YYYY',
  },
};

Changed to:

const CUSTOM_DATE_FORMATS = {
  parse: {
    dateInput: 'L, LT',
  },
  display: {
    dateInput: 'L, LT',
    monthYearLabel: 'MMM YYYY',
    dateA11yLabel: 'LL',
    monthYearA11yLabel: 'MMMM YYYY',
  },
};

And it works

Other working solution is avoid creating the constant and provide the value directly:

...
{
      provide: NGX_MAT_DATE_FORMATS,
      useValue: {
        parse: {
          dateInput: 'L, LT',
        },
        display: {
          dateInput: 'L, LT',
          monthYearLabel: 'MMM YYYY',
          dateA11yLabel: 'LL',
          monthYearA11yLabel: 'MMMM YYYY',
        },
      },
    },
    ..

Issue 2

The mat-calendar-body-label padding is broken:
Before:
Captura de pantalla 2024-07-25 a las 17 09 42

After:
Captura de pantalla 2024-07-25 a las 17 11 57

Issue 3

The buttons to change the time are disabled when the date is not yet selected, but the color is wrong:
Captura de pantalla 2024-07-25 a las 17 10 32

Issue 4

Changing month using arrows, this warning will appear (track is wrong)
Captura de pantalla 2024-07-25 a las 17 10 49

Thanks again for your work on this branch, i think we can maybe save the lib

@Sergiobop
Copy link

Sergiobop commented Jul 25, 2024

@GNURub I updated my comment pointing some issues i found while testing the branch, i hope it helps!

@Sergiobop
Copy link

Hi @GNURub , Github notified me that you did some work here.

I tested everything again, only problem left is "Issue 3", the arrow buttons color when disabled is still black (instead of grey-disabled color)

Thanks again for your work 👍

@GNURub
Copy link
Author

GNURub commented Aug 2, 2024

I found a very interesting alternative (M3). ng-matero

@Sergiobop Sergiobop mentioned this pull request Aug 19, 2024
@hassanITXI
Copy link

@GNURub if this is approved and not merged is this github not maintained anymore ? should we use https://www.npmjs.com/package/@ngxmc/datetime-picker

@capraibex
Copy link

@h2qutc
Are there any plans to merge this PR?
It would be really nice, to have an updated version of this package :)

@ewalke31
Copy link

@GNURub could you update for Angular 19?

@GNURub
Copy link
Author

GNURub commented Nov 19, 2024

Yeah. I am going to keep it

@ChristianLoosliVGT
Copy link

can you estimate when you will support angular 19 material?

@GNURub
Copy link
Author

GNURub commented Nov 20, 2024

It is very coupled with material, I have taken a look and in v19 they have deprecated many of the methods that this package uses... At the moment v19 is using angular v19 and v18 in material.

V19

@ChristianLoosliVGT
Copy link

I have tried to use https://www.npmjs.com/package/@ngxmc/color-picker/v/19.0.0:

import { MAT_COLOR_FORMATS, NgxMatColorPickerModule, NGX_MAT_COLOR_FORMATS } from '@ngxmc/color-picker';

--> TS2724: '@ngxmc/color-picker' has no exported member named NgxMatColorPickerModule. Did you mean NgxMatColorPickerInput

@GuillaumeBenini
Copy link

I have tried to use https://www.npmjs.com/package/@ngxmc/color-picker/v/19.0.0:

import { MAT_COLOR_FORMATS, NgxMatColorPickerModule, NGX_MAT_COLOR_FORMATS } from '@ngxmc/color-picker';

--> TS2724: '@ngxmc/color-picker' has no exported member named NgxMatColorPickerModule. Did you mean NgxMatColorPickerInput

I would guess the component is now exported as standalone rather than through an NgModule.

@serg-mois-capital
Copy link

serg-mois-capital commented Dec 9, 2024

@GNURub but how to install it with material 18 and angular 19 ? With --force still getting:

./node_modules/@ngxmc/datetime-picker/fesm2022/ngxmc-datetime-picker.mjs:4307:34-49 - Error: export 'mixinErrorState' (imported as 'mixinErrorState') was not found in '@angular/material/core'

./node_modules/@ngxmc/datetime-picker/fesm2022/ngxmc-datetime-picker.mjs:5506:37-47 - Error: export 'mixinColor' (imported as 'mixinColor') was not found in '@angular/material/core' (possible exports: n '@angular/material/core'

@choucry13
Copy link

hi, i have the same issue than @serg-mois-capital . Material removes use of mixinErrorState. It's same for mixinColor.

@GNURub
Copy link
Author

GNURub commented Dec 13, 2024

v19.1.0

@serg-mois-capital
Copy link

serg-mois-capital commented Dec 13, 2024

God bless you @GNURub

@@ -147,7 +142,7 @@ export class NgxMatMomentAdapter extends NgxMatDateAdapter<Moment> {
}

clone(date: Moment): Moment {
return date.clone().locale(this.locale);
return date.clone().locale(this.dateLocale);
Copy link

@cincilkka cincilkka Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why changed to dateLocale? It is initialized in constructor and its value can never be changed via setLocale() method. That means that there is no way how to reflect application locale changes in adapter... As you can see, this leads to two different locales handle by picker. (Days of week have 'cs' locale but month selector and display format is 'en').
image
image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can change it via the 'MAT_DATE_LOCALE' token

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried but moment adapter does not reflect changes of MAT_DATE_LOCALE, it takes only provided value it in main.ts {provide: MAT_DATE_LOCALE, useValue: 'cs-CZ' }. But not dynamically from any other component. Native adapter works as expected because it sets locale based on MAT_DATE_LOCALE in constructor but then works only with "locale" variable. Moment adapter uses both "locale" and "dateLocale" and I think that there is a problem. Or please do you have any working example how to change it dynamically?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to deprecate the custom providers of this library, to use the ones from material that already have time support. We will support the ones from material which are: material-date-fns-adapter, material-luxon-adapter and material-moment-adapter. I'm testing, please be patient.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@cincilkka cincilkka Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thank you :-) Using adapter from Material seems to me like the best option. I will wait for final version.

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

Successfully merging this pull request may close these issues.