Skip to content

Commit

Permalink
maybe fix focus-visible accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbarnum4 committed Jun 12, 2024
1 parent cb56533 commit c9d7f72
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 21 deletions.
9 changes: 7 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ module.exports = (phase, { defaultConfig }) => {
/**
* @type {import('next').NextConfig}
*/
return {
const config = {
...defaultConfig,
reactStrictMode: true,
compiler: {
styledComponents: true,
styledComponents: {
pure: true,
displayName: true,
},
},
env: {
OVERRIDE_NODE_ENV: OVERRIDE_NODE_ENV || '',
Expand Down Expand Up @@ -99,6 +102,8 @@ module.exports = (phase, { defaultConfig }) => {
].filter(Boolean);
},
};

return config;
};

function checkEnvVars(requiredVars) {
Expand Down
16 changes: 11 additions & 5 deletions src/components/Navbar/elements/NavAccordion/NavAccordionItem.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AnimatePresence, motion } from 'framer-motion';
import { useRouter } from 'next/router';
import { ReactNode, useState } from 'react';
import styled from 'styled-components';
import { motion, AnimatePresence } from 'framer-motion';
import { FiChevronRight } from 'react-icons/fi';
import styled from 'styled-components';

const NavAccordionItemStyles = styled(motion.div)`
box-shadow: 0 -3px 3px rgba(25, 25, 25, 0) inset;
Expand Down Expand Up @@ -31,15 +31,21 @@ const NavAccordionItemStyles = styled(motion.div)`
display: flex;
justify-content: space-between;
align-items: center;
:hover {
.accordion-item-title {
transition: all 250ms;
}
:hover .accordion-item-title,
:focus-visible .accordion-item-title {
background: linear-gradient(
90deg,
${({ theme }) => theme.primary[800]} 0%,
${({ theme }) => theme.primary[600]} 4%,
${({ theme }) => theme.primary[600]} 96%,
${({ theme }) => theme.primary[800]} 100%
);
box-shadow: 0 0 3px rgba(0, 0, 0, 0.5) inset;
border-radius: 0.25rem;
padding: 0 0.5rem;
}
}
.sub-links {
Expand Down Expand Up @@ -80,7 +86,7 @@ export const NavAccordionItem = ({ title, children, href, link }: NavAccordionIt
aria-label={title}
>
<button className='accordion-item'>
<div>{title}</div>
<div className='accordion-item-title'>{title}</div>
<motion.div
animate={{ rotate: isOpen ? 90 : 0 }}
transition={{ type: 'tween', duration: 0.1 }}
Expand Down
35 changes: 24 additions & 11 deletions src/components/Navbar/elements/NavAccordion/NavAccordionLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import styled from 'styled-components';
import { checkActiveSubLink } from '@this/src/helpers/navigation';

const NavAccordionLinkStyles = styled.div`
a {
all: unset;
}
font-family: 'Red Hat Display', sans-serif;
font-weight: 500;
cursor: pointer;
Expand All @@ -25,6 +28,22 @@ const NavAccordionLinkStyles = styled.div`
&.sub-link {
padding-left: 2.5rem;
}
a {
transition: all 250ms;
}
a:focus-visible,
a:hover {
background: linear-gradient(
90deg,
${({ theme }) => theme.primary[800]} 0%,
${({ theme }) => theme.primary[600]} 4%,
${({ theme }) => theme.primary[600]} 96%,
${({ theme }) => theme.primary[800]} 100%
);
box-shadow: 0 0 3px rgba(0, 0, 0, 0.5) inset;
border-radius: 0.25rem;
padding: 0.25rem 0.5rem;
}
`;

export const NavAccordionLink = ({
Expand All @@ -47,18 +66,12 @@ export const NavAccordionLink = ({
closeMenu();
};
return (
<a
style={{ all: 'unset' }}
href={href}
title={linkTitle}
aria-label={linkTitle}
onClick={handleClick}
<NavAccordionLinkStyles
className={`${checkActiveSubLink(href, pathname) ? 'active' : ''} ${className || ''}`}
>
<NavAccordionLinkStyles
className={`${checkActiveSubLink(href, pathname) ? 'active' : ''} ${className || ''}`}
>
<a href={href} title={linkTitle} aria-label={linkTitle} onClick={handleClick}>
{children}
</NavAccordionLinkStyles>
</a>
</a>
</NavAccordionLinkStyles>
);
};
4 changes: 1 addition & 3 deletions src/components/Navbar/elements/NavLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ export const NavLinkStyles = styled.div.attrs(({ color }: { color?: '' | 'yellow
:focus {
background: ${({ theme }) => theme.bgHover};
color: ${({ theme }) => theme.fg};
box-shadow: 0 0 3px 0px ${({ theme }) => theme.alpha.fg} inset;
z-index: 1;
}
:focus-visible {
outline: 2px solid ${({ theme }) => theme.secondary[800]};
outline: 2px solid ${({ theme }) => theme.secondary[800]} !important;
}
}
&.sub-nav.sub-nav-active {
Expand Down
3 changes: 3 additions & 0 deletions src/theme/styled/GlobalStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const GlobalStyles = createGlobalStyle`
color: ${({ theme }) => theme.white};
font-size: 1rem;
font-family: 'Red Hat Display', sans-serif;
:focus-visible {
outline: 2px solid ${({ theme }) => theme.secondary[800]};
}
}
input, textarea, select {
Expand Down

0 comments on commit c9d7f72

Please sign in to comment.