Improve Button component to only show tooltip if textual content is available

This commit is contained in:
Franz Liedke
2016-04-01 09:51:18 +09:00
parent 1fbce0db33
commit 42c9086c32
3 changed files with 16 additions and 24 deletions

View File

@ -28,7 +28,11 @@ export default class Button extends Component {
attrs.className = attrs.className || '';
attrs.type = attrs.type || 'button';
attrs.title = attrs.title || this.getDefaultTitle();
// If nothing else is provided, we use the textual button content as tooltip
if (!attrs.title && this.props.children) {
attrs.title = extractText(attrs.title);
}
const iconName = extract(attrs, 'icon');
if (iconName) attrs.className += ' hasIcon';
@ -42,16 +46,6 @@ export default class Button extends Component {
return <button {...attrs}>{this.getButtonContent()}</button>;
}
/**
* Get the default value for the title attribute.
*
* @return string
* @protected
*/
getDefaultTitle() {
return extractText(this.props.children);
}
/**
* Get the template for the button's content.
*