Skip to content

Commit

Permalink
A11y/fix scheduler month buttons (#1797)
Browse files Browse the repository at this point in the history
* fix(scheduler): disable month buttons when not in allowable range

* chore: regen js

* chore: formatting
  • Loading branch information
andrewleith authored Apr 12, 2024
1 parent 3a1c40f commit e8d577c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/scheduler.min.js

Large diffs are not rendered by default.

31 changes: 24 additions & 7 deletions app/assets/javascripts/scheduler/Calendar/YearMonth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,39 @@ import React, { useContext } from "react";
import { store, I18nContext } from "./index";
import dayjs from "dayjs";

const prevNav = (date, firstAvailableDate) => {
const prevMonthEnabled = (date, firstAvailableDate) => {
const prevMonth = dayjs(date).subtract(1, "month").format("YYYY-MM-DD");

if (dayjs(prevMonth).isBefore(firstAvailableDate, "month")) {
return ["Calendar-nav--button--unavailable"];
return false;
}

return [];
return true;
};

const nextNav = (date, lastAvailableDate) => {
const prevNav = (date, firstAvailableDate) => {
if (prevMonthEnabled(date, firstAvailableDate)) {
return [];
}

return ["Calendar-nav--button--unavailable"];
};

const nextMonthEnabled = (date, lastAvailableDate) => {
const nextMonth = dayjs(date).add(1, "month").date(1).format("YYYY-MM-DD");

if (dayjs(nextMonth).isAfter(lastAvailableDate)) {
return ["Calendar-nav--button--unavailable"];
return false;
}

return true;
};

const nextNav = (date, lastAvailableDate) => {
if (nextMonthEnabled(date, lastAvailableDate)) {
return [];
}

return [];
return ["Calendar-nav--button--unavailable"];
};

export const YearMonth = () => {
Expand All @@ -44,6 +59,7 @@ export const YearMonth = () => {
payload: "previous",
});
}}
disabled={prevMonthEnabled(date, firstAvailableDate) ? false : true}
>
❮
</button>
Expand All @@ -62,6 +78,7 @@ export const YearMonth = () => {
payload: "next",
});
}}
disabled={nextMonthEnabled(date, lastAvailableDate) ? false : true}
>
&#10095;
</button>
Expand Down

0 comments on commit e8d577c

Please sign in to comment.