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

Update toggle button and focus state #203

Merged
merged 1 commit into from
Nov 16, 2022
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
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