Skip to content
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
4 changes: 4 additions & 0 deletions packages/ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bug Fixes

- `IconButton`: Hide tooltip when the button is truly disabled ([#75754](https://github.com/WordPress/gutenberg/pull/75754)).

### Internal

- Update `@base-ui/react` from 1.0.0 to 1.2.0 ([#75698](https://github.com/WordPress/gutenberg/pull/75698)).
Expand Down
5 changes: 5 additions & 0 deletions packages/ui/src/icon-button/icon-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const IconButton = forwardRef< HTMLButtonElement, IconButtonProps >(
className,
// Prevent accidental forwarding of `children`
children: _children,
disabled,
focusableWhenDisabled,
icon,
size,
shortcut,
Expand All @@ -31,12 +33,15 @@ export const IconButton = forwardRef< HTMLButtonElement, IconButtonProps >(
<Tooltip.Root>
<Tooltip.Trigger
ref={ ref }
disabled={ disabled && ! focusableWhenDisabled }
render={
<Button
{ ...restProps }
size={ size }
aria-label={ label }
aria-keyshortcuts={ shortcut?.ariaKeyShortcut }
disabled={ disabled }
focusableWhenDisabled={ focusableWhenDisabled }
/>
}
className={ classes }
Expand Down
33 changes: 33 additions & 0 deletions packages/ui/src/icon-button/test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,39 @@ describe( 'IconButton', () => {
expect( button ).toHaveAttribute( 'aria-disabled', 'true' );
} );

describe( 'tooltip with disabled state', () => {
it( 'does not show tooltip when truly disabled', async () => {
const user = userEvent.setup();

render( <IconButton label="Save" icon={ <svg /> } disabled /> );

const button = screen.getByRole( 'button', { name: 'Save' } );
await user.hover( button );

expect( screen.queryByText( 'Save' ) ).not.toBeInTheDocument();
} );

it( 'shows tooltip when focusably disabled', async () => {
const user = userEvent.setup();

render(
<IconButton
label="Save"
icon={ <svg /> }
disabled
focusableWhenDisabled
/>
);

const button = screen.getByRole( 'button', { name: 'Save' } );
await user.hover( button );

await waitFor( () => {
expect( screen.getByText( 'Save' ) ).toBeVisible();
} );
} );
} );

describe( 'shortcut', () => {
it( 'sets aria-keyshortcuts attribute on the button', () => {
const { rerender } = render(
Expand Down
Loading