Coder Social home page Coder Social logo

kuhnroyal / mat-datetimepicker Goto Github PK

View Code? Open in Web Editor NEW
148.0 7.0 84.0 12.94 MB

Material datetimepicker for @angular/material

License: MIT License

TypeScript 77.11% JavaScript 2.37% HTML 12.26% SCSS 8.16% Shell 0.10%
angular angular-material5 angular-material typescript material-datetimepicker material datetimepicker material-datepicker

mat-datetimepicker's Introduction

Material Datetimepicker for @angular/material

The example application is on GitHub Pages!

Build Latest Stable Version License NPM Downloads


The datetimepicker was initially taken from Promact/md2 and modified to use @angular/material. We have also added theming support.

Like the @angular/material datepicker it contains a native-datetime-adapter as well as a moment-datetime-adapter .

Contents

Usage

Installation

Install:

npm install --save @mat-datetimepicker/core

And for the moment adapter:

npm install --save @angular/material-moment-adapter mat-datetimepicker/moment

Setup

Basically the same way the @angular/material datepicker is configured and imported.

imports: [
  ...MatDatepickerModule,
  // use this if you want to use native javascript dates and INTL API if available
  // MatNativeDatetimeModule,
  MatMomentDatetimeModule,
  MatDatetimepickerModule,
];

@see src/app/app.module.ts

Using the component

<form [formGroup]="group">
  <mat-form-field>
    <mat-placeholder>Start DateTime</mat-placeholder>
    <mat-datetimepicker-toggle [for]="datetimePicker" matSuffix></mat-datetimepicker-toggle>
    <mat-datetimepicker #datetimePicker type="datetime" openOnFocus="true" timeInterval="5"> </mat-datetimepicker>
    <input matInput formControlName="start" [matDatetimepicker]="datetimePicker" required autocomplete="false" />
  </mat-form-field>
</form>

Date formatting

In order to change the default input/output formats, a custom instance of MAT_DATETIME_FORMATS needs to be provided in the global configuration.

Input/output formats can be changed separately for the existing datetime picker types date, month , datetimeand time.

Accessibility

You can use the following properties to provide values for ARIA- attributes:

Property Description Default
ariaNextMonthLabel aria-label for the Next button in the month mode "Next month"
ariaPrevMonthLabel aria-label for the Previous button in the month mode "Previous month"
ariaNextYearLabel aria-label for the Next button in the year mode "Next year"
ariaPrevYearLabel aria-label for the Previous button in the year mode "Previous year"

The component supports property bindings or pipes with the aria- values.

Native

Parsing does not work with the native adapter because the Intl.DateTimeFormat API does not provide that feature.

providers: [
  {
    provide: MAT_DATETIME_FORMATS,
    useValue: {
      parse: {},
      display: {
        dateInput: {
          year: 'numeric',
          month: '2-digit',
          day: '2-digit',
        },
        monthInput: {
          month: 'long',
        },
        datetimeInput: {
          year: 'numeric',
          month: '2-digit',
          day: '2-digit',
          hour: '2-digit',
          minute: '2-digit',
        },
        timeInput: {
          hour: '2-digit',
          minute: '2-digit',
        },
        monthYearLabel: {
          year: 'numeric',
          month: 'short',
        },
        dateA11yLabel: {
          year: 'numeric',
          month: 'long',
          day: 'numeric',
        },
        monthYearA11yLabel: {
          year: 'numeric',
          month: 'long',
        },
        popupHeaderDateLabel: {
          weekday: 'short',
          month: 'short',
          day: '2-digit',
        },
      },
    },
  },
];

@see defaults in native-datetime-formats.ts
@see Intl.DateTimeFormat API documentation

Moment

providers: [
  {
    provide: MAT_DATETIME_FORMATS,
    useValue: {
      parse: {
        dateInput: 'L',
        monthInput: 'MMMM',
        timeInput: 'LT',
        datetimeInput: 'L LT',
      },
      display: {
        dateInput: 'L',
        monthInput: 'MMMM',
        datetimeInput: 'L LT',
        timeInput: 'LT',
        monthYearLabel: 'MMM YYYY',
        dateA11yLabel: 'LL',
        monthYearA11yLabel: 'MMMM YYYY',
        popupHeaderDateLabel: 'ddd, DD MMM',
      },
    },
  },
];

@see defaults in moment-datetime-formats.ts
@see moment.js documentation

Theming

@import '@mat-datetimepicker/core/datetimepicker/datetimepicker-theme.scss';

// Using the $theme variable from the pre-built theme you can call the theming function
@include mat-datetimepicker-theme($theme);

@see src/styles.scss

Development

Run npm install in order to install all required dependencies and initialize the Git hooks. Further instructions are available in the DEVELOPMENT.md.

Make sure you read at least the "Committing" section before committing anything.

mat-datetimepicker's People

Contributors

alexis-landrieu-avanade avatar alfaproject avatar bbortt avatar benjaminflopez21 avatar benoitbzl avatar denysvuika avatar dependabot[bot] avatar eugeno avatar gsontag avatar guilherfp avatar guschnwg avatar ivokh avatar kuhnroyal avatar naaajii avatar samuelmarks avatar schlosserma avatar semantic-release-bot avatar shadowjustice avatar shanelillierad avatar torstenl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mat-datetimepicker's Issues

No theming

When I add the package without theming, I can not see any of the selected items on the left side of the panel, all the texts are set color: white. When I try to add the SCSS file, in an app without custom theming, an error is thrown during build time. (I'm currently using a pre-built theme from Angular material)

Could the SCSS file be created without a call to theming, or default texts to black?

screen shot 2018-01-15 at 14 20 26

No option to put date ?

Thanks for great lib,
Is there any way to put pre-defined date?
dueDate is not empty value and but it always show empty.

<mat-datetimepicker-toggle [for]="datetimePicker" matSuffix></mat-datetimepicker-toggle> <mat-datetimepicker #datetimePicker type="datetime" openOnFocus="true" timeInterval="5"></mat-datetimepicker> <input matInput formControlName="dueDate" [matDatetimepicker]="datetimePicker" required autocomplete="false" placeholder="Due Date">

Min max validation

While writing the value into the associated text input, min / max validation does not take into account the time component.

No option to input seconds

I have not found any material design datetimepicker which allows to input seconds as well. Will it be possible to add this functionality?

Also, is there an online demo for this component I can try?

Time in UTC

I would like to use time in UTC but I didn't find this functionality.

Could you add such possibility, please?

view change event

Great job @kuhnroyal !!
Please, is there any way how to get some change event while the View "clock" | "month" | "year" switched by user?
It would be probably good for the date filtering. Now it is so that the year and month views trigger the time with the current hours and minutes. Which is, for sure, absolutely right, but what about the case I need to filter date only on the clock view?

Material Datetimepicker for @angular/material 6.x

I'm using Angular 6.1.0 & Angular material 6.4.6 and I've imported MatDatepickerModule,MatDatetimepickerModule and MatMomentDatetimeModule in app.module.ts file

But I get this error message
ERROR Error: Uncaught (in promise): TypeError: _super.prototype.createDate.call(...).format is not a function
TypeError: _super.prototype.createDate.call(...).format is not a function
at mat-datetimepicker-moment.js:52
at range (mat-datetimepicker-moment.js:24)
at MomentDatetimeAdapter.push../node_modules/@mat-datetimepicker/moment/fesm5/mat-datetimepicker-moment.js.MomentDatetimeAdapter.setLocale (mat-datetimepicker-moment.js:52)
at new MomentDatetimeAdapter (mat-datetimepicker-moment.js:32)
at createClass (core.js:8424)
at createProviderInstance (core.js:8394)
at resolveNgModuleDep (core.js:8357)
at NgModuleRef
.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef
.get (core.js:9065)
at resolveDep (core.js:9430)
at createClass (core.js:9310)
at mat-datetimepicker-moment.js:52
at range (mat-datetimepicker-moment.js:24)
at MomentDatetimeAdapter.push../node_modules/@mat-datetimepicker/moment/fesm5/mat-datetimepicker-moment.js.MomentDatetimeAdapter.setLocale (mat-datetimepicker-moment.js:52)
at new MomentDatetimeAdapter (mat-datetimepicker-moment.js:32)
at createClass (core.js:8424)
at createProviderInstance (core.js:8394)
at resolveNgModuleDep (core.js:8357)
at NgModuleRef
.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef
.get (core.js:9065)
at resolveDep (core.js:9430)
at createClass (core.js:9310)
at resolvePromise (zone.js:814)
at resolvePromise (zone.js:771)
at zone.js:873
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:3816)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
at drainMicroTaskQueue (zone.js:595)
at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:500)
at invokeTask (zone.js:1540)
So What's wrong?

Placeholder broken when ChangeDetection is used

When change detection is set to OnPush inside the component showing the datetimepicker, and a value is filled (prefilled or selected from the calendar), the placeholder does not move up like the normal material inputs. You can see this behaviour by running the demo and setting the chagnedetection on 1 of the components (native or moment).
image
After the field is clicked, the placeholder moves up and all is fine.

Angular 6

Hi,

Do you have any plans on updating this to angular 6?
I'm able to use this in my angular 6 project with rxjs-compat, but would be nice to skip that package.

Thanks

can't find it on Yarn

Hello!

I am very interested in this component, looks really interesting, but I can't find it on Yarn as the Readme file specifies... is there any other way I can import this component in my project?

Midnight label issue

According to the official Android timepicker, the hour label for displaying midnight should be 00.
It's currently 12, this can be disturbing for users to find out which hour to select, as noon and midnight are displayed with the same value.

Invalid input when manual modification with specific localization

Hello,

I'm using a specific localization for my datetime picker, the display is correct and if I'm using the picker it works well. However, if I'm trying to modify directly the date, the input is invalid while the date entered is correct in its localization format.

App.component.ts

import {Component, OnInit} from '@angular/core';
import {FormControl, FormGroup} from '@angular/forms';
import {DateAdapter, NativeDateAdapter} from '@angular/material';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  form: FormGroup;
  constructor(private adapter: DateAdapter<NativeDateAdapter>) {
    this.adapter.setLocale('fr-FR');
  }

  ngOnInit() {
    this.form = new FormGroup({
      start: new FormControl(new Date())
    });
  }
}

App.component.html

<form [formGroup]="form">
  <mat-form-field>
    <mat-placeholder>Start DateTime</mat-placeholder>
    <mat-datetimepicker-toggle [for]="datetimePicker" matSuffix></mat-datetimepicker-toggle>
    <mat-datetimepicker #datetimePicker type="datetime" openOnFocus="true" timeInterval="5"></mat-datetimepicker>
    <input matInput formControlName="start" [matDatetimepicker]="datetimePicker" required autocomplete="false">
  </mat-form-field>
</form>

App.module.ts

  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    MatDatepickerModule,
    FormsModule,
    MatInputModule,
    ReactiveFormsModule,
    // use this if you want to use native javascript dates and INTL API if available
    // MatNativeDatetimeModule,
    MatNativeDatetimeModule,
    MatDatetimepickerModule
  ]

Time & Minutes disabled but able to select it.

When setting [min]="1/11/2018 3:00 AM", the UI shows 1:00 AM and 2:00 AM as disabled on the same date. Even in disabled state, you can click and select times before 3:00 AM even though [min] shows 3:00 AM as minimum time.

Attached is a screen shot.
datetime-picker-bug

Not working in IE11

Hi,

running this in IE11 works, but the dialog cannot be closed anymore, also on selecting a date the popup does not close. Any chance this can be easily fixed?

Thanks!

mat-datetimepicker keep opening

I am using latest version 1.0.2 , I am facing one issue in the ie 11, when click in the text box, instead of clicking on the calendar icon , Calendar popup comes up but after choosing the date popup close and open again, keep happening like this.Can't close totally. Even though I call datetimepicker.close() function, behaviour still the same. When I called datetimepicker.close(), calendar popup close and open back again.Please advise me what to do.It already took 3 hours to fix it but can't.
Thanks.

No way to change date label in header

Would be nice to be able to change the format of the mat-datetimepicker-calendar-header-date with a moment format for example.
I'm using localised formats and the date is kind of 'americanised'.
Thanks

Predefined value for date will not be taken

We have the following html code:

<mat-datetimepicker-toggle [for]="datePicker" [disabled]="isDisabled" matSuffix>
<mat-datetimepicker #datePicker type="date" openOnFocus="true">
<input matInput #dueDate [matDatetimepicker]="datePicker" formControlName="dueDate" [min]="today" [placeholder]="'APP.IDEAS.IDEA_FORM.DUE_DATE.PLACEHOLDER' | translate"/>

In our reactive form, we will set the value like that:

this.formGroup = this.formBuilder.group({
dueDate: [""],
});
const dueDate: Date = new Date(this.idea.due_date);
this.formGroup.get("dueDate").setValue(dueDate.toISOString());

but the input field is empty and the given date isn't used as preselection in the date calendar.

Version 1.0.4

dateFilter does not trigger on a clock view

Hi, thank You for this great job!
I just would like to ask why dateFilter trigger only on a year and month views and not on a clock one? I try to filter also hours per day but without the dateFilter triggering I am not able to figure it out.

Date Format

Hello, there is some possibility of changing the format of the date?

Documentation Request - date formatting in the input and dialog to alter the date format

Thank you for providing the great date/time picker. I've been able to include it in my project and have the basic functionality for it in place. I do have several questions about how to get it to display things in different formats though and don't really understand how to configure the adapters.

In my shared material module I've included the MatMomentDatetimeModule,
MatDatetimepickerModule. I have not yet set any providers to customize the format in this module, though from what I've read, I realize this may be required? I then created a component to wrap the datetimepicker. The component markup is the standard from your examples:

<form [formGroup]="group">
  <mat-form-field>
    <mat-placeholder>Start Date and Time</mat-placeholder>
    <mat-datetimepicker-toggle
      [for]="datetimePicker"
      matSuffix></mat-datetimepicker-toggle>
    <mat-datetimepicker
      #datetimePicker
      type="datetime"
      openOnFocus="true"
      timeInterval="5"></mat-datetimepicker>
    <input
      matInput
      formControlName="starttime"
      [matDatetimepicker]="datetimePicker"
      required
      autocomplete="false" />
  </mat-form-field>
</form>

and the .ts file is fairly standard as well:

import { AfterViewInit, Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild } from '@angular/core';
import { InvestigateTrafficRequestModel } from '../../../shared/models/investigate-traffic-request.model';
import { FormControl, FormGroup } from '@angular/forms';
import { Moment } from 'moment';
import * as moment from 'moment';
import { MatDatetimepicker } from '@mat-datetimepicker/core';


@Component({
  selector: 'app-traffic-filter-controls',
  templateUrl: './traffic-filter-controls.component.html',
  styleUrls: ['./traffic-filter-controls.component.css']
})
export class TrafficFilterControlsComponent implements OnInit, OnChanges, AfterViewInit {
  @Input() filterObject: InvestigateTrafficRequestModel = new InvestigateTrafficRequestModel();
  @ViewChild(MatDatetimepicker) datetimePicker: MatDatetimepicker<Moment>;
  public group: FormGroup;
  public isValidMoment = false;

  constructor() {
  }

  ngOnInit() {
    this.group = new FormGroup({
      starttime: new FormControl(moment(this.filterObject.timeRange.start))
    });
  }

  ngOnChanges(changes: SimpleChanges) {
    console.log(changes);

  }

  ngAfterViewInit(){
    this.datetimePicker.selectedChanged.subscribe(
      (newDate: Moment) => {
        this.isValidMoment = moment.isMoment(newDate);
      },
      (error) => {
        throw Error(error);
      }
    );
  }
}

Here are my questions... If I want to customize the way the input displays the selected datetime, what changes would I need to make to have it appear in the same format as the angular date pipe medium format (MMM d, y, h:mm:ss a)?

Similarly, the datetimepicker popup currently displays the time in a 24 hour clock format. If I wanted it to display a 12 hour clock format with AM/PM selectors how would I change my code to make that happen?

Thanks in advance for any suggestions.

Locale change does not seem to work

//class MyService
constructor(protected dateAdapter: DateAdapter<any>, protected datetimeAdapter: DatetimeAdapter<any>) {}

setLocale(locale) {
    this.dateAdapter.setLocale(locale);
    this.datetimeAdapter.setLocale(locale);
}

//later
myService.setLocale("it");
//later still
myService.setLocale("en");

Observed effect: regular Material date picker switches from DD/MM to MM/DD. Date-time picker doesn't. However, in the popup the names of months and days do change.

Working Demo

This plugin seems great - I just wondered if someone had a working demo of this so I can determine at a glance if this is what I need for my next project? Thanks in advance

month format not affected

When I open my datetimepicker and configures it so, that I can only choose the month, the month is not in the format I set.
image

image

Component fails to package with ng-packagr

When testing the component in an Angular 6 library I get the following error when running ng-packagr:

Directive MatDatetimepickerInput, Property '_dateAdapter' is private and only accessible within class 'MatDatetimepickerInput'

I think it might be related to AoT and the use of the property in a directive with host.

Type=time broken since 2.0.1

The initial value of the datetimepicker with type=time shows the date (i.e. '01/01/2000') instead of the time.
When the input is focus and blurred, the correct time value shows again (i.e. '13:37').

The time value was shown correctly with 1.0.4.

Unable to change month when day index is outside bounds

Steps to reproduce:

  1. Choose some date which is last day of month (e.g. 31 days long months - January, March, etc.)
  2. Now try to change the selected month to a month with less days in total (like February).
  3. Error appears due to this line.

image

Expected result:

Month is properly set with no error and user must reselect the day to complete the change.

Can't set value with datetime

When i set the value into my form, the minutes and seconds are not displayed.. Any reason ?

View:
image

Code;
image

Code inline

const startDate = new Date(delegation.StartDate);
const endDate = new Date(delegation.EndDate);
console.log(startDate, endDate);
this.delegationForm.get('startDate').setValue(startDate);
this.delegationForm.get('endDate').setValue(endDate);
this.delegationForm.get('sendEmail').setValue(delegation.SendEmail);
this.delegationForm.get('sendEmailToSignatory').setValue(delegation.SendEmailToSignatory);

Console:
image

mat-datetimepicker format="y-mm-dd HH:MM:ss" setting has no effect

In order to enable the user to enter seconds, "format: 'y-mm-dd HH:MM:ss'" is set on "mat-datetimepicker" , but the setting has no effect.

<mat-form-field style="width: 100%">
    <input matInput [matDatetimepicker]="datetimePicker" name="outTime" [(ngModel)]="form.outTime" autocomplete="false" [max]="curTime"  placeholder="Date time" >
    <mat-datetimepicker-toggle [for]="datetimePicker" matSuffix></mat-datetimepicker-toggle>
    <mat-datetimepicker #datetimePicker type="datetime" openOnFocus="true" timeInterval="1" format="y-mm-dd HH:MM:ss"></mat-datetimepicker>
</mat-form-field>

Min and Max dates not working

    <mat-datetimepicker #datetimePickerEnd type="datetime" [min]='minDate' openOnFocus="true" timeInterval="5" ></mat-datetimepicker>

Min date not working, however it works on md2. How am I able to get this to work?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.