31

Material example for customizing-the-parse-and-display-formats for date picker uses custom MAT_DATE_FORMATS

export const MY_FORMATS = {
  parse: {
    dateInput: 'LL',
  },
  display: {
    dateInput: 'LL',
    monthYearLabel: 'MMM YYYY',
    dateA11yLabel: 'LL',
    monthYearA11yLabel: 'MMMM YYYY',
  },
};

I could not find where and how these fields like dateA11yLabel will come into play. What I could figure out was display.dateInput is used in displaying selected date on calendar and display.monthYearLabel is used in the select drop-down of year selector.

  1. Where are rest of the fields used?
  2. When writing custom MAT_DATE_FORMATS is it mandatory to define all fields?
laike9m
  • 18,344
  • 20
  • 107
  • 140
Abhishek Jha
  • 935
  • 2
  • 10
  • 22

2 Answers2

33

Well, I figured out the following:

datepicker

 parse: {

    dateInput: 'DD.MM.YYYY',
  }, 
  display: {

    dateInput: 'DD.MM.YYYY',
    monthYearLabel: 'MMM YYYY',
    dateA11yLabel: 'LL',
    monthYearA11yLabel: 'MMMM-YYYY',
  },
  • with parse.dateInput: you can let the user enter any type of date with any format, and the date adapter will reformat it to the format you specify in this attribute

  • with display.dateInput you can specify the input date format (marked with 1)

  • display.monthYearLabel you can specify the area marked with 2

unfortunately, I still don't know about the rest!

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Mo Hamid
  • 471
  • 5
  • 9
5

A11Y - means accessibility. Look here https://material.angular.io/cdk/a11y/overview and here https://material.angular.io/components/datepicker/overview#accessibility

According that I think these formats are used to display datepicker when accessibility mode on.

Community
  • 1
  • 1
Dmytro Bardai
  • 154
  • 1
  • 7