Skip to content

Commit 7e75437

Browse files
authored
Merge pull request #97 from dsumer/master
Added Screenreader-Support with ariaId
2 parents af0a7a1 + b5e7030 commit 7e75437

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,32 @@ Online examples: [http://react-component.github.io/tooltip/examples/](http://rea
181181
<td>false</td>
182182
<td>whether destroy tooltip when tooltip is hidden</td>
183183
</tr>
184+
<tr>
185+
<td>id</td>
186+
<td>String</td>
187+
<td></td>
188+
<td>Id which gets attached to the tooltip content. Can be used with aria-describedby to achieve Screenreader-Support.</td>
189+
</tr>
184190
</tbody>
185191
</table>
186192

187193
## Note
188194

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

197+
## Accessibility
198+
199+
For accessibility purpose you can use the `id` prop to link your tooltip with another element. For example attaching it to an input element:
200+
```jsx
201+
<Tooltip
202+
...
203+
id={this.props.name}>
204+
<input type="text"
205+
...
206+
aria-describedby={this.props.name}/>
207+
</Tooltip>
208+
```
209+
If you do it like this, a screenreader would read the content of your tooltip if you focus the input element.
191210

192211
## Development
193212

src/Tooltip.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Tooltip extends Component {
2727
destroyTooltipOnHide: PropTypes.bool,
2828
align: PropTypes.object,
2929
arrowContent: PropTypes.any,
30+
id: PropTypes.string,
3031
};
3132

3233
static defaultProps = {
@@ -41,12 +42,12 @@ class Tooltip extends Component {
4142
};
4243

4344
getPopupElement = () => {
44-
const { arrowContent, overlay, prefixCls } = this.props;
45+
const { arrowContent, overlay, prefixCls, id } = this.props;
4546
return ([
4647
<div className={`${prefixCls}-arrow`} key="arrow">
4748
{arrowContent}
4849
</div>,
49-
<div className={`${prefixCls}-inner`} key="content">
50+
<div className={`${prefixCls}-inner`} key="content" id={id}>
5051
{typeof overlay === 'function' ? overlay() : overlay}
5152
</div>,
5253
]);

0 commit comments

Comments
 (0)