Skip to content

Added Screenreader-Support with ariaId #97

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

Merged
merged 7 commits into from
Sep 28, 2017
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
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,32 @@ Online examples: [http://react-component.github.io/tooltip/examples/](http://rea
<td>false</td>
<td>whether destroy tooltip when tooltip is hidden</td>
</tr>
<tr>
<td>id</td>
<td>String</td>
<td></td>
<td>Id which gets attached to the tooltip content. Can be used with aria-describedby to achieve Screenreader-Support.</td>
</tr>
</tbody>
</table>

## Note

`Tooltip` requires child node accepts `onMouseEnter`, `onMouseLeave`, `onFocus`, `onClick` event.

## Accessibility

For accessibility purpose you can use the `id` prop to link your tooltip with another element. For example attaching it to an input element:
```jsx
<Tooltip
...
id={this.props.name}>
<input type="text"
...
aria-describedby={this.props.name}/>
</Tooltip>
```
If you do it like this, a screenreader would read the content of your tooltip if you focus the input element.

## Development

Expand Down
5 changes: 3 additions & 2 deletions src/Tooltip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Tooltip extends Component {
destroyTooltipOnHide: PropTypes.bool,
align: PropTypes.object,
arrowContent: PropTypes.any,
id: PropTypes.string,
};

static defaultProps = {
Expand All @@ -41,12 +42,12 @@ class Tooltip extends Component {
};

getPopupElement = () => {
const { arrowContent, overlay, prefixCls } = this.props;
const { arrowContent, overlay, prefixCls, id } = this.props;
return ([
<div className={`${prefixCls}-arrow`} key="arrow">
{arrowContent}
</div>,
<div className={`${prefixCls}-inner`} key="content">
<div className={`${prefixCls}-inner`} key="content" id={id}>
{typeof overlay === 'function' ? overlay() : overlay}
</div>,
]);
Expand Down