Skip to content

Commit

Permalink
♿️(frontend) update left nav panel
Browse files Browse the repository at this point in the history
- the HTML semantic needed improvement:
the menu items were button wrapped in a li
wrapped in link.
- update related tests
  • Loading branch information
daproclaima committed Sep 27, 2024
1 parent 2967f1b commit 976c955
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ and this project adheres to
- ✨(frontend) allow group members filtering #363
- ✨(mailbox) send new mailbox confirmation email #397

### Fixed

- ♿️(frontend) fix left nav panel #396

### Changed

- ♻️(serializers) move business logic to serializers #414
Expand Down
11 changes: 9 additions & 2 deletions src/frontend/apps/desk/src/core/__tests__/MainLayout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { useConfigStore } from '../config';
jest.mock('next/navigation', () => ({
...jest.requireActual('next/navigation'),
usePathname: () => '/',
useRouter: () => ({
push: () => {},
}),
}));

describe('MainLayout', () => {
Expand All @@ -20,19 +23,23 @@ describe('MainLayout', () => {
render(<MainLayout />, { wrapper: AppWrapper });

expect(
screen.getByRole('link', {
screen.getByRole('button', {
name: /Teams button/i,
}),
).toBeInTheDocument();

expect(
screen.getByRole('link', {
screen.getByRole('button', {
name: /Mail Domains button/i,
}),
).toBeInTheDocument();
});

it('checks menu rendering without team feature', () => {
useConfigStore.setState({
config: { FEATURES: { TEAMS: false }, LANGUAGES: [] },
});

render(<MainLayout />, { wrapper: AppWrapper });

expect(
Expand Down
53 changes: 25 additions & 28 deletions src/frontend/apps/desk/src/features/menu/MenuItems.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { usePathname } from 'next/navigation';
import { usePathname, useRouter } from 'next/navigation';
import React, { useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';

import { Box, BoxButton, StyledLink } from '@/components';
import { Box, BoxButton } from '@/components';
import { useCunninghamTheme } from '@/cunningham';
import { SVGComponent } from '@/types/components';

Expand All @@ -17,6 +17,7 @@ interface MenuItemProps {

const MenuItem = ({ Icon, label, href, alias }: MenuItemProps) => {
const { t } = useTranslation();
const router = useRouter();
const pathname = usePathname();
const { colorsTokens } = useCunninghamTheme();
const parentRef = useRef(null);
Expand All @@ -43,34 +44,28 @@ const MenuItem = ({ Icon, label, href, alias }: MenuItemProps) => {
};

return (
<StyledLink
href={href}
aria-current={isActive && 'page'}
ref={parentRef}
onMouseOver={() => setIsTooltipOpen(true)}
onMouseLeave={() => setIsTooltipOpen(false)}
style={{ display: 'block' }}
$css={`
&:focus-visible {
outline: #fff solid 2px;
}`}
>
<Box ref={parentRef}>
<Box
$margin="xtiny"
$padding="tiny"
as="li"
$justify="center"
$css={`
& > button { padding: 0};
transition: all 0.2s ease-in-out
`}
$css="transition: all 0.2s ease-in-out;"
$background={background}
$radius="10px"
>
<BoxButton
aria-current={isActive && 'page'}
onMouseOver={() => setIsTooltipOpen(true)}
onMouseLeave={() => setIsTooltipOpen(false)}
$css={`
padding: 0;
${isActive ? null : '&:focus-visible {outline: #fff solid 2px;}'}
`}
aria-label={t(`{{label}} button`, { label })}
$color={color}
as="span"
as="button"
onClick={() => router.push(href)}
>
<Icon
width="2.375rem"
Expand All @@ -81,15 +76,17 @@ const MenuItem = ({ Icon, label, href, alias }: MenuItemProps) => {
/>
</BoxButton>
</Box>
{isTooltipOpen && (
<Tooltip
parentRef={parentRef}
label={label}
backgroundColor={backgroundTooltip}
textColor={colorTooltip}
/>
)}
</StyledLink>
<Box as="span">
{isTooltipOpen && (
<Tooltip
parentRef={parentRef}
label={label}
backgroundColor={backgroundTooltip}
textColor={colorTooltip}
/>
)}
</Box>
</Box>
);
};

Expand Down

0 comments on commit 976c955

Please sign in to comment.