From d7c20ba6e8f0675ad2fcd4fb41419de005ae3979 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> Date: Sat, 16 Jan 2021 22:31:50 +0300 Subject: Rewrites Components For Accessibility Makes major changes to the structuring of checkboxes, and ranges to be more accessible to all users. Signed-off-by: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> --- src/commonStyles.tsx | 23 +++++++++++- src/components/InputTypes/Checkbox.tsx | 27 +++++--------- src/components/InputTypes/Range.tsx | 64 ++++++++++++---------------------- src/components/InputTypes/index.tsx | 2 +- src/components/Question.tsx | 11 +++--- 5 files changed, 57 insertions(+), 70 deletions(-) (limited to 'src') diff --git a/src/commonStyles.tsx b/src/commonStyles.tsx index 5053846..71bbd13 100644 --- a/src/commonStyles.tsx +++ b/src/commonStyles.tsx @@ -14,6 +14,24 @@ const unselectable = css` user-select: none; `; +const hiddenInput = css` + position: absolute; + opacity: 0; + height: 0; + width: 0; +`; + +const multiSelectInput = css` + display: inline-block; + position: relative; + + margin: 1rem 0.5rem 0 0; + border: whitesmoke 0.2rem solid; + + background-color: whitesmoke; + transition: background-color 300ms; +`; + const textInputs = css` display: inline-block; width: min(20rem, 90%); @@ -32,8 +50,11 @@ const textInputs = css` border-radius: 8px; `; + export { selectable, unselectable, - textInputs + hiddenInput, + multiSelectInput, + textInputs, }; diff --git a/src/components/InputTypes/Checkbox.tsx b/src/components/InputTypes/Checkbox.tsx index f63da31..3093caf 100644 --- a/src/components/InputTypes/Checkbox.tsx +++ b/src/components/InputTypes/Checkbox.tsx @@ -2,6 +2,7 @@ import { jsx, css } from "@emotion/react"; import React, { ChangeEvent } from "react"; import colors from "../../colors"; +import { multiSelectInput, hiddenInput } from "../../commonStyles"; interface CheckboxProps { index: number, @@ -10,36 +11,25 @@ interface CheckboxProps { } const generalStyles = css` + cursor: pointer; + label { - display: inline-block; - position: relative; - top: 0.3rem; - width: 1em; height: 1em; + top: 0.3rem; - margin: 1rem 0.5rem 0 0; - border: whitesmoke 0.2rem solid; border-radius: 25%; - - transition: background-color 300ms; + cursor: pointer; } .unselected { background-color: white; } - .unselected:hover { + .unselected:focus-within, :hover .unselected { background-color: lightgray; } - input { - position: absolute; - opacity: 0; - height: 0; - width: 0; - } - .checkmark { position: absolute; } @@ -65,9 +55,8 @@ const activeStyles = css` export default function Checkbox(props: CheckboxProps): JSX.Element { return (