Skip to content

Commit

Permalink
Replace tooltip prop with showTooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Dec 18, 2019
1 parent b9d72e4 commit 2ca5ed5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
14 changes: 6 additions & 8 deletions packages/components/src/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function Button( props, ref ) {
disabled,
icon,
iconSize,
tooltip,
showTooltip,
tooltipPosition,
shortcut,
label,
Expand Down Expand Up @@ -69,9 +69,9 @@ export function Button( props, ref ) {
{ type: 'button', disabled, 'aria-pressed': isPressed };

// Should show the tooltip if...
const showTooltip = ! disabled && (
const shouldShowTooltip = ! disabled && (
// an explicit tooltip is passed or...
tooltip ||
( showTooltip && label ) ||
// there's a shortcut or...
shortcut ||
(
Expand All @@ -80,7 +80,7 @@ export function Button( props, ref ) {
// the children are empty and...
( ! children || ( isArray( children ) && ! children.length ) ) &&
// the tooltip is not explicitly disabled.
false !== tooltip
false !== showTooltip
)
);

Expand All @@ -97,14 +97,12 @@ export function Button( props, ref ) {
</Tag>
);

if ( ! showTooltip ) {
if ( ! shouldShowTooltip ) {
return element;
}

const tooltipText = tooltip || label;

return (
<Tooltip text={ tooltipText } shortcut={ shortcut } position={ tooltipPosition }>
<Tooltip text={ label } shortcut={ shortcut } position={ tooltipPosition }>
{ element }
</Tooltip>
);
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/icon-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import Button from '../button';
function IconButton( {
labelPosition,
size,
tooltip,
label,
...props
}, ref ) {
return (
Expand All @@ -19,6 +21,8 @@ function IconButton( {
ref={ ref }
tooltipPosition={ labelPosition }
iconSize={ size }
showTooltip={ tooltip !== undefined ? !! tooltip : undefined }
label={ tooltip || label }
/>
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/icon-button/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ describe( 'IconButton', () => {
} );

it( 'should allow custom tooltip text', () => {
const iconButton = shallow( <IconButton label="WordPress" tooltip="Custom" /> );
const iconButton = shallow( <IconButton tooltip="Custom" /> );
expect( iconButton.name() ).toBe( 'Tooltip' );
expect( iconButton.prop( 'text' ) ).toBe( 'Custom' );
expect( iconButton.find( 'ForwardRef(Button)' ).prop( 'aria-label' ) ).toBe( 'WordPress' );
expect( iconButton.find( 'ForwardRef(Button)' ).prop( 'aria-label' ) ).toBe( 'Custom' );
} );

it( 'should allow tooltip disable', () => {
Expand Down

0 comments on commit 2ca5ed5

Please sign in to comment.