diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..bb04982 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Christopher. Najman + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..92c7070 --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# Accessible Mobile Menu + +A responsive mobile menu that prioritizes accessibility features for screen readers and keyboard users. + +## Description + +The mobile menu is designed to be responsive, and is visible on screens less than 768px wide. It is initially hidden and appears upon clicking the hamburger menu button. + +## Accessibility Features + +### Screen Reader Accessibility + +The menu is accessible to screen readers through the use of appropriate ARIA attributes. + +#### ARIA Attributes Used + +- `aria-controls="site-navigation"`: Associates the hamburger button with the site navigation menu. +- `aria-expanded="false" / aria-expanded="true"`: Dynamically updates the state of the navigation menu, indicating whether it's expanded or collapsed. + +### Keyboard Accessibility + +The menu ensures accessibility for keyboard users by allowing them to navigate to the hamburger button using the keyboard's tab functionality. Once focused on the button, users can press the 'enter' key to toggle the visibility of the menu. This behavior ensures that keyboard users can interact with the menu effectively, enabling them to open and close it without relying on mouse interactions. + +## Usage + +### HTML Structure + +The HTML structure comprises a div element with an ID of `primary-navigation`, containing the hamburger button and the navigation menu. + +### CSS + +The CSS defines the styles for the mobile menu and the hamburger button, including responsive design for different screen sizes. + +### JavaScript Functionality + +The JavaScript function `btnHamburger()` handles the click event on the hamburger button, toggling the visibility of the navigation menu and updating ARIA attributes accordingly. + +## Source + +- The animation on the button is based on the basic version of [Basic, Intermediate & Pro animated hamburger icons](https://youtu.be/R00QiudbD4Y?si=VDTxfeCotRcLGnGx). + +## Testing + +Tested on Windows 10 with: + +- Chrome +- Firefox +- Microsoft Edge + +The page has been tested in both browser and device views. diff --git a/css/base.css b/css/base.css new file mode 100644 index 0000000..d6dbc68 --- /dev/null +++ b/css/base.css @@ -0,0 +1,281 @@ +*, +*::after { + box-sizing: border-box; + margin: 0; +} + +html { + overflow-y: scroll; + font-size: 10px; +} + +@media (prefers-reduced-motion: no-preference) { + html, + html:focus-within { + scroll-behavior: smooth; + } +} + +:root { + --font-sans: system-ui, sans-serif; + --font-serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, serif; + --font-mono: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, "DejaVu Sans Mono", monospace; + --horz-center: 0 auto; + --flex: flex; + --grid: grid; +} + +ul:empty, +p:empty { + display: none; +} + +body { + background-color: var(--body-bg); + color: var(--body-txt); + font-family: var(--font-sans); + margin: 0; + line-height: 1.5; + font-size: clamp(1.5rem, 1.35rem + 0.4vw, 1.8rem); +} + +h1 { + font-size: clamp(2.4rem, 2.2rem + 0.8889vw, 3.2rem); + line-height: 1.3; + @media screen and (width < 360px) { + padding: 0 1rem; + } +} + +h2 { + font-size: clamp(2rem, 1.9rem + 0.4444vw, 2.4rem); +} + +h3 { + font-size: clamp(1.6rem, 1.525rem + 0.3333vw, 1.9rem); + margin-bottom: 1rem; +} + +h1 { + font-weight: 400; +} + +h2, +h3, +h4, +h5, +h6 { + line-height: 1.1; +} + +h2 { + text-align: center; + margin-bottom: 3rem; +} + +img { + max-width: 100%; + height: auto; + vertical-align: middle; /* replaces display: block but also removes space below */ + font-style: italic; +} + +ul[role="list"] { + list-style: none; + padding-left: 0; +} + +code, +pre { + font-family: var(--font-mono); +} + +:focus-visible { + outline: 3px solid var(--highlight); + outline-offset: 3px; +} + +button { + all: unset; + color: inherit; + cursor: pointer; +} + +.page-layout { + min-height: 100vh; + min-height: 100dvh; + display: var(--grid); + grid-template-rows: auto 1fr auto; +} + +.page-header { + padding: 3.2rem 0; + @media screen and (width < 360px) { + padding-inline: 1rem; + padding-top: 5rem; + } + + & p { + text-wrap: balance; + padding-inline: 1rem; + max-width: 60ch; + margin: var(--horz-center); + } +} + +.main { + max-width: 80rem; + margin: var(--horz-center); + padding: 5rem 2rem; + display: var(--flex); + flex-direction: column; + + & p { + margin-bottom: 2.5rem; + } +} + +.page-footer { + padding: 3.2rem 0; +} + +.page-header, +.page-footer { + background-color: var(--clr-darkest); + color: var(--clr-lightest); + text-align: center; + display: flex; + flex-direction: column; + gap: 2rem; +} + +.page-header a, +.page-footer a { + color: var(--clr-lightest); + text-decoration: none; +} + +.page-header ul, +.page-footer ul { + display: flex; + gap: 1rem; +} + +.page-footer { + & a:hover { + text-decoration: underline; + } + + & a::after { + content: " \27F6"; + } + + & ul { + flex-direction: column; + } +} + +.icon-logo { + fill: var(--clr-lightest); + width: 3.6rem; + height: 3.6rem; + margin: var(--horz-center); +} + +.article { + max-width: 100rem; + margin: var(--horz-center); + padding: 3rem 0 8rem; + display: var(--flex); + flex-direction: column; + gap: 3rem; + + & h2 { + text-align: center; + margin: 1rem 0; + text-transform: capitalize; + } + + & p:first-of-type { + max-width: 60ch; + } + + & section { + display: var(--flex); + flex-direction: column; + gap: 2.5rem; + } +} + +/** Helpers */ +/* Scrollable container for tables */ +[role="region"][aria-labelledby][tabindex] { + overflow: auto; +} + +/* Skip link */ +.skip-link { + color: var(--clr-lightest); + text-decoration: none; + font-weight: 600; + padding: 0.5rem 1rem; + + &::after { + content: " \2193"; + } +} +.element-invisible { + clip: rect(1px, 1px, 1px, 1px); + height: 1px; + overflow: hidden; + position: absolute; + top: 0; + left: 0; + z-index: 200; + border-bottom: 5px solid transparent; + &.element-focusable:active, + &.element-focusable:focus { + clip: auto; + height: auto; + overflow: visible; + border-bottom-color: var(--clr-lightest); + } +} + +/* Screenreader only */ +.visually-hidden { + position: absolute; + width: 1px; + height: 1px; + padding: 0; + margin: -1px; + overflow: clip; + clip-path: inset(0); + border: 0; +} + +/* Remove all animations, transitions and smooth scroll for people that prefer not to see them */ +@media (prefers-reduced-motion: reduce) { + html, + html:focus-within { + scroll-behavior: auto; + } + *, + *::before, + *::after { + animation-duration: 0.01ms !important; + animation-iteration-count: 1 !important; + transition-duration: 0.01ms !important; + scroll-behavior: auto !important; + transition-delay: 0ms !important; + } +} + +.warning { + color: var(--clr-warning); + font-weight: 600; +} +/* Always comes last **/ +.hide { + display: none; +} diff --git a/css/index.css b/css/index.css new file mode 100644 index 0000000..7d2a0eb --- /dev/null +++ b/css/index.css @@ -0,0 +1,6 @@ +@import "./theme.css"; +@import "./base.css"; +@import "./primary-navigation.css"; +/* @import "./hamburger-button.css"; */ + +@import "./theme-switcher.css"; diff --git a/css/primary-navigation.css b/css/primary-navigation.css new file mode 100644 index 0000000..86370cf --- /dev/null +++ b/css/primary-navigation.css @@ -0,0 +1,139 @@ +:root { + --animation-timing: 200ms; +} + +.primary-navigation { + position: relative; + width: 100%; + + &.padding { + padding-block-end: 1.8rem; + } + + & nav { + width: fit-content; + margin: var(--horz-center); + @media screen and (width <= 768px) { + flex-direction: column; + margin: 0 auto 0 2rem; + } + } + + & ul { + list-style: none; + padding-left: 0; + display: var(--flex); + gap: 2rem; + align-items: baseline; + + @media screen and (width <= 768px) { + flex-direction: column; + } + } + & a { + text-decoration: none; + color: var(--clr-lightest); + border-bottom: 5px solid transparent; + padding-block-end: 0.5rem; + margin-bottom: 1rem; + + &:hover { + border-bottom-color: var(--clr-lightest); + } + + &.current-page, + &.current-page:hover { + text-decoration: none; + cursor: default; + border-bottom-color: var(--clr-lightest); + font-weight: 600; + } + } + + @media screen and (width <= 768px) { + max-width: 100%; + margin: 0; + } +} + +.hamburger-button-wrapper { + display: none; +} + +@media screen and (width <= 768px) { + .hamburger-button-wrapper { + width: fit-content; + display: var(--flex); + gap: 1rem; + align-items: center; + margin: var(--horz-center); + position: absolute; + top: -1.2rem; + right: 2rem; + + & h2 { + font-size: 1.6rem; + font-weight: normal; + margin-bottom: 1rem; + } + } + + .hamburger-button { + cursor: pointer; + width: 5rem; + + & .line { + width: 80%; + height: 1rem; + fill: var(--hamburger-line-colour); + transition: + y var(--animation-timing) ease-in var(--animation-timing), + rotate var(--animation-timing) ease-in, + opacity 0ms var(--animation-timing); + transform-origin: center; + } + + &[aria-expanded="true"] .line { + transition: + y var(--animation-timing) ease-in, + rotate var(--animation-timing) ease-in var(--animation-timing), + opacity 0ms var(--animation-timing); + } + &[aria-expanded="true"] :is(.top, .bottom) { + /* + VS Code linter warns that 'y' is an unknown property: + It isn't, it's an svg property. + */ + y: 47px; + } + &[aria-expanded="true"] .top { + rotate: 45deg; + } + &[aria-expanded="true"] .bottom { + rotate: -45deg; + } + &[aria-expanded="true"] .middle { + opacity: 0; + } + } + + .menu-hidden { + position: absolute; + width: 1px; + height: 1px; + margin: -1px; + overflow: clip; + clip-path: inset(0); + border: 0; + opacity: 0; + } + .menu-visible { + position: static; + width: auto; + height: auto; + margin: inherit; + overflow: visible; + clip-path: none; + transition: opacity var(--animation-timing) var(--animation-timing) ease-in; + } +} diff --git a/css/theme-switcher.css b/css/theme-switcher.css new file mode 100644 index 0000000..037cd9e --- /dev/null +++ b/css/theme-switcher.css @@ -0,0 +1,31 @@ +.theme-picker { + position: absolute; + top: 0.5rem; + right: 1rem; + z-index: 300; + width: fit-content; +} + +.theme-icon { + width: 2.4rem; + height: 2.4rem; + fill: var(--clr-lightest); + margin-right: 0.5rem; +} + +.btn-theme-toggle { + display: var(--flex); + align-items: center; + padding: 0.5rem 0.5rem 0.75rem 0; + border-bottom: 5px solid var(--clr-mid); + color: var(--clr-lightest); + font-size: clamp(1.2rem, 1.1rem + 0.4444vw, 1.6rem); + + &:hover { + border-bottom-color: var(--clr-lightest); + } + + & .mode { + margin-inline-start: 0.5rem; + } +} diff --git a/css/theme.css b/css/theme.css new file mode 100644 index 0000000..662bfc9 --- /dev/null +++ b/css/theme.css @@ -0,0 +1,35 @@ +:root { + --clr-light-blue: rgb(135, 206, 235); + --clr-blue: rgb(0, 117, 255); + --clr-lightest: white; + --clr-mid: #555; + --clr-light-green: rgb(239, 250, 250); + --clr-green: rgb(4, 167, 167); + --clr-grey-green: rgb(44, 58, 58); + --clr-dark: rgb(30, 39, 39); + --clr-darker: #222; + --clr-darkest: black; + --clr-code-bg: beige; + --clr-red-tile: rgb(205, 74, 10); + --clr-warning: red; + + --highlight: var(--clr-light-blue); + --timeline: var(--clr-red-tile); + --hamburger-line-colour: var(--clr-light-green); + + /* Dark theme (default) */ + + --body-bg: var(--clr-dark); + --body-txt: var(--clr-light-green); + --item-shadow: rgba(0, 0, 0, 0.5); + --item-bg: var(--clr-grey-green); + --item-repo-link: var(--clr-light-green); +} + +.light-theme { + --body-bg: var(--clr-light-green); + --body-txt: var(--clr-darkest); + --item-shadow: rgba(0, 0, 0, 0.3); + --item-bg: var(--clr-lightest); + --item-repo-link: var(--clr-green); +} diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..b419ac2 Binary files /dev/null and b/favicon.ico differ diff --git a/img/sprite.svg b/img/sprite.svg new file mode 100644 index 0000000..35dc00c --- /dev/null +++ b/img/sprite.svg @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..ded0e96 --- /dev/null +++ b/index.html @@ -0,0 +1,80 @@ + + + + + + + + + + Accessible Mobile Menu + + + + + + + +
+ +
+
+ +
+

Designed with accessibility in mind, this menu emphasizes features for screen reader users and + individuals reliant on keyboard navigation. Leveraging ARIA attributes, it ensures screen reader + compatibility and enables smooth interaction through keyboard controls.

+

The hamburger menu button, when clicked, reveals the menu. Additionally, keyboard users can easily + navigate to the button and toggle the menu visibility using the 'enter' key for enhanced accessibility. +

+
+ +
+ + + \ No newline at end of file diff --git a/js/hamburger-button copy.js b/js/hamburger-button copy.js new file mode 100644 index 0000000..7541450 --- /dev/null +++ b/js/hamburger-button copy.js @@ -0,0 +1,15 @@ +export default function btnHamburger() { + const hamburgerButton = document.getElementById("hamburger-button") + const primaryNavigation = document.getElementById("primary-navigation") + const siteNavigation = document.getElementById("site-navigation") + + hamburgerButton.addEventListener("click", () => { + const isExpanded = hamburgerButton.getAttribute("aria-expanded") + isExpanded === "false" + ? hamburgerButton.setAttribute("aria-expanded", "true") + : hamburgerButton.setAttribute("aria-expanded", "false") + siteNavigation.classList.toggle("menu-hidden") + siteNavigation.classList.toggle("menu-visible") + primaryNavigation.classList.toggle("padding") + }) +} diff --git a/js/hamburger-button.js b/js/hamburger-button.js new file mode 100644 index 0000000..7541450 --- /dev/null +++ b/js/hamburger-button.js @@ -0,0 +1,15 @@ +export default function btnHamburger() { + const hamburgerButton = document.getElementById("hamburger-button") + const primaryNavigation = document.getElementById("primary-navigation") + const siteNavigation = document.getElementById("site-navigation") + + hamburgerButton.addEventListener("click", () => { + const isExpanded = hamburgerButton.getAttribute("aria-expanded") + isExpanded === "false" + ? hamburgerButton.setAttribute("aria-expanded", "true") + : hamburgerButton.setAttribute("aria-expanded", "false") + siteNavigation.classList.toggle("menu-hidden") + siteNavigation.classList.toggle("menu-visible") + primaryNavigation.classList.toggle("padding") + }) +} diff --git a/js/index.js b/js/index.js new file mode 100644 index 0000000..2e8c39c --- /dev/null +++ b/js/index.js @@ -0,0 +1,5 @@ +import themeSwitcher from "./theme-switcher.js" +import btnHamburger from "./hamburger-button.js" + +themeSwitcher() +btnHamburger() diff --git a/js/theme-switcher.js b/js/theme-switcher.js new file mode 100644 index 0000000..bdae0a8 --- /dev/null +++ b/js/theme-switcher.js @@ -0,0 +1,65 @@ +export default function themeSwitcher() { + const LOCAL_STORAGE_PREFIX = "HAMBURGER-MENU" + const MODE_STORAGE_KEY = `${LOCAL_STORAGE_PREFIX}-switcher` + + const btnThemeToggle = document.getElementById("btn-theme-toggle") + const themeLightMode = document.getElementById("theme-lightmode") + const themeDarkMode = document.getElementById("theme-darkmode") + const root = document.querySelector("html") + const mode = document.getElementById("mode") + + btnThemeToggle.addEventListener("click", (e) => { + e.preventDefault() + root.classList.toggle("light-theme") + + const isLightMode = root.classList.contains("light-theme") + + e.target.setAttribute("aria-pressed", String(isLightMode)) + + if (isLightMode) { + lightModeStyle() + } else { + darkModeStyle() + } + + const lightClass = themeLightMode.classList.contains("hide") ? "hide" : "" + const darkClass = themeDarkMode.classList.contains("hide") ? "hide" : "" + + const themeItems = [isLightMode, lightClass, darkClass] + localStorage.setItem(MODE_STORAGE_KEY, JSON.stringify(themeItems)) + }) + + function setTheme() { + const activeTheme = JSON.parse(localStorage.getItem(MODE_STORAGE_KEY)) || [ + false, + "", + "", + ] + + const isLightMode = activeTheme[0] + + if (isLightMode) { + root.classList.add("light-theme") + lightModeStyle() + } else { + root.classList.remove("light-theme") + darkModeStyle() + } + + btnThemeToggle.setAttribute("aria-pressed", String(isLightMode)) + } + + function lightModeStyle() { + themeDarkMode.classList.add("hide") + themeLightMode.classList.remove("hide") + mode.textContent = "off" + } + + function darkModeStyle() { + themeLightMode.classList.add("hide") + themeDarkMode.classList.remove("hide") + mode.textContent = "on" + } + + setTheme() +} diff --git a/ref/about-and-items-json-entry.txt b/ref/about-and-items-json-entry.txt new file mode 100644 index 0000000..0860022 --- /dev/null +++ b/ref/about-and-items-json-entry.txt @@ -0,0 +1 @@ +A responsive mobile menu with accessibility features designed for both screen reader users and keyboard-based navigation. \ No newline at end of file diff --git a/ref/button/5.html b/ref/button/5.html new file mode 100644 index 0000000..a2dca80 --- /dev/null +++ b/ref/button/5.html @@ -0,0 +1,28 @@ + + + + + + + 5 Svg test + + + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/ref/button/script.js b/ref/button/script.js new file mode 100644 index 0000000..f878536 --- /dev/null +++ b/ref/button/script.js @@ -0,0 +1,10 @@ +const button = document.querySelector("button") + +button.addEventListener("click", () => { + const isExpanded = button.getAttribute("aria-expanded") + if (isExpanded === "false") { + button.setAttribute("aria-expanded", "true") + } else { + button.setAttribute("aria-expanded", "false") + } +}) diff --git a/ref/button/style-5.css b/ref/button/style-5.css new file mode 100644 index 0000000..b590c89 --- /dev/null +++ b/ref/button/style-5.css @@ -0,0 +1,104 @@ +*, +*::before, +*::after { + box-sizing: border-box; +} + +:root { + --clr-dark: rgb(30, 39, 39); + --clr-light-green: rgb(239, 250, 250); + --clr-green: rgb(4, 167, 167); + --button-colour: var(--clr-dark); + --button-border: var(--clr-green); + --line-colour: var(--clr-light-green); +} + +body { + min-height: 100vh; + display: grid; + place-content: center; + background: black; +} + +.examples { + padding: 3rem; + max-width: 1200px; + display: flex; + gap: clamp(2rem, 8vw, 4rem); +} + +button { + background-color: var(--button-colour); + appearance: none; + border: 5px solid var(--button-border); + border-radius: 10px; + cursor: pointer; +} + +button:focus-visible { + outline: 2px solid var(--line-colour); +} + +.hamburger { + width: 50px; + fill: var(--line-colour); +} + +.line { + width: 80px; + + height: 10px; + + x: 10px; + + rx: 5px; +} + +.top { + y: 28px; +} + +.middle { + y: 47px; +} + +.bottom { + y: 68px; +} + +/* button one */ + +/* .button-one { + --button-color: #333; +} */ + +.button-one .line { + transition: + y 300ms ease-in 300ms, + rotate 300ms ease-in, + opacity 0ms 300ms; + transform-origin: center; +} + +.button-one[aria-expanded="true"] .line { + transition: + y 300ms ease-in, + rotate 300ms ease-in 300ms, + opacity 0ms 300ms; +} + +.button-one[aria-expanded="true"] :is(.top, .bottom) { + y: 47; +} + +.button-one[aria-expanded="true"] .top { + rotate: 45deg; +} + +.button-one[aria-expanded="true"] .middle { + opacity: 0; +} + +.button-one[aria-expanded="true"] .bottom { + rotate: -45deg; +} diff --git a/ref/css/hamburger-menu.css b/ref/css/hamburger-menu.css new file mode 100644 index 0000000..0ad158a --- /dev/null +++ b/ref/css/hamburger-menu.css @@ -0,0 +1,107 @@ +*, +*::after, +*::before { + box-sizing: border-box; +} + +body { + margin: 0; +} + +:root { + --bar-width: 60px; + --bar-height: 8px; + --hamburger-gap: 6px; + --foreground: #333; + --background: white; + --hamburger-margin: 8px; + --animation-timing: 200ms ease-in-out; + --hamburger-height: calc(var(--bar-height) * 3 + var(--hamburger-gap) * 2); +} + +.hamburger-menu { + --x-width: calc(var(--hamburger-height) * 1.41421356237); + + display: flex; + flex-direction: column; + gap: var(--hamburger-gap); + width: max-content; + position: absolute; + top: var(--hamburger-margin); + left: var(--hamburger-margin); + z-index: 2; + cursor: pointer; +} + +.hamburger-menu:has(input:checked) { + --foreground: white; + --background: #333; +} + +.hamburger-menu:has(input:focus-visible)::before, +.hamburger-menu:has(input:focus-visible)::after, +.hamburger-menu input:focus-visible { + border: 1px solid var(--background); + box-shadow: 0 0 0 1px var(--foreground); +} + +.hamburger-menu::before, +.hamburger-menu::after, +.hamburger-menu input { + content: ""; + width: var(--bar-width); + height: var(--bar-height); + background-color: var(--foreground); + border-radius: 9999px; + transform-origin: left center; + transition: + opacity var(--animation-timing), + width var(--animation-timing), + rotate var(--animation-timing), + translate var(--animation-timing), + background-color var(--animation-timing); +} + +.hamburger-menu input { + appearance: none; + padding: 0; + margin: 0; + outline: none; + pointer-events: none; +} + +.hamburger-menu:has(input:checked)::before { + rotate: 45deg; + width: var(--x-width); + translate: 0 calc(var(--bar-height) / -2); +} + +.hamburger-menu:has(input:checked)::after { + rotate: -45deg; + width: var(--x-width); + translate: 0 calc(var(--bar-height) / 2); +} + +.hamburger-menu input:checked { + opacity: 0; + width: 0; +} + +.sidebar { + transition: translate var(--animation-timing); + translate: -100%; + padding: 0.5rem 1rem; + padding-top: calc(var(--hamburger-height) + var(--hamburger-margin) + 1rem); + background-color: var(--foreground); + color: var(--background); + max-width: 10rem; + min-height: 100vh; +} + +/* .hamburger-menu:has(input:checked) + .sidebar { + translate: 0; +} */ + +.translateZero { + translate: 0; +} diff --git a/ref/css/style-5.css b/ref/css/style-5.css new file mode 100644 index 0000000..b590c89 --- /dev/null +++ b/ref/css/style-5.css @@ -0,0 +1,104 @@ +*, +*::before, +*::after { + box-sizing: border-box; +} + +:root { + --clr-dark: rgb(30, 39, 39); + --clr-light-green: rgb(239, 250, 250); + --clr-green: rgb(4, 167, 167); + --button-colour: var(--clr-dark); + --button-border: var(--clr-green); + --line-colour: var(--clr-light-green); +} + +body { + min-height: 100vh; + display: grid; + place-content: center; + background: black; +} + +.examples { + padding: 3rem; + max-width: 1200px; + display: flex; + gap: clamp(2rem, 8vw, 4rem); +} + +button { + background-color: var(--button-colour); + appearance: none; + border: 5px solid var(--button-border); + border-radius: 10px; + cursor: pointer; +} + +button:focus-visible { + outline: 2px solid var(--line-colour); +} + +.hamburger { + width: 50px; + fill: var(--line-colour); +} + +.line { + width: 80px; + + height: 10px; + + x: 10px; + + rx: 5px; +} + +.top { + y: 28px; +} + +.middle { + y: 47px; +} + +.bottom { + y: 68px; +} + +/* button one */ + +/* .button-one { + --button-color: #333; +} */ + +.button-one .line { + transition: + y 300ms ease-in 300ms, + rotate 300ms ease-in, + opacity 0ms 300ms; + transform-origin: center; +} + +.button-one[aria-expanded="true"] .line { + transition: + y 300ms ease-in, + rotate 300ms ease-in 300ms, + opacity 0ms 300ms; +} + +.button-one[aria-expanded="true"] :is(.top, .bottom) { + y: 47; +} + +.button-one[aria-expanded="true"] .top { + rotate: 45deg; +} + +.button-one[aria-expanded="true"] .middle { + opacity: 0; +} + +.button-one[aria-expanded="true"] .bottom { + rotate: -45deg; +} diff --git a/ref/question.txt b/ref/question.txt new file mode 100644 index 0000000..d2bf3d9 --- /dev/null +++ b/ref/question.txt @@ -0,0 +1,228 @@ +I have a question about web accessibility for screen reader users. + +Given this CSS: + +```CSS + +.visually-hidden { + position: absolute; + width: 1px; + height: 1px; + padding: 0; + margin: -1px; + overflow: clip; + clip-path: inset(0); + border: 0; +} + +``` + +and this HTML: + +```HTML + + +``` + +Will a screen reader user be able to click on / interact with the links? + + + +Following on from our previous chat, create a readme file in markdown using the Git Hub markdown format. + +Base the readme on the following HTML, CSS and JavaScript: + +```HTML +
+
+

Menu

+ +
+ + +
+``` + +```CSS +:root { + --animation-timing: 200ms; +} + +.primary-navigation { + position: relative; + width: 100%; + + &.padding { + padding-block-end: 1.8rem; + } + + & nav { + width: fit-content; + margin: var(--horz-center); + @media screen and (width <= 768px) { + flex-direction: column; + margin: 0 auto 0 2rem; + } + } + + & ul { + list-style: none; + padding-left: 0; + display: var(--flex); + gap: 2rem; + align-items: baseline; + + @media screen and (width <= 768px) { + flex-direction: column; + } + } + & a { + text-decoration: none; + color: var(--clr-lightest); + border-bottom: 5px solid transparent; + padding-block-end: 0.5rem; + margin-bottom: 1rem; + + &:hover { + border-bottom-color: var(--clr-lightest); + } + + &.current-page, + &.current-page:hover { + text-decoration: none; + cursor: default; + border-bottom-color: var(--clr-lightest); + font-weight: 600; + } + } + + @media screen and (width <= 768px) { + max-width: 100%; + margin: 0; + } +} + +.hamburger-button-wrapper { + display: none; +} + +@media screen and (width <= 768px) { + .hamburger-button-wrapper { + width: fit-content; + display: var(--flex); + gap: 1rem; + align-items: center; + margin: var(--horz-center); + position: absolute; + top: -1.2rem; + right: 2rem; + + & h2 { + font-size: 1.6rem; + font-weight: normal; + margin-bottom: 1rem; + } + } + + .hamburger-button { + cursor: pointer; + width: 5rem; + + & .line { + width: 80%; + height: 1rem; + fill: var(--hamburger-line-colour); + transition: + y var(--animation-timing) ease-in var(--animation-timing), + rotate var(--animation-timing) ease-in, + opacity 0ms var(--animation-timing); + transform-origin: center; + } + + &[aria-expanded="true"] .line { + transition: + y var(--animation-timing) ease-in, + rotate var(--animation-timing) ease-in var(--animation-timing), + opacity 0ms var(--animation-timing); + } + &[aria-expanded="true"] :is(.top, .bottom) { + y: 47; + } + &[aria-expanded="true"] .top { + rotate: 45deg; + } + &[aria-expanded="true"] .bottom { + rotate: -45deg; + } + &[aria-expanded="true"] .middle { + opacity: 0; + } + } + + .menu-hidden { + position: absolute; + width: 1px; + height: 1px; + margin: -1px; + overflow: clip; + clip-path: inset(0); + border: 0; + opacity: 0; + } + .menu-visible { + position: static; + width: auto; + height: auto; + margin: inherit; + overflow: visible; + clip-path: none; + transition: opacity var(--animation-timing) var(--animation-timing) ease-in; + } +} + +``` + +```JAVASCRIPT +function btnHamburger() { + const hamburgerButton = document.getElementById("hamburger-button") + const primaryNavigation = document.getElementById("primary-navigation") + const siteNavigation = document.getElementById("site-navigation") + + hamburgerButton.addEventListener("click", () => { + const isExpanded = hamburgerButton.getAttribute("aria-expanded") + isExpanded === "false" + ? hamburgerButton.setAttribute("aria-expanded", "true") + : hamburgerButton.setAttribute("aria-expanded", "false") + siteNavigation.classList.toggle("menu-hidden") + siteNavigation.classList.toggle("menu-visible") + primaryNavigation.classList.toggle("padding") + }) +} +btnHamburger() +``` +The hamburger menu button appears at screens less than 768px wide. At this point the menu itself is hidden and is brought into view by clicking the button. +Describe how the menu is accessible to screen readers and keyboard users even when it is not visible. +Also mention the various 'aria-' attributes. \ No newline at end of file diff --git a/ref/snippet.html b/ref/snippet.html new file mode 100644 index 0000000..5ed14a2 --- /dev/null +++ b/ref/snippet.html @@ -0,0 +1,41 @@ + + + + + + + + Document + + + + + + + + + + + \ No newline at end of file