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(Dl): remove span as direct sibling in horizontal layout direction definition lists #1625

Merged
merged 1 commit into from
Oct 12, 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
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ render(<Dl>
<Dd>Description 1</Dd>
<Dd>Description 2</Dd>
<Dd>Description 3</Dd>
<dl className="dnb-dl">
<Dt>Sub Term</Dt>
<Dd>Sub Description</Dd>
</dl>
<Dd>
<Dl>
<Dt>Sub Term</Dt>
<Dd>Sub Description</Dd>
</Dl>
</Dd>
</Dl>)
`
}
Expand Down
5 changes: 3 additions & 2 deletions packages/dnb-eufemia/src/elements/Dl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ Dl.Item = ({
children,
}: DlItemProps & React.AllHTMLAttributes<HTMLSpanElement>) => {
return (
<span className={classnames(className, 'dnb-dl__item')}>
<>
{children}
</span>
<dd aria-hidden className={classnames(className, 'dnb-dl__item')} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this actually be dd and not dl?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to be dd because only a dd is allowed inside a dl – that's what axe tells us at least. When I tested it with a span, VoiceOver did work fine. So this PR is more about to avoid noise in the automated a11y tests.

</>
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('List screenshot', () => {

it('have to match dl list', async () => {
const screenshot = await testPageScreenshot({
style: { width: '40rem' },
style: { width: '35rem' },
selector: '[data-visual-test="lists-dl-horizontal"]',
})
expect(screenshot).toMatchImageSnapshot()
Expand Down
49 changes: 49 additions & 0 deletions packages/dnb-eufemia/src/elements/__tests__/Lists.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Dl Test
*
*/

import React from 'react'
import { axeComponent } from '../../core/jest/jestSetup'
import { render } from '@testing-library/react'
import Dl from '../Dl'
import Dt from '../Dt'
import Dd from '../Dd'

describe('Dl', () => {
describe('in horizontal direction', () => {
it('should validate with ARIA rules', async () => {
const Component = render(
<Dl direction="horizontal">
<Dl.Item>
<Dt>Term</Dt>
<Dd>Description</Dd>
</Dl.Item>
<Dl.Item>
<Dt>Term</Dt>
<Dd>Description</Dd>
</Dl.Item>
</Dl>
)
expect(await axeComponent(Component)).toHaveNoViolations()
})
})

describe('with nested Dls', () => {
it('should validate with ARIA rules', async () => {
const Component = render(
<Dl>
<Dt>Term</Dt>
<Dd>Description</Dd>
<Dd>
<Dl>
<Dt>Term</Dt>
<Dd>Description</Dd>
</Dl>
</Dd>
</Dl>
)
expect(await axeComponent(Component)).toHaveNoViolations()
})
})
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions packages/dnb-eufemia/src/elements/stories/Lists.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,19 @@ export const ListSandbox = () => (
<Dt>Term</Dt>
<Dd>Description</Dd>
</Dl.Item>
<Dl.Item>
<Dt>A term with several</Dt>
<Dd>
Description with several words lorem nulla mi posuere
cubilia vel vulputate
</Dd>
</Dl.Item>
<Dl.Item>
<Dt>A term with several words</Dt>
<Dd>Description</Dd>
</Dl.Item>
<Dl.Item>
<Dt>Term word</Dt>
<Dd>
Description with several words lorem nulla mi posuere
cubilia vel vulputate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,24 +726,29 @@ a.dnb-button {
.dnb-dl dd {
padding: 0;
margin: 0.5rem 0 1rem; }
.dnb-dl > dl,
.dnb-dl:not([class*='dnb-space']) > dl {
.dnb-dl > dd > dl,
.dnb-dl:not([class*='dnb-space']) > dd > dl {
margin-top: 1.5rem;
margin-left: 2rem; }
@media screen and (min-width: 40em) {
.dnb-dl__direction--horizontal {
display: flex;
flex-direction: column;
flex-wrap: wrap;
gap: 0.5rem; }
.dnb-dl__direction--horizontal dt,
.dnb-dl__direction--horizontal dt {
margin-right: 0.5rem;
max-width: 30%; }
.dnb-dl__direction--horizontal dd {
width: calc(70% - 1.5rem); }
.dnb-dl__direction--horizontal dt,
.dnb-dl__direction--horizontal dd,
.dnb-dl__direction--horizontal dd ~ dt {
margin-top: 0;
margin-bottom: 0; }
.dnb-dl__direction--horizontal dt {
margin-right: 1rem;
max-width: 60ch; }
.dnb-dl__item {
display: flex; } }
.dnb-dl dd.dnb-dl__item {
width: 100%;
height: 0;
overflow: hidden; } }

.dnb-spacing .dnb-ul:not([class*='dnb-space__top']),
.dnb-spacing .dnb-ol:not([class*='dnb-space__top']) {
Expand Down
27 changes: 17 additions & 10 deletions packages/dnb-eufemia/src/style/elements/lists.scss
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@
// In case we really want / need to have a indented definition content
// margin-left: 2rem;
}
& > dl,
&:not([class*='dnb-space']) > dl {
& > dd > dl,
&:not([class*='dnb-space']) > dd > dl {
margin-top: 1.5rem;
margin-left: 2rem;
}
Expand All @@ -140,22 +140,29 @@
@include allAbove(small) {
&__direction--horizontal {
display: flex;
flex-direction: column;
flex-wrap: wrap;
gap: 0.5rem;

& dt,
& dt {
margin-right: 0.5rem;
max-width: 30%;
}
& dd {
// width: calc(70% - 1.5rem); // minus margin-right and the gap
width: calc(70% - 1.5rem); // minus margin-right and the gap
}
& dt,
& dd,
& dd ~ dt {
margin-top: 0;
margin-bottom: 0;
}
& dt {
margin-right: 1rem;
max-width: 60ch;
}
}

&__item {
display: flex;
dd#{&}__item {
width: 100%;
height: 0;
overflow: hidden;
}
}
}
Expand Down