Skip to content

Commit

Permalink
Scheduler a11y: Disabled time ranges are not supported (#28202)
Browse files Browse the repository at this point in the history
  • Loading branch information
tongsonbarbs authored Oct 23, 2024
1 parent 57520af commit 19bd42e
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
dataCellTemplate="dataCellTemplate"
dateCellTemplate="dateCellTemplate"
timeCellTemplate="timeCellTemplate"
(onContentReady)="onContentReady($event)"
(onAppointmentFormOpening)="onAppointmentFormOpening($event)"
(onAppointmentAdding)="onAppointmentAdding($event)"
(onAppointmentUpdating)="onAppointmentUpdating($event)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,34 @@ export class AppComponent {

currentView = this.views[0];

ariaDescription = () => {
const disabledDates = this.holidays
.filter(date => !this.isWeekend(date))
.map(date => new Date(date).toLocaleDateString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
})
);
if (disabledDates?.length === 1) {
return `${disabledDates} is a disabled date`;
}
if (disabledDates?.length > 1) {
return `${disabledDates.join(', ')} are disabled dates`;
}
};

constructor(public dataService: DataService) {
this.dataSource = new DataSource({
store: dataService.getData(),
});
}

onContentReady = (e: DxSchedulerTypes.ContentReadyEvent) => {
this.setComponentAria(e.component?.$element());
};

onOptionChanged = (e: DxSchedulerTypes.OptionChangedEvent) => {
if (e.name === 'currentView') {
this.currentView = e.value;
Expand Down Expand Up @@ -148,6 +170,11 @@ export class AppComponent {
const endDateEditor = form.getEditor('endDate');
endDateEditor.option('disabledDates', holidays);
};

setComponentAria(element): void {
const prevAria = element?.attr('aria-label') || '';
element?.attr('aria-label', `${prevAria} ${this.ariaDescription()}`);
}
}

@NgModule({
Expand Down
27 changes: 27 additions & 0 deletions apps/demos/Demos/Scheduler/CellTemplates/React/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,32 @@ import TimeCell from './TimeCell.tsx';

const currentDate = new Date(2021, 3, 27);
const views: SchedulerTypes.ViewType[] = ['workWeek', 'month'];
const ariaDescription = () => {
const disabledDates = holidays
.filter((date) => !Utils.isWeekend(date))
.map((date) => new Date(date).toLocaleDateString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
})
);
if (disabledDates?.length === 1) {
return `${disabledDates} is a disabled date`;
}
if (disabledDates?.length > 1) {
return `${disabledDates.join(', ')} are disabled dates`;
}
};

const notifyDisableDate = () => {
notify('Cannot create or move an appointment/event to disabled time/date regions.', 'warning', 1000);
};

const onContentReady = (e: SchedulerTypes.ContentReadyEvent) => {
setComponentAria(e.component?.$element());
}

const applyDisableDatesToDateEditors = (form: ReturnType<FormRef['instance']>) => {
const startDateEditor = form.getEditor('startDate');
startDateEditor?.option('disabledDates', holidays);
Expand Down Expand Up @@ -53,6 +74,11 @@ const onAppointmentUpdating = (e: SchedulerTypes.AppointmentUpdatingEvent) => {
}
};

const setComponentAria = (element) => {
const prevAria = element?.attr('aria-label') || '';
element?.attr('aria-label', `${prevAria} ${ariaDescription()}`);
}

const App = () => {
const [currentView, setCurrentView] = useState<SchedulerTypes.ViewType>(views[0]);

Expand Down Expand Up @@ -81,6 +107,7 @@ const App = () => {
dataCellComponent={DataCellComponent}
dateCellRender={renderDateCell}
timeCellComponent={TimeCell}
onContentReady={onContentReady}
onAppointmentFormOpening={onAppointmentFormOpening}
onAppointmentAdding={onAppointmentAdding}
onAppointmentUpdating={onAppointmentUpdating}
Expand Down
25 changes: 25 additions & 0 deletions apps/demos/Demos/Scheduler/CellTemplates/ReactJs/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,33 @@ import TimeCell from './TimeCell.js';

const currentDate = new Date(2021, 3, 27);
const views = ['workWeek', 'month'];
const ariaDescription = () => {
const disabledDates = holidays
.filter((date) => !Utils.isWeekend(date))
.map((date) =>
new Date(date).toLocaleDateString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
}));
if (disabledDates?.length === 1) {
return `${disabledDates} is a disabled date`;
}
if (disabledDates?.length > 1) {
return `${disabledDates.join(', ')} are disabled dates`;
}
};
const notifyDisableDate = () => {
notify(
'Cannot create or move an appointment/event to disabled time/date regions.',
'warning',
1000,
);
};
const onContentReady = (e) => {
setComponentAria(e.component?.$element());
};
const applyDisableDatesToDateEditors = (form) => {
const startDateEditor = form.getEditor('startDate');
startDateEditor?.option('disabledDates', holidays);
Expand Down Expand Up @@ -48,6 +68,10 @@ const onAppointmentUpdating = (e) => {
notifyDisableDate();
}
};
const setComponentAria = (element) => {
const prevAria = element?.attr('aria-label') || '';
element?.attr('aria-label', `${prevAria} ${ariaDescription()}`);
};
const App = () => {
const [currentView, setCurrentView] = useState(views[0]);
const DataCellComponent = useMemo(
Expand Down Expand Up @@ -79,6 +103,7 @@ const App = () => {
dataCellComponent={DataCellComponent}
dateCellRender={renderDateCell}
timeCellComponent={TimeCell}
onContentReady={onContentReady}
onAppointmentFormOpening={onAppointmentFormOpening}
onAppointmentAdding={onAppointmentAdding}
onAppointmentUpdating={onAppointmentUpdating}
Expand Down
28 changes: 28 additions & 0 deletions apps/demos/Demos/Scheduler/CellTemplates/Vue/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
data-cell-template="dataCellTemplate"
date-cell-template="dateCellTemplate"
time-cell-template="timeCellTemplate"
:on-content-ready="onContentReady"
:on-appointment-form-opening="onAppointmentFormOpening"
:on-appointment-adding="onAppointmentAdding"
:on-appointment-updating="onAppointmentUpdating"
Expand Down Expand Up @@ -59,6 +60,28 @@ const dataSource = data;
const isMonthView = computed(() => currentView.value === 'month');
const ariaDescription = computed(() => {
const disabledDates = holidays
.filter((date) => !Utils.isWeekend(date))
.map((date) => new Date(date).toLocaleDateString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
})
);
if (disabledDates?.length === 1) {
return `${disabledDates} is a disabled date`;
}
if (disabledDates?.length > 1) {
return `${disabledDates.join(', ')} are disabled dates`;
}
});
function onContentReady(e: DxSchedulerTypes.ContentReadyEvent) {
setComponentAria(e.component?.$element());
}
function onAppointmentFormOpening(e: DxSchedulerTypes.AppointmentFormOpeningEvent) {
const startDate = new Date(e.appointmentData.startDate);
if (!Utils.isValidAppointmentDate(startDate)) {
Expand Down Expand Up @@ -91,4 +114,9 @@ function applyDisableDatesToDateEditors(form) {
const endDateEditor = form.getEditor('endDate');
endDateEditor.option('disabledDates', holidays);
}
function setComponentAria(element) {
const prevAria = element?.attr('aria-label') || '';
element?.attr('aria-label', `${prevAria} ${ariaDescription.value}`);
}
</script>
26 changes: 26 additions & 0 deletions apps/demos/Demos/Scheduler/CellTemplates/jQuery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ $(() => {
return itemElement.append(element);
},

onContentReady(e) {
setComponentAria(e.component.$element());
},

onAppointmentFormOpening(e) {
const startDate = new Date(e.appointmentData.startDate);
if (!isValidAppointmentDate(startDate)) {
Expand Down Expand Up @@ -87,6 +91,23 @@ const holidays = [
new Date(2021, 3, 29),
new Date(2021, 5, 6),
];
const ariaDescription = () => {
const disabledDates = holidays
.filter(date => !isWeekend(date))
.map(date => new Date(date).toLocaleDateString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
})
);
if (disabledDates?.length === 1) {
return `${disabledDates} is a disabled date`;
}
if (disabledDates?.length > 1) {
return `${disabledDates.join(', ')} are disabled dates`;
}
};

function notifyDisableDate() {
DevExpress.ui.notify('Cannot create or move an appointment/event to disabled time/date regions.', 'warning', 1000);
Expand Down Expand Up @@ -156,3 +177,8 @@ function applyDisableDatesToDateEditors(form) {
const endDateEditor = form.getEditor('endDate');
endDateEditor.option('disabledDates', holidays);
}

function setComponentAria(element) {
const prevAria = element?.attr('aria-label') || '';
element?.attr('aria-label', `${prevAria} ${ariaDescription()}`);
}

0 comments on commit 19bd42e

Please sign in to comment.