Skip to content

Commit

Permalink
docs: add accessibility docs to Heading component
Browse files Browse the repository at this point in the history
  • Loading branch information
DSil committed Nov 14, 2024
1 parent 2d9b3fd commit c4e98a4
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
8 changes: 6 additions & 2 deletions docs/src/__examples__/Heading/DEFAULT.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import React from "react";
import { Heading } from "@kiwicom/orbit-components";

export default {
Example: () => <Heading>Orbit components</Heading>,
Example: () => (
<Heading role="heading" level={1}>
Orbit components
</Heading>
),
exampleKnobs: [
{
component: "Heading",
Expand All @@ -26,7 +30,7 @@ export default {
"title5",
"title6",
],
defaultValue: "div",
defaultValue: "title1",
},
],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
title: Accessibility
redirect_from:
- /components/heading/accessibility/
---

# Accessibility

## Heading

The Heading component has been designed with accessibility in mind.

The component offers flexibility in terms of the HTML element used for the root node, the `role` attribute, and the `level` attribute.
These properties allow for the creation of semantic and accessible headings.

| Name | Type | Description |
| :---- | :------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------------------- |
| as | `"h1" \| "h2" \| "h3" \| "h4" \| "h5" \| "h6" \| "div"` | Defines the HTML element to be rendered. |
| role | `"heading"` | Can only be used if `as="div"`. If defined, sets the role of the element to be "heading". |
| level | `number` | Can only be used if `as="div"` and "`role="heading`". Defines the `aria-level` of the rendered `div` with the heading role. |

All the props above are optional by default.

If they are not provided, the component will render a `div` element with no role or aria-level defined.

Check warning on line 24 in docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Kiwi.Contractions] Feel free to use a contraction instead of 'they are': https://orbit.kiwi/content/technical-content/language/#use-contractions Raw Output: {"message": "[Kiwi.Contractions] Feel free to use a contraction instead of 'they are': https://orbit.kiwi/content/technical-content/language/#use-contractions", "location": {"path": "docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx", "range": {"start": {"line": 24, "column": 4}}}, "severity": "INFO"}

Check warning on line 24 in docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Kiwi.Will] Avoid using 'will'. Stick to the present tense. Raw Output: {"message": "[Kiwi.Will] Avoid using 'will'. Stick to the present tense.", "location": {"path": "docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx", "range": {"start": {"line": 24, "column": 41}}}, "severity": "WARNING"}
It is not semantically wrong but won't tell screen readers that the element is a heading. This should be used only for decorative purposes.

Check warning on line 25 in docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Kiwi.Contractions] Feel free to use a contraction instead of 'It is': https://orbit.kiwi/content/technical-content/language/#use-contractions Raw Output: {"message": "[Kiwi.Contractions] Feel free to use a contraction instead of 'It is': https://orbit.kiwi/content/technical-content/language/#use-contractions", "location": {"path": "docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx", "range": {"start": {"line": 25, "column": 1}}}, "severity": "INFO"}

Check warning on line 25 in docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Kiwi.Will] Avoid using 'won't'. Stick to the present tense. Raw Output: {"message": "[Kiwi.Will] Avoid using 'won't'. Stick to the present tense.", "location": {"path": "docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx", "range": {"start": {"line": 25, "column": 34}}}, "severity": "WARNING"}

```jsx
<Heading>Hello World!</Heading>
```

renders:

```html
<div>Hello World!</div>
```

If the `as` prop is set to `"div"` (or undefined), the `role` prop is optional, but only accepts one possible value (if not `undefined`): `"heading"`.
If the `role` prop is set to `"heading"`, the `level` prop must be defined as well. It will tell assistive technologies the level of the heading.

Check warning on line 38 in docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Kiwi.Will] Avoid using 'will'. Stick to the present tense. Raw Output: {"message": "[Kiwi.Will] Avoid using 'will'. Stick to the present tense.", "location": {"path": "docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx", "range": {"start": {"line": 38, "column": 88}}}, "severity": "WARNING"}
The `level` prop must be a number between 1 and 6 and cannot be used if the `role` prop is not set to `"heading"`.

Check warning on line 39 in docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Kiwi.Contractions] Feel free to use a contraction instead of 'cannot': https://orbit.kiwi/content/technical-content/language/#use-contractions Raw Output: {"message": "[Kiwi.Contractions] Feel free to use a contraction instead of 'cannot': https://orbit.kiwi/content/technical-content/language/#use-contractions", "location": {"path": "docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx", "range": {"start": {"line": 39, "column": 55}}}, "severity": "INFO"}

Check warning on line 39 in docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Kiwi.Contractions] Feel free to use a contraction instead of 'is not': https://orbit.kiwi/content/technical-content/language/#use-contractions Raw Output: {"message": "[Kiwi.Contractions] Feel free to use a contraction instead of 'is not': https://orbit.kiwi/content/technical-content/language/#use-contractions", "location": {"path": "docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx", "range": {"start": {"line": 39, "column": 89}}}, "severity": "INFO"}

```jsx
<Heading as="div" role="heading" level={1}>
Hello World!
</Heading>
```

renders:

```html
<div role="heading" aria-level="1">Hello World!</div>
```

If the `as` prop is set to `"h1"`, `"h2"`, `"h3"`, `"h4"`, `"h5"`, or `"h6"`, the component will render the corresponding HTML element.

Check warning on line 53 in docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Kiwi.Will] Avoid using 'will'. Stick to the present tense. Raw Output: {"message": "[Kiwi.Will] Avoid using 'will'. Stick to the present tense.", "location": {"path": "docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx", "range": {"start": {"line": 53, "column": 93}}}, "severity": "WARNING"}
In that case, the `role` and `level` props are not needed, since assistive technologies will recognize the element as a heading and its correct level automatically.

Check warning on line 54 in docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Kiwi.Contractions] Feel free to use a contraction instead of 'are not': https://orbit.kiwi/content/technical-content/language/#use-contractions Raw Output: {"message": "[Kiwi.Contractions] Feel free to use a contraction instead of 'are not': https://orbit.kiwi/content/technical-content/language/#use-contractions", "location": {"path": "docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx", "range": {"start": {"line": 54, "column": 44}}}, "severity": "INFO"}

Check warning on line 54 in docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Kiwi.Will] Avoid using 'will'. Stick to the present tense. Raw Output: {"message": "[Kiwi.Will] Avoid using 'will'. Stick to the present tense.", "location": {"path": "docs/src/documentation/03-components/09-text/heading/03-accessibility.mdx", "range": {"start": {"line": 54, "column": 89}}}, "severity": "WARNING"}

```jsx
<Heading as="h1">Hello World!</Heading>
```

renders:

```html
<h1>Hello World!</h1>
```

### Compatibility with SkipNavigation

The `dataA11ySection` prop can be used to link the Heading to a `SkipNavigation` component.

0 comments on commit c4e98a4

Please sign in to comment.