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

Aria label consistency #498

Merged
merged 7 commits into from
Jul 19, 2019
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: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ declare module '@primer/components' {

export interface TooltipProps extends CommonProps {
align?: 'left' | 'right'
'aria-label'?: string
direction?: 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'nw'
noDelay?: boolean
text?: string
Expand All @@ -265,6 +266,7 @@ declare module '@primer/components' {
export interface UnderlineNavProps extends CommonProps {
actions?: React.ReactNode
align?: 'right'
'aria-label'?: string
full?: boolean
label?: string
}
Expand Down
15 changes: 12 additions & 3 deletions pages/components/docs/Tooltip.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
# Tooltip

The Tooltip component adds a tooltip to add context to elements on the page. The Toolip has a black background by default.
The Tooltip component adds a tooltip to add context to elements on the page. The Tooltip has a black background by default.

### ⚠️ Usage warning! ⚠️
Tooltips as a UI pattern should be our last resort for conveying information because it is hidden by default and often with zero or little visual indicator of its existence.

Before adding a tooltip, please consider: Is this information essential and necessary? Can the UI be made clearer? Can the information be shown on the page by default?

**Attention:** we use aria-label for tooltip contents, because it is crucial that they are accessible to screen reader users. However, aria-label replaces the text content of an element in screen readers, so only use Tooltip on elements with no existing text content, or consider using `title` for supplemental information.



## Default example

```.jsx
<BorderBox p={3}>
<Tooltip text="Hello, Tooltip!">Text with a tooltip</Tooltip>
<Tooltip aria-label="Hello, Tooltip!">Text with a tooltip</Tooltip>
</BorderBox>
```

Expand All @@ -21,7 +30,7 @@ Tooltip components get `COMMON` system props. Read our [System Props](/component
| align | String | | Can be either `left` or `right`.|
| direction | String | | Can be one of `n`, `ne`, `e`, `se`, `s`, `sw`, `w`, `nw` | Sets where the tooltip renders in relation to the target. |
| noDelay | Boolean | | When set to `true`, tooltip appears without any delay |
| text | String | | Text used in `aria-label` (for accessibility).
| aria-label | String | | Text used in `aria-label` (for accessibility).
| wrap | Boolean | | Use `true` to allow text within tooltip to wrap.


Expand Down
14 changes: 8 additions & 6 deletions pages/components/docs/UnderlineNav.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ To use UnderlineNav with [react-router](https://github.com/ReactTraining/react-r
```as={NavLink}``` and omit the ```selected``` prop.
This ensures that the NavLink gets ```activeClassName='selected'```

**Attention:** Make sure to properly label your `UnderlineNav` with an `aria-label` to provide context about the type of navigation contained in `UnderlineNav`.

## Default example

```.jsx
<ExampleHeading>
Using <Text fontFamily="mono">{'<UnderlineNav.Link>'}</Text>
</ExampleHeading>
<UnderlineNav>
<UnderlineNav.Link href="#foo" selected>
Selected
<UnderlineNav aria-label="Main">
<UnderlineNav.Link href="#home" selected>
Home
</UnderlineNav.Link>
<UnderlineNav.Link href="#bar">Bar</UnderlineNav.Link>
<UnderlineNav.Link href="#baz">Baz</UnderlineNav.Link>
<UnderlineNav.Link href="#documentation">Documentation</UnderlineNav.Link>
<UnderlineNav.Link href="#support">Support</UnderlineNav.Link>
</UnderlineNav>
```

Expand All @@ -35,7 +37,7 @@ UnderlineNav and UnderlineNav.Link components get `COMMON` system props. Read ou
| actions | Node | Place another element, such as a button, to the opposite side of the navigation items.|
| align | String | Use `right` to have navigation items aligned right. |
| full | Boolean | Used to make navigation fill the width of the container. |
| label | String | Used to set the `aria-label` on the top level `<nav>` element. |
| aria-label | String | Used to set the `aria-label` on the top level `<nav>` element. |

### UnderlineNav.Link
| Prop name | Type | Description |
Expand Down
4 changes: 2 additions & 2 deletions src/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import styled from 'styled-components'
import {COMMON, get} from './constants'
import theme from './theme'

function TooltipBase({direction, children, className, text, noDelay, align, wrap}) {
function TooltipBase({direction, children, className, text, noDelay, align, wrap, ...rest}) {
const classes = classnames(
className,
`tooltipped-${direction}`,
Expand All @@ -14,7 +14,7 @@ function TooltipBase({direction, children, className, text, noDelay, align, wrap
wrap && 'tooltipped-multiline'
)
return (
<span aria-label={text} className={classes}>
<span aria-label={text} {...rest} className={classes}>
{children}
</span>
)
Expand Down
4 changes: 2 additions & 2 deletions src/UnderlineNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import theme from './theme'
const ITEM_CLASS = 'UnderlineNav-item'
const SELECTED_CLASS = 'selected'

function UnderlineNavBase({actions, className, align, children, full, label}) {
function UnderlineNavBase({actions, className, align, children, full, label, ...rest}) {
const classes = classnames(className, 'UnderlineNav', align && `UnderlineNav--${align}`, full && 'UnderlineNav--full')
return (
<nav className={classes} aria-label={label}>
<nav className={classes} aria-label={label} {...rest}>
<div className="UnderlineNav-body">{children}</div>
{actions && <div className="UnderlineNav-actions">{actions}</div>}
</nav>
Expand Down