-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Correct layout of Description List if multiple terms share a des…
…cription (#1763) Co-authored-by: Vincent Smedinga <[email protected]>
- Loading branch information
1 parent
adcd819
commit ca913af
Showing
6 changed files
with
118 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/react/src/DescriptionList/DescriptionListSection.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { DescriptionList } from './DescriptionList' | ||
import '@testing-library/jest-dom' | ||
|
||
describe('Description List Section', () => { | ||
it('renders', () => { | ||
const { container } = render(<DescriptionList.Section>Test</DescriptionList.Section>) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toBeInTheDocument() | ||
expect(component).toBeVisible() | ||
}) | ||
|
||
it('renders a design system BEM class name', () => { | ||
const { container } = render(<DescriptionList.Section>Test</DescriptionList.Section>) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toHaveClass('ams-description-list__section') | ||
}) | ||
|
||
it('renders an additional class name', () => { | ||
const { container } = render(<DescriptionList.Section className="extra">Test</DescriptionList.Section>) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toHaveClass('ams-description-list__section extra') | ||
}) | ||
|
||
it('supports ForwardRef in React', () => { | ||
const ref = createRef<HTMLDivElement>() | ||
|
||
const { container } = render(<DescriptionList.Section ref={ref}>Test</DescriptionList.Section>) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(ref.current).toBe(component) | ||
}) | ||
}) |
20 changes: 20 additions & 0 deletions
20
packages/react/src/DescriptionList/DescriptionListSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright Gemeente Amsterdam | ||
*/ | ||
|
||
import clsx from 'clsx' | ||
import { forwardRef } from 'react' | ||
import type { ForwardedRef, HTMLAttributes, PropsWithChildren } from 'react' | ||
|
||
export type DescriptionListSectionProps = PropsWithChildren<HTMLAttributes<HTMLDivElement>> | ||
|
||
export const DescriptionListSection = forwardRef( | ||
({ children, className, ...restProps }: DescriptionListSectionProps, ref: ForwardedRef<HTMLDivElement>) => ( | ||
<div {...restProps} ref={ref} className={clsx('ams-description-list__section', className)}> | ||
{children} | ||
</div> | ||
), | ||
) | ||
|
||
DescriptionListSection.displayName = 'DescriptionList.Section' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters