Skip to content

Commit

Permalink
docs(material/datepicker): Update close calendar label (#26738)
Browse files Browse the repository at this point in the history
Previously, the close calendar label was not updating correctly when switching languages. This commit fixes that issue.

Fixes: #25021
(cherry picked from commit ff27a93)
  • Loading branch information
hamzajazyri authored and crisbeto committed Nov 9, 2023
1 parent 4bcbc84 commit 4ee928a
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, Inject} from '@angular/core';
import {Component, Inject, OnInit} from '@angular/core';
import {
MAT_MOMENT_DATE_FORMATS,
MomentDateAdapter,
Expand All @@ -11,6 +11,7 @@ import {MatInputModule} from '@angular/material/input';
import {MatFormFieldModule} from '@angular/material/form-field';
import 'moment/locale/ja';
import 'moment/locale/fr';
import {MatDatepickerIntl} from '@angular/material/datepicker';

/** @title Datepicker with different locale */
@Component({
Expand All @@ -34,15 +35,26 @@ import 'moment/locale/fr';
standalone: true,
imports: [MatFormFieldModule, MatInputModule, MatDatepickerModule, MatButtonModule],
})
export class DatepickerLocaleExample {
export class DatepickerLocaleExample implements OnInit {
constructor(
private _adapter: DateAdapter<any>,
private _intl: MatDatepickerIntl,
@Inject(MAT_DATE_LOCALE) private _locale: string,
) {}

ngOnInit() {
this.updateCloseButtonLabel('カレンダーを閉じる');
}

french() {
this._locale = 'fr';
this._adapter.setLocale(this._locale);
this.updateCloseButtonLabel('Fermer le calendrier');
}

updateCloseButtonLabel(label: string) {
this._intl.closeCalendarLabel = label;
this._intl.changes.next();
}

getDateFormatString(): string {
Expand Down

0 comments on commit 4ee928a

Please sign in to comment.