fetrarij / ngx-daterangepicker-material

Pure Angular 2+ date range picker with material design theme, a demo here:
https://fetrarij.github.io/ngx-daterangepicker-material/
MIT License
248 stars 251 forks source link

[inline] Selection isn't highlighted #295

Closed Joelius300 closed 4 years ago

Joelius300 commented 4 years ago

Versions

Angular CLI: 9.1.9
Node: 12.14.1
OS: win32 x64

Angular:
...
Ivy Workspace:

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.901.9
@angular-devkit/core         9.1.9
@angular-devkit/schematics   9.1.9
@schematics/angular          9.1.9
@schematics/update           0.901.9
rxjs                         6.5.4
"ngx-daterangepicker-material": "^3.0.1"

Describe the bug When adding a simple in-line daterangepicker to a project which already has material installed and setup, the selection isn't highlighted. Also the style is off but that seems to be a side-effect of that (maybe #282 is related?).

I'm new to angular and I don't know what I'm missing here. Is there a step that's not documented in the readme (like adding moment.js) or is this a bug?

To Reproduce Basically follow the readme:

Expected behavior The date is selected and displayed in the div below the picker.
The selection is highlighted like in the basic in-line demo.

Actual behavior The date is selected and displayed in the div below the picker but nothing is highlighted.

Screenshots Expected (taken from demo): grafik

Actual (10. - 12. June should be highlighted but it's not): grafik

Stackblitz link I tried to create a stackblitz with the same steps but there are errors I don't know how to fix :/
https://stackblitz.com/edit/angular-ivy-z1rwff

Additional context Here's a full project which was created by following the repro steps that shows the issue: repro-project.zip

Things I tried:

th3b3s1 commented 4 years ago

I have the same issue

nimasrn commented 4 years ago

I have the same issue too. any solution yet?

kirega commented 4 years ago

Hey @Joelius300 , I guess you can force the calendar to update the selection by, getting the instance of the datePicker with @ViewChild and updating your chosenDate function as follows

  @ViewChild(DaterangepickerComponent, { static: false }) datePicker: DaterangepickerComponent;

  chosenDate(chosenDate: { chosenLabel: string; startDate: moment.Moment; endDate: moment.Moment }): void {
      console.log(chosenDate);
      this.inlineDate = chosenDate;
       /*add this*/
       this.datePicker.updateView()
  }
th3b3s1 commented 4 years ago

Thanks for the anwswer, but i've chenged to this module ng-bootstrap and is working perfectly.

Joelius300 commented 4 years ago

@kirega Thank you for the suggestion but unfortunately that doesn't solve the issue. It doesn't show the selection even when calling updateView. It's also suboptimal conceptually because the selection should be highlighted and updated before I submit.

Is there any workaround for this or a foreseeable fix? It seems like I'm not the only one having this issue.

akrolasik commented 4 years ago

I have the same issue

masteruser20 commented 4 years ago

same here

djoyrocks commented 4 years ago

I am facing the same issue. Any Update ?

masteruser20 commented 4 years ago

I've fixed(workaround) by adding simple mixin to my app styles. https://github.com/fetrarij/ngx-daterangepicker-material/issues/266

djoyrocks commented 4 years ago

I've fixed(workaround) by adding simple mixin to my app styles. #266

Thanks, It's Working Fine

Joelius300 commented 4 years ago

Seems to work, thank you. It still seems to have an issue because the start-date's corners aren't rounded (with pink-bluegray) but for now that's good enough :)

fetrarij commented 4 years ago

@Joelius300 I'm sorry this is not a bug, with inline picker we dont use ngModel, just use startDate and endDate

[startDate]="selected?.startDate"
 [endDate]="selected?.endDate"

take a look at Basic In-line Timepicker Example in https://fetrarij.github.io/ngx-daterangepicker-material/simple @djoyrocks @akrolasik @nimax1998 @kirega @1h3b3s1 you should do the same

nboukeffa commented 4 years ago

Hi @fetrarij,

Except if I'm wrong the props that you're mentioning are not present in the inline picker example, this is confusing and probably why the issue has be opened. Updating the example will help.

Thanks :)

fetrarij commented 4 years ago

@nboukeffa check the link I provided, it's there

Joelius300 commented 4 years ago

@fetrarij Are you sure? The issue also reproduces without using ngModel like so:
(also why did you even think I used ngModel? I didn't use it in my repro)

picker.component.html

<ngx-daterangepicker-material (chosenDate)="chosenDate($event)"></ngx-daterangepicker-material>
<div>Chosen date: {{ inlineDate | json }}</div>

picker.component.ts

import { Component, ViewChild } from '@angular/core';
import * as moment from 'moment';

@Component({
  selector: 'app-picker',
  templateUrl: './picker.component.html',
  styleUrls: ['./picker.component.css']
})
export class PickerComponent {
  inlineDate: { chosenLabel: string; startDate: moment.Moment; endDate: moment.Moment };

  chosenDate(chosenDate: { chosenLabel: string; startDate: moment.Moment; endDate: moment.Moment }): void {
      this.inlineDate = chosenDate;
  }
}

Also it's not related to inline at all. You can also reproduce it like this:

<mat-form-field>
  <input
      type="text" <-- this line isn't documented but without it it doesn't work correctly (no styling and date isn't displayed)
      matInput
      ngxDaterangepickerMd
      showCancel="true"
      placeholder="Choose date"
      [(ngModel)]="selected"
      [showDropdowns]="true"
      [lockStartDate]="false"
      [customRangeDirection]="false"
      (ngModelChange)="ngModelChange($event)"
      (change)="change($event)"
  />
</mat-form-field>
import { Component } from '@angular/core';
import * as moment from 'moment';

@Component({
  selector: 'app-picker',
  templateUrl: './picker.component.html',
  styleUrls: ['./picker.component.css']
})
export class PickerComponent {
  selected = {
    startDate: moment('2015-11-18T00:00Z'),
    endDate: moment('2015-11-26T00:00Z'),
  };

  ngModelChange(e): void {
    console.log(e);
  }

  change(e): void {
      console.log(e);
  }
}

The code is taken from the link you posted (your demo page).

I'm almost certain this has to be a styling bug in regard to the pre-built styles because the here mentioned workaround fixes the issue. However, it's not documented anywhere and I believe a lot of people (especially beginners who have trouble helping themselfs with angular) use angular material with pre-built themes.

Could you please investigate this again?

Ps. Cannot reopen because I didn't close it myself.

fetrarij commented 4 years ago

v3.0.2 is up. From there, if you install the plugin with ng add ngx-daterangepicker-material you will be prompted with a theme selector, then the theme you selected will be added in angular.json (styles). If you added the plugin manually just includes your preferred theme in node_modules/ngx-daterangepicker-material/prebuilt-themes/

Joelius300 commented 4 years ago

Just a note because someone else might trip on this: You need both styles in the styles array, otherwise it's completely messed up.

When installing I got

"styles": [
    "./node_modules/ngx-daterangepicker-material/prebuilt-themes/pink-bluegrey.css",
    "src/styles.scss"
],

but you need

"styles": [
    "./node_modules/ngx-daterangepicker-material/prebuilt-themes/pink-bluegrey.css",
    "./node_modules/@angular/material/prebuilt-themes/pink-bluegrey.css",
    "src/styles.scss"
],