-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SkipContent): add new component to skip large contents when usin…
…g tab key (#1981) Co-authored-by: Anders <anderslangseth@gmail.com> Add SkipContent.Return
- Loading branch information
1 parent
03e7680
commit 9607418
Showing
26 changed files
with
1,528 additions
and
83 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
packages/dnb-design-system-portal/src/docs/EUFEMIA_CHANGELOG.md
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
12 changes: 12 additions & 0 deletions
12
packages/dnb-design-system-portal/src/docs/uilib/components/skip-content.md
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,12 @@ | ||
--- | ||
title: 'SkipContent' | ||
description: 'SkipContent gives users – using their keyboard for navigation – the option to skip over content which contains a large amount of interactive elements.' | ||
status: 'new' | ||
showTabs: true | ||
--- | ||
|
||
import SkipContentInfo from 'Docs/uilib/components/skip-content/info' | ||
import SkipContentDemos from 'Docs/uilib/components/skip-content/demos' | ||
|
||
<SkipContentInfo /> | ||
<SkipContentDemos /> |
102 changes: 102 additions & 0 deletions
102
packages/dnb-design-system-portal/src/docs/uilib/components/skip-content/Examples.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,102 @@ | ||
/** | ||
* UI lib Component Example | ||
* | ||
*/ | ||
|
||
import ComponentBox from 'dnb-design-system-portal/src/shared/tags/ComponentBox' | ||
import { | ||
SkipContent, | ||
Button, | ||
Table, | ||
Td, | ||
Tr, | ||
Th, | ||
Checkbox, | ||
Input, | ||
Section, | ||
H4, | ||
Dl, | ||
Dd, | ||
Dt, | ||
} from '@dnb/eufemia/src' | ||
|
||
export const SkipContentTable = () => ( | ||
<ComponentBox hideCode scope={{ LargeTableWithInteractiveElements }}> | ||
<section aria-labelledby="table-with-caption heading"> | ||
<H4 id="heading" space={0}> | ||
This table has many focusable elements | ||
</H4> | ||
|
||
<SkipContent selector="#submit-area" text="Skip table content" top /> | ||
|
||
<LargeTableWithInteractiveElements id="table-with-caption" /> | ||
</section> | ||
|
||
<Section id="submit-area" spacing="small" style_type="divider" top> | ||
<SkipContent.Return selector="#submit-area" bottom> | ||
Back to beginning of table | ||
</SkipContent.Return> | ||
|
||
<Button>Submit</Button> | ||
</Section> | ||
</ComponentBox> | ||
) | ||
|
||
const LargeTableWithInteractiveElements = (props) => { | ||
const TdCheckbox = () => { | ||
return <Checkbox label="Select row" label_sr_only /> | ||
} | ||
const TdInput = () => { | ||
return <Input label="Label" label_sr_only size={4} /> | ||
} | ||
|
||
const Row = ({ nr }) => { | ||
return ( | ||
<Tr> | ||
<Td> | ||
<TdCheckbox /> | ||
</Td> | ||
<Td>Row {nr}</Td> | ||
<Td spacing="horizontal"> | ||
<TdInput /> | ||
</Td> | ||
<Td align="right">Row {nr}</Td> | ||
|
||
<Td.AccordionContent> | ||
<Section top spacing> | ||
<Dl> | ||
<Dt>Favorittfarge</Dt> | ||
<Dd>Grønn</Dd> | ||
<Dt>Favorittmat</Dt> | ||
<Dd>Taco</Dd> | ||
</Dl> | ||
</Section> | ||
</Td.AccordionContent> | ||
</Tr> | ||
) | ||
} | ||
|
||
const Rows = [] | ||
for (let i = 0, l = 10; i < l; i++) { | ||
Rows.push(<Row key={i} nr={String(i + 1)} />) | ||
} | ||
|
||
return ( | ||
<Table.ScrollView top> | ||
<Table accordion border outline size="medium" {...props}> | ||
<caption className="dnb-sr-only">A Table Caption</caption> | ||
|
||
<thead> | ||
<Tr> | ||
<Th>Column A</Th> | ||
<Th>Column B</Th> | ||
<Th>Column C</Th> | ||
<Th align="right">Column D</Th> | ||
</Tr> | ||
</thead> | ||
|
||
<tbody>{Rows}</tbody> | ||
</Table> | ||
</Table.ScrollView> | ||
) | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/dnb-design-system-portal/src/docs/uilib/components/skip-content/demos.md
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,13 @@ | ||
--- | ||
showTabs: true | ||
--- | ||
|
||
import { | ||
SkipContentTable, | ||
} from 'Docs/uilib/components/skip-content/Examples' | ||
|
||
## Demos | ||
|
||
### SkipContent with section | ||
|
||
<SkipContentTable /> |
93 changes: 93 additions & 0 deletions
93
packages/dnb-design-system-portal/src/docs/uilib/components/skip-content/info.md
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,93 @@ | ||
--- | ||
showTabs: true | ||
--- | ||
|
||
import { Button } from '@dnb/eufemia/src' | ||
|
||
## Description | ||
|
||
`SkipContent` gives users – using their keyboard for navigation – the option to skip over content which contains a large amount of interactive elements. | ||
|
||
**When is it desired?** | ||
|
||
Typical when an action button, such as a save button, is placed below the content. | ||
|
||
**What are interactive elements?** | ||
|
||
- Text links/Anchors | ||
- Buttons | ||
- Inputs and other form elements | ||
- Basically every focusable element | ||
|
||
**What is considered as large contents?** | ||
|
||
- Tables with interactive elements | ||
- Lists with interactive elements | ||
- Articles with interactive elements | ||
- Parts of a form | ||
|
||
**How does it work?** | ||
|
||
1. An initially hidden button will reveal when `tab` key is used. | ||
2. The user can then press this button, or continue tabbing when desired. | ||
3. When the user decides to continue using the `tab` key, the button will disappear again. | ||
4. When the button gets pressed, the focus will be set to another defined HTML class selector and the browser will scroll to the element. | ||
|
||
**Good description** | ||
|
||
The revealing button needs a clear message to let the user easily understand the intention. | ||
|
||
### Placement | ||
|
||
Ensure you put a header or a section before the `SkipContent` component. It should describe the content, so the user understands the context. | ||
|
||
- Example with a section landmark (section) and header + `SkipContent.Return`: | ||
|
||
```jsx | ||
<section aria-labelledby="heading-id"> | ||
<H2 id="heading-id">Description of table</H2> | ||
|
||
<SkipContent | ||
selector="#my-selector" | ||
text="Skip table content" | ||
/> | ||
|
||
<Table aria-labelledby="heading-id" /> | ||
|
||
</section> | ||
|
||
<section id="my-selector" aria-label="Submit"> | ||
<SubmitForm /> | ||
</section> | ||
``` | ||
|
||
- Example using a section landmark (section) and table caption: | ||
|
||
```jsx | ||
<section aria-labelledby="table-id"> | ||
<SkipContent selector=".my-selector">Skip table content</SkipContent> | ||
|
||
<Table id="table-id"> | ||
<caption>Description of table</caption> | ||
</Table> | ||
|
||
<div className="my-selector"> | ||
<SkipContent.Return | ||
selector=".my-selector" // same as SkipContent | ||
text="Back to beginning of table" | ||
/> | ||
|
||
<SubmitForm /> | ||
</div> | ||
</section> | ||
``` | ||
|
||
### Return button | ||
|
||
Optionally, you should consider to include the `SkipContent.Return` utility as well. It lets the user jump back to where they came from (before the large content). This button is only focusable when the enter action by the skip button was done. | ||
|
||
### Screen readers and landmarks | ||
|
||
The `SkipContent` helper component is mainly dedicated to keyboard navigation. | ||
|
||
In order to let screen readers skip large parts of content, you need to ensure your HTML has [logical landmarks and regions](/uilib/usage/accessibility/checklist/#landmark--and-semantics-example). |
13 changes: 13 additions & 0 deletions
13
...s/dnb-design-system-portal/src/docs/uilib/components/skip-content/properties.md
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,13 @@ | ||
--- | ||
showTabs: true | ||
--- | ||
|
||
## Properties | ||
|
||
The following properties applies to `SkipContent.Return` as well. | ||
|
||
| Properties | Description | | ||
| -------------------- | ------------------------------------------------------------------------------------------------- | | ||
| `selector` | _(required)_ Define an existing HTML element selector to focus when the inner button got pressed. | | ||
| `text` or `children` | _(required)_ Define a clear message describing the choices the users has. | | ||
| `focusDelay` | _(optional)_ Defines the delay after the enter key has been pressed. | |
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
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
Oops, something went wrong.