diff --git a/src/components/keyboard-shortcut-controls.test.tsx b/src/components/keyboard-shortcut-controls.test.tsx index 0a9b882..f683029 100644 --- a/src/components/keyboard-shortcut-controls.test.tsx +++ b/src/components/keyboard-shortcut-controls.test.tsx @@ -55,7 +55,7 @@ describe("test keyboard shortcut controls component", () => { expect(input).toHaveAttribute("aria-describedby", "custom-keyboard-shortcut-confirmation"); expect(screen.getByTestId("custom-keyboard-shortcut-confirmation")).toBeInTheDocument(); const confirmationMsg = screen.getByTestId("custom-keyboard-shortcut-confirmation").textContent; - expect(confirmationMsg).toContain(`Keyboard shortcut changed to ${customShortcut}.`); + expect(confirmationMsg).toContain(`Keyboard shortcut changed to ${customShortcut}`); const dismissButton = screen.getByTestId("custom-keyboard-shortcut-confirmation-dismiss"); expect(dismissButton).toHaveTextContent("X"); }); diff --git a/src/components/keyboard-shortcut-controls.tsx b/src/components/keyboard-shortcut-controls.tsx index 9414d6b..ba60c59 100644 --- a/src/components/keyboard-shortcut-controls.tsx +++ b/src/components/keyboard-shortcut-controls.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { FormEvent, useState } from "react"; import "./keyboard-shortcut-controls.scss"; @@ -10,34 +10,34 @@ interface IProps { } export const KeyboardShortcutControls = (props: IProps) => { - const { shortcutEnabled, onToggleShortcut } = props; + const { shortcutEnabled, shortcutKeys, onCustomizeShortcut, onToggleShortcut } = props; const toggleButtonLabel = shortcutEnabled ? "Disable Shortcut" : "Enable Shortcut"; - // const [showError, setShowError] = useState(false); - // const [showConfirmation, setShowConfirmation] = useState(false); + const [showError, setShowError] = useState(false); + const [showConfirmation, setShowConfirmation] = useState(false); const handleToggleShortcut = () => { onToggleShortcut(); }; - // const handleCustomizeShortcut = (event: FormEvent) => { - // event.preventDefault(); - // const form = event.target as HTMLInputElement; - // const shortcut = form.querySelector("input")?.value; - // if (shortcut) { - // onCustomizeShortcut?.(shortcut); - // setShowError(false); - // setShowConfirmation(true); - // } else { - // setShowError(true); - // setShowConfirmation(false); - // } - // }; + const handleCustomizeShortcut = (event: FormEvent) => { + event.preventDefault(); + const form = event.target as HTMLInputElement; + const shortcut = form.querySelector("input")?.value; + if (shortcut) { + onCustomizeShortcut?.(shortcut); + setShowError(false); + setShowConfirmation(true); + } else { + setShowError(true); + setShowConfirmation(false); + } + }; - // const customShortcutInputDescribedBy = showConfirmation - // ? "custom-keyboard-shortcut-confirmation" - // : showError - // ? "custom-keyboard-shortcut-error" - // : undefined; + const customShortcutInputDescribedBy = showConfirmation + ? "custom-keyboard-shortcut-confirmation" + : showError + ? "custom-keyboard-shortcut-error" + : undefined; return (