Skip to content

Commit 9493245

Browse files
yihuiliaoLFDanLu
andauthored
chore: rename closeOnPress to shouldCloseOnPress (#9337)
* chore: rename closeOnPress to shouldCloseOnPress * fix test * update doc example --------- Co-authored-by: Daniel Lu <[email protected]>
1 parent 810a385 commit 9493245

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

packages/@react-aria/tooltip/src/useTooltipTrigger.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTrig
3737
let {
3838
isDisabled,
3939
trigger,
40-
closeOnPress = true
40+
shouldCloseOnPress = true
4141
} = props;
4242

4343
let tooltipId = useId();
@@ -103,8 +103,8 @@ export function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTrig
103103
};
104104

105105
let onPressStart = () => {
106-
// if closeOnPress is false, we should not close the tooltip
107-
if (!closeOnPress) {
106+
// if shouldCloseOnPress is false, we should not close the tooltip
107+
if (!shouldCloseOnPress) {
108108
return;
109109
}
110110
// no matter how the trigger is pressed, we should close the tooltip

packages/@react-spectrum/tooltip/src/TooltipTrigger.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {useTooltipTriggerState} from '@react-stately/tooltip';
2222

2323
const DEFAULT_OFFSET = -1; // Offset needed to reach 4px/5px (med/large) distance between tooltip and trigger button
2424
const DEFAULT_CROSS_OFFSET = 0;
25-
const DEFAULT_CLOSE_ON_PRESS = true; // Whether the tooltip should close when the trigger is pressed
25+
const DEFAULT_SHOULD_CLOSE_ON_PRESS = true; // Whether the tooltip should close when the trigger is pressed
2626

2727
function TooltipTrigger(props: SpectrumTooltipTriggerProps) {
2828
let {
@@ -31,7 +31,7 @@ function TooltipTrigger(props: SpectrumTooltipTriggerProps) {
3131
isDisabled,
3232
offset = DEFAULT_OFFSET,
3333
trigger: triggerAction,
34-
closeOnPress = DEFAULT_CLOSE_ON_PRESS
34+
shouldCloseOnPress = DEFAULT_SHOULD_CLOSE_ON_PRESS
3535
} = props;
3636

3737
let [trigger, tooltip] = React.Children.toArray(children) as [ReactElement, ReactElement];
@@ -43,7 +43,7 @@ function TooltipTrigger(props: SpectrumTooltipTriggerProps) {
4343
let {triggerProps, tooltipProps} = useTooltipTrigger({
4444
isDisabled,
4545
trigger: triggerAction,
46-
closeOnPress
46+
shouldCloseOnPress
4747
}, state, tooltipTriggerRef);
4848

4949
let [borderRadius, setBorderRadius] = useState(0);

packages/@react-spectrum/tooltip/stories/TooltipTrigger.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const argTypes = {
7373
children: {
7474
control: {disable: true}
7575
},
76-
closeOnPress: {
76+
shouldCloseOnPress: {
7777
control: 'boolean'
7878
}
7979
};
@@ -117,7 +117,7 @@ export default {
117117
<Tooltip>Change Name</Tooltip>
118118
],
119119
onOpenChange: action('openChange'),
120-
closeOnPress: true
120+
shouldCloseOnPress: true
121121
},
122122
argTypes: argTypes
123123
} as Meta<typeof TooltipTrigger>;

packages/@react-spectrum/tooltip/test/TooltipTrigger.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,10 @@ describe('TooltipTrigger', function () {
330330
expect(queryByRole('tooltip')).toBeNull();
331331
});
332332

333-
it('does not close if the trigger is clicked when closeOnPress is false', async () => {
333+
it('does not close if the trigger is clicked when shouldCloseOnPress is false', async () => {
334334
let {getByRole, getByLabelText} = render(
335335
<Provider theme={theme}>
336-
<TooltipTrigger onOpenChange={onOpenChange} delay={0} closeOnPress={false}>
336+
<TooltipTrigger onOpenChange={onOpenChange} delay={0} shouldCloseOnPress={false}>
337337
<ActionButton aria-label="trigger" />
338338
<Tooltip>Helpful information.</Tooltip>
339339
</TooltipTrigger>
@@ -351,10 +351,10 @@ describe('TooltipTrigger', function () {
351351
expect(tooltip).toBeVisible();
352352
});
353353

354-
it('does not close if the trigger is clicked with the keyboard when closeOnPress is false', async () => {
354+
it('does not close if the trigger is clicked with the keyboard when shouldCloseOnPress is false', async () => {
355355
let {getByRole, getByLabelText} = render(
356356
<Provider theme={theme}>
357-
<TooltipTrigger onOpenChange={onOpenChange} delay={0} closeOnPress={false}>
357+
<TooltipTrigger onOpenChange={onOpenChange} delay={0} shouldCloseOnPress={false}>
358358
<ActionButton aria-label="trigger" />
359359
<Tooltip>Helpful information.</Tooltip>
360360
</TooltipTrigger>

packages/@react-types/tooltip/src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface TooltipTriggerProps extends OverlayTriggerProps {
4242
* Whether the tooltip should close when the trigger is pressed.
4343
* @default true
4444
*/
45-
closeOnPress?: boolean
45+
shouldCloseOnPress?: boolean
4646
}
4747

4848
export interface SpectrumTooltipTriggerProps extends Omit<TooltipTriggerProps, 'closeDelay'>, PositionProps {

packages/dev/s2-docs/pages/s2/Tooltip.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const description = 'Displays a description of an element on hover or foc
1111

1212
<PageDescription>{docs.exports.Tooltip.description}</PageDescription>
1313

14-
```tsx render docs={docs.exports.TooltipTrigger} links={docs.links} props={['placement', 'crossOffset', 'shouldFlip']} type="s2"
14+
```tsx render docs={docs.exports.TooltipTrigger} links={docs.links} props={['placement', 'crossOffset', 'shouldFlip', 'shouldCloseOnPress']} type="s2"
1515
"use client";
1616
import {Tooltip, TooltipTrigger, ActionButton} from '@react-spectrum/s2';
1717
import Edit from '@react-spectrum/s2/icons/Edit';

0 commit comments

Comments
 (0)