Skip to content

Commit

Permalink
add a firefox fallback to display the keyboard shortcut as part of th…
Browse files Browse the repository at this point in the history
…e aria-label, since aria-keyshortcuts don't work in Firefox right now
  • Loading branch information
Timtam committed Sep 20, 2024
1 parent 60b9013 commit 04283d6
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
7 changes: 7 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"boolify-string": "^2.0.2",
"bootstrap": "^5.3.3",
"deepcopy": "^2.1.0",
"detect-browser": "^5.3.0",
"howler": "^2.2.4",
"i18next": "^23.10.1",
"i18next-browser-languagedetector": "^7.2.1",
Expand Down
8 changes: 8 additions & 0 deletions client/src/pages/game.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import EventManager from "@lomray/event-manager"
import { bindKeyCombo, unbindKeyCombo } from "@rwh/keystrokes"
import deepcopy from "deepcopy"
import { detect } from "detect-browser"
import { useEffect, useMemo } from "react"
import Button from "react-bootstrap/Button"
import ButtonGroup from "react-bootstrap/ButtonGroup"
Expand Down Expand Up @@ -364,6 +365,13 @@ export function Game() {
: t("startGameShortcut")
: ""
}
aria-label={
detect()?.name === "firefox" && canStartOrStopGame()
? game.state !== GameState.Open
? `${t("stopGameShortcut")} ${t("stopGame")}`
: `${t("startGameShortcut")} ${t("startGame")}`
: ""
}
>
{canStartOrStopGame()
? game.state !== GameState.Open
Expand Down
19 changes: 19 additions & 0 deletions client/src/pages/game/slot-selector.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import EventManager from "@lomray/event-manager"
import { bindKeyCombo, unbindKeyCombo } from "@rwh/keystrokes"
import { detect } from "detect-browser"
import { useEffect, useState } from "react"
import Button from "react-bootstrap/Button"
import ToggleButton from "react-bootstrap/ToggleButton"
Expand Down Expand Up @@ -380,13 +381,23 @@ export default ({ game }: { game: Game }) => {
className="me-2"
onClick={async () => await confirm(false)}
aria-keyshortcuts={t("noShortcut")}
aria-label={
detect()?.name === "firefox"
? `${t("noShortcut")} ${t("no")}`
: ""
}
>
{t("no")}
</Button>
<Button
className="me-2"
onClick={async () => await confirm(true)}
aria-keyshortcuts={t("yesShortcut")}
aria-label={
detect()?.name === "firefox"
? `${t("yesShortcut")} ${t("yes")}`
: ""
}
>
{t("yes")}
</Button>
Expand Down Expand Up @@ -531,6 +542,14 @@ export default ({ game }: { game: Game }) => {
? t("submitGuessShortcut")
: ""
}
aria-label={
detect()?.name === "firefox" &&
((actionRequired() === PlayerState.Guessing &&
selectedSlot !== "0") ||
actionRequired() === PlayerState.Intercepting)
? `${t("submitGuessShortcut")} ${t("submitGuess")}`
: ""
}
>
{actionRequired() === PlayerState.Guessing ||
actionRequired() === PlayerState.Intercepting
Expand Down
16 changes: 16 additions & 0 deletions client/src/pages/lobby.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import EventManager from "@lomray/event-manager"
import { bindKeyCombo, unbindKeyCombo } from "@rwh/keystrokes"
import { detect } from "detect-browser"
import { useEffect, useMemo } from "react"
import Dropdown from "react-bootstrap/Dropdown"
import Table from "react-bootstrap/Table"
Expand Down Expand Up @@ -75,18 +76,33 @@ export function Lobby() {
<Dropdown.Item
onClick={() => createGame(GameMode.Public)}
aria-keyshortcuts={t("publicGameShortcut")}
aria-label={
detect()?.name === "firefox"
? `${t("publicGameShortcut")} ${t("publicGame")}`
: ""
}
>
{t("publicGame")}
</Dropdown.Item>
<Dropdown.Item
onClick={() => createGame(GameMode.Private)}
aria-keyshortcuts={t("privateGameShortcut")}
aria-label={
detect()?.name === "firefox"
? `${t("privateGameShortcut")} ${t("privateGame")}`
: ""
}
>
{t("privateGame")}
</Dropdown.Item>
<Dropdown.Item
onClick={() => createGame(GameMode.Local)}
aria-keyshortcuts={t("localGameShortcut")}
aria-label={
detect()?.name === "firefox"
? `${t("localGameShortcut")} ${t("localGame")}`
: ""
}
>
{t("localGame")}
</Dropdown.Item>
Expand Down

0 comments on commit 04283d6

Please sign in to comment.