a11y: Try to make screenreaders read tooltips

Refs #1835.
This commit is contained in:
Franz Liedke 2019-08-08 22:40:30 +02:00
parent b3019e72fe
commit 1702929079

View File

@ -29,6 +29,12 @@ export default class Button extends Component {
attrs.className = attrs.className || ''; attrs.className = attrs.className || '';
attrs.type = attrs.type || 'button'; attrs.type = attrs.type || 'button';
// If a tooltip was provided for buttons without additional content, we also
// use this tooltip as text for screen readers
if (attrs.title && !this.props.children) {
attrs['aria-label'] = attrs.title;
}
// If nothing else is provided, we use the textual button content as tooltip // If nothing else is provided, we use the textual button content as tooltip
if (!attrs.title && this.props.children) { if (!attrs.title && this.props.children) {
attrs.title = extractText(this.props.children); attrs.title = extractText(this.props.children);