Skip to content

Commit

Permalink
Merge pull request #262 from scottbenton/fix/a11y-testing
Browse files Browse the repository at this point in the history
feat(home page): addressed a11y violations on the home page
  • Loading branch information
scottbenton authored Oct 29, 2023
2 parents 9dcb023 + 7a290bf commit 06a4cfb
Show file tree
Hide file tree
Showing 37 changed files with 548 additions and 73 deletions.
3 changes: 3 additions & 0 deletions src/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useListenToCampaigns } from "stores/campaign/useListenToCampaigns";
import { useListenToAuth } from "stores/auth/useListenToAuth";
import { useListenToWorlds } from "stores/world/useListenToWorlds";
import { useListenToOracleSettings } from "stores/settings/useListenToOracleSettings";
import { useListenToAccessibilitySettings } from "stores/accessibilitySettings/useListenToAccessibilitySettings";

const router = createBrowserRouter(
createRoutesFromElements(
Expand Down Expand Up @@ -108,6 +109,8 @@ const router = createBrowserRouter(
export function Router() {
useListenToAuth();

useListenToAccessibilitySettings();

useListenToCharacters();
useListenToCampaigns();
useListenToWorlds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
doc,
DocumentReference,
} from "firebase/firestore";
import { OracleSettings } from "types/UserSettings.type";
import { OracleSettings } from "types/UserOracleSettings.type";

export function constructUserSettingsCollectionPath(userId: string) {
return `/users/${userId}/settings`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { onSnapshot, setDoc } from "firebase/firestore";
import { decodeDataswornId } from "functions/dataswornIdEncoder";
import { OracleSettings } from "types/UserSettings.type";
import { OracleSettings } from "types/UserOracleSettings.type";
import { getUserOracleSettingsDoc } from "./_getRef";

export function listenToOracleSettings(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { arrayRemove, arrayUnion, setDoc, updateDoc } from "firebase/firestore";
import { setDoc, updateDoc } from "firebase/firestore";
import { getCampaignSettingsDoc, getCharacterSettingsDoc } from "./_getRef";
import { createApiFunction } from "api-calls/createApiFunction";
import { SettingsDoc } from "types/Settings.type";
Expand Down
30 changes: 30 additions & 0 deletions src/api-calls/user/settings/_getRef.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { firestore } from "config/firebase.config";
import {
CollectionReference,
DocumentReference,
collection,
doc,
} from "firebase/firestore";
import { IAccessibilitySettings } from "types/UserAccessibilitySettings.type";

export function constructUserSettingsCollectionPath(userId: string) {
return `/users/${userId}/settings`;
}

export function constructUserAccessibilitySettingsDocPath(userId: string) {
return `/users/${userId}/settings/accessibility`;
}

export function getUserSettingsCollectionRef(userId: string) {
return collection(
firestore,
constructUserSettingsCollectionPath(userId)
) as CollectionReference<any>;
}

export function getUserAccessibilitySettingsDoc(userId: string) {
return doc(
firestore,
constructUserAccessibilitySettingsDocPath(userId)
) as DocumentReference<IAccessibilitySettings>;
}
12 changes: 12 additions & 0 deletions src/api-calls/user/settings/listenToAccessibilitySettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { onSnapshot } from "firebase/firestore";
import { IAccessibilitySettings } from "types/UserAccessibilitySettings.type";
import { getUserAccessibilitySettingsDoc } from "./_getRef";

export const listenToAccessibilitySettings = (
uid: string,
onSettings: (settings: IAccessibilitySettings) => void
) => {
return onSnapshot(getUserAccessibilitySettingsDoc(uid), (snapshot) => {
onSettings(snapshot.data() ?? {});
});
};
14 changes: 14 additions & 0 deletions src/api-calls/user/settings/updateAccessibilitySettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ApiFunction } from "api-calls/createApiFunction";
import { setDoc, updateDoc } from "firebase/firestore";
import { IAccessibilitySettings } from "types/UserAccessibilitySettings.type";
import { getUserAccessibilitySettingsDoc } from "./_getRef";

export const updateAccessibilitySettings: ApiFunction<
{ uid: string; settings: Partial<IAccessibilitySettings> },
void
> = (params) => {
const { uid, settings } = params;
return setDoc(getUserAccessibilitySettingsDoc(uid), settings, {
merge: true,
});
};
21 changes: 19 additions & 2 deletions src/components/features/ProgressTrack/ProgressTrack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Stack,
Typography,
} from "@mui/material";
import { useEffect, useState } from "react";
import { useEffect, useId, useState } from "react";
import { ProgressTrackTick } from "./ProgressTrackTick";
import MinusIcon from "@mui/icons-material/Remove";
import PlusIcon from "@mui/icons-material/Add";
Expand Down Expand Up @@ -160,12 +160,15 @@ export function ProgressTrack(props: ProgressTracksProps) {
setChecks(checks);
}, [max, value]);

const labelId = useId();

return (
<Box>
<Box>
{difficulty && !hideDifficultyLabel && (
<Typography
variant={"subtitle1"}
component={"p"}
color={(theme) => theme.palette.text.secondary}
fontFamily={(theme) => theme.fontFamilyTitle}
>
Expand All @@ -175,6 +178,8 @@ export function ProgressTrack(props: ProgressTracksProps) {
{(label || onEdit) && (
<Typography
variant={"h6"}
component={"p"}
id={labelId}
color={(theme) => theme.palette.text.primary}
fontFamily={(theme) => theme.fontFamilyTitle}
>
Expand All @@ -194,6 +199,7 @@ export function ProgressTrack(props: ProgressTracksProps) {
{description && (
<Typography
variant={"subtitle1"}
component={"p"}
color={(theme) => theme.palette.text.secondary}
whiteSpace={"pre-wrap"}
>
Expand All @@ -204,12 +210,14 @@ export function ProgressTrack(props: ProgressTracksProps) {
<Box display={"flex"} mt={label ? 1 : 0}>
{onValueChange && (
<ButtonBase
aria-label={"Decrement Track"}
onClick={() =>
onValueChange &&
onValueChange(
value > 0 ? value - getDifficultyStep(difficulty) : 0
)
}
focusRipple
sx={(theme) => ({
backgroundColor:
theme.palette.darkGrey[
Expand Down Expand Up @@ -238,6 +246,14 @@ export function ProgressTrack(props: ProgressTracksProps) {
borderTop={1}
borderBottom={1}
borderColor={(theme) => theme.palette.divider}
role={"progressbar"}
aria-labelledby={labelId}
aria-valuemin={0}
aria-valuemax={max}
aria-valuenow={value}
aria-valuetext={`${value} (${Math.floor(
value / 4
)} boxes fully filled)`}
>
{checks.map((value, index) => (
<Box
Expand All @@ -250,12 +266,13 @@ export function ProgressTrack(props: ProgressTracksProps) {
index !== 0 ? theme.palette.divider : undefined,
})}
>
<ProgressTrackTick value={value} key={index} />
<ProgressTrackTick value={value} key={index} aria-hidden />
</Box>
))}
</Box>
{onValueChange && (
<ButtonBase
aria-label={"Increment Track"}
onClick={() =>
onValueChange(
value < max ? value + getDifficultyStep(difficulty) : max
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const tickProps = (sizeValue: number) => ({
height: sizeValue,
strokeWidth: 4,
style: { stroke: "currentcolor" },
"aria-hidden": true,
});

export function ProgressTrackTick(props: ProgressTrackTickProps) {
Expand Down
7 changes: 6 additions & 1 deletion src/components/features/Track.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
SxProps,
Theme,
} from "@mui/material";
import { useEffect, useState } from "react";
import { useEffect, useId, useState } from "react";

export interface TrackProps {
label?: string;
Expand Down Expand Up @@ -49,6 +49,8 @@ export function Track(props: TrackProps) {
setNumbers(getArr(min, max));
}, [min, max]);

const labelId = useId();

return (
<Box sx={sx} display={"flex"} overflow={"auto"}>
{label && (
Expand All @@ -75,12 +77,15 @@ export function Track(props: TrackProps) {
<Typography
fontFamily={(theme) => theme.fontFamilyTitle}
variant={"subtitle1"}
id={labelId}
component={"p"}
>
{label}
</Typography>
</Box>
)}
<ToggleButtonGroup
aria-labelledby={labelId}
exclusive
disabled={disabled || loading}
value={value}
Expand Down
13 changes: 9 additions & 4 deletions src/components/features/characters/StatComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function StatComponent(props: StatComponentProps) {
["background-color", "border-color", "outline-width"],
{ duration: theme.transitions.duration.shorter }
),
"&>h6#track-label": {
"&>[id$='-label']": {
transition: theme.transitions.create(
["background-color", "color"],
{ duration: theme.transitions.duration.shorter }
Expand All @@ -82,7 +82,7 @@ export function StatComponent(props: StatComponentProps) {
updateTrack || disableRoll
? {}
: {
"&>h6#track-label": {
"&>[id$='-label']": {
backgroundColor: theme.palette.background.paperInlayDarker,
color: theme.palette.text.primary,
},
Expand Down Expand Up @@ -114,8 +114,9 @@ export function StatComponent(props: StatComponentProps) {
display={"block"}
textAlign={"center"}
variant={"subtitle1"}
component={"span"}
lineHeight={1}
id={"track-label"}
id={`${label}-label`}
>
{label}
{hasAdds && label !== "Adds" && "*"}
Expand All @@ -134,6 +135,7 @@ export function StatComponent(props: StatComponentProps) {
updateTrack ? { lineHeight: "1.5rem" } : {},
]}
variant={"h6"}
component={"span"}
textAlign={"center"}
>
<Typography component={"span"} variant={"body1"} mr={0.2}>
Expand All @@ -154,7 +156,10 @@ export function StatComponent(props: StatComponentProps) {
}}
type={"number"}
size={"small"}
inputProps={{ inputMode: "numeric" }}
inputProps={{
inputMode: "numeric",
"aria-labelledby": `${label}-label`,
}}
onFocus={() => setIsInputFocused(true)}
onBlur={() => setIsInputFocused(false)}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {
Box,
Button,
Checkbox,
Dialog,
DialogActions,
DialogContent,
FormControlLabel,
} from "@mui/material";
import { DialogTitleWithCloseButton } from "../DialogTitleWithCloseButton";
import { useStore } from "stores/store";

export interface AccessibilitySettingsDialogProps {
open?: boolean;
onClose: () => void;
}

export function AccessibilitySettingsDialog(
props: AccessibilitySettingsDialogProps
) {
const { open, onClose } = props;

const accessibilitySettings = useStore(
(store) => store.accessibilitySettings.settings
);

const updateSettings = useStore(
(store) => store.accessibilitySettings.updateSettings
);

return (
<Dialog open={open ?? false} onClose={onClose}>
<DialogTitleWithCloseButton onClose={onClose}>
Accessibility Settings
</DialogTitleWithCloseButton>
<DialogContent>
<Box sx={{ pt: 1 }}>
<FormControlLabel
control={
<Checkbox
checked={accessibilitySettings.verboseRollResults ?? false}
onChange={(evt, value) =>
updateSettings({ verboseRollResults: value }).catch(() => {})
}
/>
}
label={"Announce rolls and modifiers when rolling?"}
sx={{ textTransform: "capitalize", marginRight: 3 }}
/>
</Box>
</DialogContent>
<DialogActions>
<Button variant={"contained"} onClick={onClose}>
Done
</Button>
</DialogActions>
</Dialog>
);
}
Loading

0 comments on commit 06a4cfb

Please sign in to comment.