Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Refactor Mega menu, use correct list category class #1079

Merged
merged 3 commits into from
Feb 13, 2024
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
2 changes: 1 addition & 1 deletion packages/react/src/Accordion/AccordionSection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createRef } from 'react'
import { Accordion } from './Accordion'
import '@testing-library/jest-dom'

describe('Accordion', () => {
describe('Accordion section', () => {
const testLabel = 'Test title'
const testContent = 'Test content'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { fireEvent, render } from '@testing-library/react'
import { useRef } from 'react'
import useFocusWithArrows, { KeyboardKeys } from './useFocusWithArrows'

describe('useFocusWithArrows', () => {
describe('use focus with arrows', () => {
const onFocusOneMock = jest.fn()
const onFocusTwoMock = jest.fn()
const onFocusThreeMock = jest.fn()
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/Breadcrumb/BreadcrumbItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createRef } from 'react'
import { BreadcrumbItem } from './BreadcrumbItem'
import '@testing-library/jest-dom'

describe('BreadcrumbItem', () => {
describe('Breadcrumb item', () => {
it('renders', () => {
render(<BreadcrumbItem href="/" />)
const component = screen.getByRole('listitem')
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/Card/CardHeadingGroup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createRef } from 'react'
import { CardHeadingGroup } from './CardHeadingGroup'
import '@testing-library/jest-dom'

describe('CardHeadingGroup', () => {
describe('Card heading group', () => {
it('renders', () => {
const { container } = render(<CardHeadingGroup tagline="test" />)

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/Card/CardLink.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createRef } from 'react'
import { CardLink } from './CardLink'
import '@testing-library/jest-dom'

describe('CardLink', () => {
describe('Card link', () => {
it('renders', () => {
render(<CardLink href="/" />)

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/Footer/FooterBottom.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createRef } from 'react'
import { FooterBottom } from './FooterBottom'
import '@testing-library/jest-dom'

describe('Footer', () => {
describe('Footer bottom', () => {
it('renders', () => {
const { container } = render(<FooterBottom />)

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/Footer/FooterTop.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createRef } from 'react'
import { FooterTop } from './FooterTop'
import '@testing-library/jest-dom'

describe('Footer', () => {
describe('Footer top', () => {
it('renders', () => {
const { container } = render(<FooterTop />)

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/Grid/GridCell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createRef } from 'react'
import { Grid } from './Grid'
import '@testing-library/jest-dom'

describe('Grid.Cell', () => {
describe('Grid cell', () => {
it('renders', () => {
const { container } = render(<Grid.Cell />)
const component = container.querySelector(':only-child')
Expand Down
4 changes: 1 addition & 3 deletions packages/react/src/MegaMenu/MegaMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ describe('Mega menu', () => {

const component = container.querySelector(':only-child')

expect(component).toHaveClass('extra')

expect(component).toHaveClass('amsterdam-mega-menu')
expect(component).toHaveClass('amsterdam-mega-menu extra')
})

it('supports ForwardRef in React', () => {
Expand Down
13 changes: 1 addition & 12 deletions packages/react/src/MegaMenu/MegaMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import clsx from 'clsx'
import { forwardRef } from 'react'
import type { ForwardedRef, ForwardRefExoticComponent, HTMLAttributes, PropsWithChildren, RefAttributes } from 'react'
import { MegaMenuListCategory } from './MegaMenuListCategory'

export type MegaMenuProps = PropsWithChildren<HTMLAttributes<HTMLDivElement>>

Expand All @@ -21,17 +22,5 @@ export const MegaMenu = forwardRef(
),
) as MegaMenuComponent

const MegaMenuListCategory = forwardRef(
(
{ children, className, ...restProps }: PropsWithChildren<HTMLAttributes<HTMLDivElement>>,
ref: ForwardedRef<HTMLDivElement>,
) => (
<div {...restProps} ref={ref} className={clsx('amsterdam-mega-menu__list-wrapper', className)}>
{children}
</div>
),
)

MegaMenu.displayName = 'MegaMenu'
MegaMenuListCategory.displayName = 'MegaMenu.ListCategory'
MegaMenu.ListCategory = MegaMenuListCategory
41 changes: 41 additions & 0 deletions packages/react/src/MegaMenu/MegaMenuListCategory.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { render } from '@testing-library/react'
import { createRef } from 'react'
import { MegaMenuListCategory } from './MegaMenuListCategory'
import '@testing-library/jest-dom'

describe('Mega menu category', () => {
it('renders', () => {
const { container } = render(<MegaMenuListCategory />)

const component = container.querySelector(':only-child')

expect(component).toBeInTheDocument()
expect(component).toBeVisible()
})

it('renders a design system BEM class name', () => {
const { container } = render(<MegaMenuListCategory />)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('amsterdam-mega-menu__list-category')
})

it('renders an additional class name', () => {
const { container } = render(<MegaMenuListCategory className="extra" />)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('amsterdam-mega-menu__list-category extra')
})

it('supports ForwardRef in React', () => {
const ref = createRef<HTMLDivElement>()

const { container } = render(<MegaMenuListCategory ref={ref} />)

const component = container.querySelector(':only-child')

expect(ref.current).toBe(component)
})
})
19 changes: 19 additions & 0 deletions packages/react/src/MegaMenu/MegaMenuListCategory.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @license EUPL-1.2+
* Copyright (c) 2024 Gemeente Amsterdam
*/

import clsx from 'clsx'
import { ForwardedRef, forwardRef, HTMLAttributes, PropsWithChildren } from 'react'

export type MegaMenuListCategoryProps = PropsWithChildren<HTMLAttributes<HTMLDivElement>>

export const MegaMenuListCategory = forwardRef(
({ children, className, ...restProps }: MegaMenuListCategoryProps, ref: ForwardedRef<HTMLDivElement>) => (
<div {...restProps} ref={ref} className={clsx('amsterdam-mega-menu__list-category', className)}>
{children}
</div>
),
)

MegaMenuListCategory.displayName = 'MegaMenu.ListCategory'
1 change: 1 addition & 0 deletions packages/react/src/MegaMenu/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { MegaMenu } from './MegaMenu'
export type { MegaMenuProps } from './MegaMenu'
export type { MegaMenuListCategoryProps } from './MegaMenuListCategory'
2 changes: 1 addition & 1 deletion packages/react/src/OrderedList/OrderedList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createRef } from 'react'
import { OrderedList } from './OrderedList'
import '@testing-library/jest-dom'

describe('Ordered List', () => {
describe('Ordered list', () => {
it('renders an HTML ol element', () => {
const { container } = render(<OrderedList />)
const list = container.querySelector('ol:only-child')
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/OrderedList/OrderedListItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createRef } from 'react'
import { OrderedListItem } from './OrderedListItem'
import '@testing-library/jest-dom'

describe('Ordered List Item', () => {
describe('Ordered list item', () => {
it('renders', () => {
render(<OrderedListItem />)

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/PageHeading/PageHeading.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createRef } from 'react'
import { PageHeading } from './PageHeading'
import '@testing-library/jest-dom'

describe('PageHeading', () => {
describe('Page heading', () => {
it('renders a heading role element', () => {
render(<PageHeading>Breaking news</PageHeading>)

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/PageMenu/PageMenuLink.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createRef } from 'react'
import { PageMenuLink } from './PageMenuLink'
import '@testing-library/jest-dom'

describe('PageMenuLink', () => {
describe('Page menu link', () => {
it('renders with href attribute', () => {
render(<PageMenuLink href="#">Link</PageMenuLink>)

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/SkipLink/SkipLink.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createRef } from 'react'
import { SkipLink } from './SkipLink'
import '@testing-library/jest-dom'

describe('Skip Link', () => {
describe('Skip link', () => {
it('renders', () => {
render(<SkipLink href="/" />)

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/UnorderedList/UnorderedList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createRef } from 'react'
import { UnorderedList } from './UnorderedList'
import '@testing-library/jest-dom'

describe('Unordered List', () => {
describe('Unordered list', () => {
it('renders an HTML ul element', () => {
const { container } = render(<UnorderedList />)
const list = container.querySelector('ul:only-child')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createRef } from 'react'
import { UnorderedListItem } from './UnorderedListItem'
import '@testing-library/jest-dom'

describe('Ordered List Item', () => {
describe('Ordered list item', () => {
it('renders', () => {
render(<UnorderedListItem />)

Expand Down
Loading