Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Update :focus to :focus-visible (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliewongbandue authored Nov 16, 2022
1 parent b10ba3d commit 6743514
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/components/Menu/Menu.minors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,19 @@ export function Item({
{action && (
<Action onClick={doAction}>
{action.icon}
<Focus parent={Action} />
<Focus parent={Action} isKeyboardOnly />
</Action>
)}

{icon && icon}
{simpleKids}
<Focus parent={ItemStyled} />
<Focus parent={ItemStyled} isKeyboardOnly />
</ItemStyled>

{toggle && (
<Toggle open={open}>
<ChevronDown />
<Focus parent={Toggle} />
<Focus parent={Toggle} isKeyboardOnly />
</Toggle>
)}
{open && complexKids && (
Expand Down
19 changes: 15 additions & 4 deletions src/utils/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ export const hidden = {
};

export const Focus = styled.div<any>`
${({ parent, focused, variant, radius = 6, distance = 4 }) => {
${({
parent,
focused,
variant,
radius = 6,
distance = 4,
isKeyboardOnly = false,
}) => {
const underline =
variant === 'underline' &&
css`
Expand All @@ -30,6 +37,10 @@ export const Focus = styled.div<any>`
border-right-color: rgba(0, 0, 0, 0) !important;
`;
const focusPseudoSelector = isKeyboardOnly
? ':focus-visible'
: ':focus';
return css`
z-index: 1;
top: ${rem(distance * -1)};
Expand All @@ -43,9 +54,9 @@ export const Focus = styled.div<any>`
opacity: 0;
transition: 150ms ease-in-out;
${parent}:focus > &,
${parent}:focus ~ &,
${parent}:focus ~ div > & {
${parent}${focusPseudoSelector} > &,
${parent}${focusPseudoSelector} ~ &,
${parent}${focusPseudoSelector} ~ div > & {
opacity: 1;
}
Expand Down

0 comments on commit 6743514

Please # to comment.