Skip to content

Commit

Permalink
Stop using propagation when escape key is pressed, update useTooltipT…
Browse files Browse the repository at this point in the history
…rigger.ts (#4203)

Escape to close tooltip no longer closes dialogs
  • Loading branch information
audreyso authored Mar 15, 2023
1 parent dabf87d commit e044ef7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/@react-aria/tooltip/src/useTooltipTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTrig
// Escape after clicking something can give it keyboard focus
// dismiss tooltip on esc key press
if (e.key === 'Escape') {
e.stopPropagation();
state.close(true);
}
}
Expand Down
22 changes: 22 additions & 0 deletions packages/@react-spectrum/dialog/stories/DialogTrigger.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {Item, Menu, MenuTrigger} from '@react-spectrum/menu';
import {Provider} from '@react-spectrum/provider';
import React, {useState} from 'react';
import {storiesOf} from '@storybook/react';
import {Tooltip, TooltipTrigger} from '@react-spectrum/tooltip';

storiesOf('DialogTrigger', module)
.addParameters({providerSwitcher: {status: 'notice'}})
Expand Down Expand Up @@ -362,6 +363,27 @@ storiesOf('DialogTrigger', module)
.add(
'adjustable dialog',
() => <AdjustableDialog />
)
.add(
'withTooltip',
() => (
<div style={{display: 'flex', width: 'auto', margin: '100px 0'}}>
<DialogTrigger isDismissable>
<ActionButton>Trigger</ActionButton>
<Dialog>
<Heading>Has tooltip</Heading>
<Divider />
<Content>
<p>Pressing escape when Tooltip is open closes Tooltip and not Dialog too.</p>
<TooltipTrigger>
<Button variant="cta">Has tooltip</Button>
<Tooltip>Press escape</Tooltip>
</TooltipTrigger>
</Content>
</Dialog>
</DialogTrigger>
</div>
)
);

function render({width = 'auto', ...props}) {
Expand Down

1 comment on commit e044ef7

@rspbot
Copy link

@rspbot rspbot commented on e044ef7 Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.