Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: a11y updates #22

Merged
merged 2 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 54 additions & 7 deletions package-lock.json

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

21 changes: 19 additions & 2 deletions packages/react-frontend/account/LoginForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useAccountStore } from "store/account";
import { useLog } from "hooks/useLog";
import { Input } from "components/Form/Input";
import * as Styled from "./LoginForm.styled";
import { useError } from "hooks/form/useError";

export const LoginForm = () => {
const { login } = useApi();
Expand All @@ -16,9 +17,12 @@ export const LoginForm = () => {
const [email, setEmail] = useState(IS_DEV ? "miko@mikosramek.ca" : "");
const [password, setPassword] = useState(IS_DEV ? "password" : "");

const { ErrorText, setError } = useError();

const handleSubmit = useCallback(
(e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
setError("");
login({ email, password })
.then((response) => {
if (response && !(response instanceof Error)) {
Expand All @@ -32,9 +36,19 @@ export const LoginForm = () => {
Router.push("/armies");
}
})
.catch(error);
.catch((err) => {
error(err);
const errMessage = err.response.data;
switch (errMessage) {
case "Email or Password incorrect":
setError(errMessage);
break;
default:
setError("Something went wrong");
}
});
},
[email, error, logUserIn, login, password]
[email, error, logUserIn, login, password, setError]
);

return (
Expand All @@ -46,6 +60,7 @@ export const LoginForm = () => {
label="Email"
value={email}
onChange={(_i, val) => setEmail(val)}
required
/>
<Input
type="password"
Expand All @@ -54,8 +69,10 @@ export const LoginForm = () => {
value={password}
onChange={(_i, val) => setPassword(val)}
autocomplete="current-password"
required
/>
<MainButton copy="Login" />
{ErrorText}
</Styled.Form>
);
};
18 changes: 9 additions & 9 deletions packages/react-frontend/account/SignupForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useApi } from "hooks/useApi";
import { useAccountStore } from "store/account";
import { useLog } from "hooks/useLog";
import { storeSession } from "utils/general";
import { useError } from "hooks/form/useError";

export const SignupForm = () => {
const { signUp } = useApi();
Expand All @@ -18,14 +19,12 @@ export const SignupForm = () => {
);
const [password, setPassword] = useState(IS_DEV ? "password" : "");
const [showPassword, toggleShowPassword] = useReducer((val) => !val, false);

const [apiError, setApiError] = useState("");
const errorRef = useRef<HTMLInputElement>(null);
const { ErrorText, setError } = useError();

const handleSubmit = useCallback(
(e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
setApiError("");
setError("");
signUp({ email, password })
.then((response) => {
if (response && !(response instanceof Error)) {
Expand All @@ -41,11 +40,10 @@ export const SignupForm = () => {
})
.catch((e) => {
error(e);
setApiError(e.response.data);
if (errorRef.current) errorRef.current.focus();
setError(e.response.data);
});
},
[email, error, logUserIn, password, signUp]
[email, error, logUserIn, password, signUp, setError]
);

return (
Expand Down Expand Up @@ -76,11 +74,13 @@ export const SignupForm = () => {
label="Show Password"
checked={showPassword}
onChange={toggleShowPassword}
aria-label="Show password as plain text. Warning: this will display your password on the screen."
ariaLabel={`Show password as plain text. Warning: this ${
showPassword ? "is displaying" : "will display"
} your password as plain text.`}
/>
</Styled.ToggleWrapper>
<MainButton copy="Sign up" />
<Styled.Error ref={errorRef}>{apiError}</Styled.Error>
{ErrorText}
</Styled.Form>
);
};
4 changes: 2 additions & 2 deletions packages/react-frontend/armies/StepContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const StepContainer = ({ step, stepCount }: Props) => {
const handleDelete = useCallback(() => {
const confirmation = confirm(`Delete the "${step.name}" step?`);
if (confirmation) deleteStep(step.id);
}, [step]);
}, [deleteStep, step.id, step.name]);

const [isLoading, setLoading] = useState(false);
const handleReorder = useCallback(
Expand All @@ -38,7 +38,7 @@ const StepContainer = ({ step, stepCount }: Props) => {
setLoading(false);
}
},
[step, isLoading, canReorder]
[isLoading, canReorder, moveStep, step.id, error]
);

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/react-frontend/armies/Steps/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const StepsPage = ({ steps }: Props) => {
decreaseCounter();
}
}
}, [counter, parsedSteps]);
}, [counter, decreaseCounter, log, parsedSteps, setCurrentStepId]);

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const ListButton = styled(MainButton)`
`;

export const TurnButton = styled(ListButton)`
border: 1px solid var(--black);
border: 1px solid var(--impact);
width: 75px;
height: 75px;
display: flex;
Expand Down
3 changes: 3 additions & 0 deletions packages/react-frontend/components/Form/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Props = {
autocomplete?: string;
required?: boolean;
checked?: boolean;
ariaLabel?: string;
};

export const Input = ({
Expand All @@ -23,6 +24,7 @@ export const Input = ({
autocomplete,
required = false,
checked = false,
ariaLabel,
}: Props) => {
return (
<>
Expand Down Expand Up @@ -54,6 +56,7 @@ export const Input = ({
autoComplete={autocomplete}
required={required}
checked={checked}
aria-label={ariaLabel}
/>
)}
</>
Expand Down
10 changes: 8 additions & 2 deletions packages/react-frontend/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ const Header = () => {
{!isLoggedIn && (
<>
<Link href="/signup" passHref legacyBehavior>
<Styled.StyledLink isActive={pathname === "/signup"}>
<Styled.StyledLink
aria-current={pathname === "/signup" ? "page" : undefined}
isActive={pathname === "/signup"}
>
Sign up
</Styled.StyledLink>
</Link>
<Link href="/" passHref legacyBehavior>
<Styled.StyledLink isActive={pathname === "/"}>
<Styled.StyledLink
aria-current={pathname === "/" ? "page" : undefined}
isActive={pathname === "/"}
>
Log in
</Styled.StyledLink>
</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ export const Button = styled.button`
&:disabled {
color: var(--impact-dark);
}
&:focus {
color: var(--white);
background: var(--impact);
}
`;
6 changes: 4 additions & 2 deletions packages/react-frontend/components/MainButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as Styled from "./MainButton.styled";

type Props = {
export type Props = {
onClick?: () => void;
copy: string;
className?: string;
disabled?: boolean;
ariaLabel?: string;
type?: "submit" | "reset" | "button";
};

export const MainButton = ({
Expand All @@ -14,10 +15,11 @@ export const MainButton = ({
className = "",
disabled = false,
ariaLabel = copy,
type = "submit",
}: Props) => {
return (
<Styled.Button
type="submit"
type={type}
className={className}
onClick={onClick}
disabled={disabled}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MainButton } from "components/MainButton";
import styled from "styled-components";

export const Button = styled(MainButton)`
border: 1px solid var(--impact);
margin-right: 10px;
&:last-of-type {
margin-right: 0;
}
&:focus {
border-color: var(--white);
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Props as BaseProps } from "components/MainButton";
import * as Styled from "./ModalButton.styled";

type Props = {} & BaseProps;

export const ModalButton = ({ ...props }: Props) => {
return <Styled.Button {...props} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export const CloseButton = styled.button`
font-size: 36px;
background-color: var(--white);
color: var(--impact);
&:focus {
border: 2px solid var(--impact);
}
`;

export const Heading = styled.h2`
Expand Down
Loading