Skip to content
This repository was archived by the owner on Sep 28, 2023. It is now read-only.

Commit

Permalink
fix(datepicker): accessibility correction
Browse files Browse the repository at this point in the history
  • Loading branch information
BehnooshShiva committed May 25, 2020
1 parent 2edb69b commit 0ced78c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/app/demos/datepicker.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
<div class="form-group">
<div class="input-group">
<div class="input-group-append">
<button class="btn btn-outline-secondary icon-calendar-day" (click)="d.toggle()" type="button" id="button-toggle" attr.aria-label="Open Calendar" aria-haspopup="true"></button>
<button class="btn btn-outline-secondary icon-calendar-day" (click)="d.toggle()" type="button" id="button-toggle" aria-label="choose date" aria-haspopup="true">
<span class="sr-only">choose date</span>
</button>
</div>
<input class="form-control calendar-input" placeholder="Une date (jj/mm/aaa)"
name="dp2" [(ngModel)]="model2" ngbDatepicker #d="ngbDatepicker" attr.aria-label='Calendar'>
Expand Down
32 changes: 17 additions & 15 deletions src/app/demos/datepicker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { NgbDatepickerI18n, NgbDateStruct, NgbDate, NgbCalendar } from '@ng-boot

const I18N_VALUES = {
'fr': {
weekdays: ['Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa', 'Di'],
months: ['Jan', 'Fév', 'Mar', 'Avr', 'Mai', 'Juin', 'Juil', 'Aou', 'Sep', 'Oct', 'Nov', 'Déc'],
weekdays: ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche'],
months: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'],
}
// other languages you would support
};
Expand All @@ -19,23 +19,25 @@ const I18N_VALUES = {
// Define custom service providing the months and weekdays translations
@Injectable()
export class CustomDatepickerI18n extends NgbDatepickerI18n {

constructor(private _i18n: I18n) {
constructor(private _i18n: I18n) {
super();
}

public getWeekdayShortName(weekday: number): string {
}
public getWeekdayShortName(weekday: number): string {
return I18N_VALUES[this._i18n.language].weekdays[weekday - 1];
}
public getMonthShortName(month: number): string {
}
public getMonthShortName(month: number): string {
return I18N_VALUES[this._i18n.language].months[month - 1];
}
public getMonthFullName(month: number): string {
}
public getMonthFullName(month: number): string {
return this.getMonthShortName(month);
}
public getDayAriaLabel(date: NgbDateStruct): string {
return `${date.day}-${date.month}-${date.year}`;
}
}
public getDayAriaLabel(date: NgbDateStruct): string {
var newDate = new Date(date.year, date.month - 1, date.day);
var newDay = newDate.getDay();
newDay = newDay === 0 ? 7 : newDay;
const day = this.getWeekdayShortName(newDay);
return day + ' ' + `${date.day}-${date.month}-${date.year}`;
}
}

@Component({
Expand Down

0 comments on commit 0ced78c

Please sign in to comment.