Skip to content

Commit

Permalink
[core] Remove delayType prop across hoverable popup components (mui…
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks authored Oct 15, 2024
1 parent 6d7156a commit 18256f6
Show file tree
Hide file tree
Showing 21 changed files with 6 additions and 218 deletions.
4 changes: 0 additions & 4 deletions docs/data/api/popover-root.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
"closeDelay": { "type": { "name": "number" }, "default": "0" },
"defaultOpen": { "type": { "name": "bool" }, "default": "false" },
"delay": { "type": { "name": "number" }, "default": "300" },
"delayType": {
"type": { "name": "enum", "description": "'hover'<br>&#124;&nbsp;'rest'" },
"default": "'rest'"
},
"onOpenChange": { "type": { "name": "func" } },
"open": { "type": { "name": "bool" }, "default": "false" },
"openOnHover": { "type": { "name": "bool" }, "default": "false" }
Expand Down
4 changes: 0 additions & 4 deletions docs/data/api/preview-card-root.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
"closeDelay": { "type": { "name": "number" }, "default": "300" },
"defaultOpen": { "type": { "name": "bool" }, "default": "false" },
"delay": { "type": { "name": "number" }, "default": "600" },
"delayType": {
"type": { "name": "enum", "description": "'hover'<br>&#124;&nbsp;'rest'" },
"default": "'rest'"
},
"onOpenChange": { "type": { "name": "func" } },
"open": { "type": { "name": "bool" }, "default": "false" }
},
Expand Down
4 changes: 0 additions & 4 deletions docs/data/api/tooltip-root.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
"closeDelay": { "type": { "name": "number" }, "default": "0" },
"defaultOpen": { "type": { "name": "bool" }, "default": "false" },
"delay": { "type": { "name": "number" }, "default": "600" },
"delayType": {
"type": { "name": "enum", "description": "'hover'<br>&#124;&nbsp;'rest'" },
"default": "'rest'"
},
"hoverable": { "type": { "name": "bool" }, "default": "true" },
"onOpenChange": { "type": { "name": "func" } },
"open": { "type": { "name": "bool" }, "default": "false" },
Expand Down
6 changes: 0 additions & 6 deletions docs/data/components/popover/popover.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@ To change how long the popover waits until it opens or closes when `openOnHover`
<Popover.Root openOnHover delay={200} closeDelay={200}>
```

The delay type can be changed from `"rest"` (user's cursor is static over the trigger for the given timeout in milliseconds) to `"hover"` (the user's cursor has entered the trigger):

```jsx
<Popover.Root openOnHover delayType="hover">
```

## Controlled

To control the popover with external state, use the `open` and `onOpenChange` props:
Expand Down
6 changes: 0 additions & 6 deletions docs/data/components/preview-card/preview-card.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,6 @@ To change how long the Preview Card waits until it opens or closes, use the `del
<PreviewCard.Root delay={200} closeDelay={200}>
```

The delay type can be changed from `"rest"` (user's cursor is static over the trigger for the given timeout in milliseconds) to `"hover"` (the user's cursor has entered the trigger):

```jsx
<PreviewCard.Root delayType="hover">
```

## Controlled

To control the Preview Card with external state, use the `open` and `onOpenChange` props:
Expand Down
6 changes: 0 additions & 6 deletions docs/data/components/tooltip/tooltip.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@ To change how long the tooltip waits until it opens or closes, use the `delay` a
<Tooltip.Root delay={200} closeDelay={200}>
```

The delay type can be changed from `"rest"` (user's cursor is static over the trigger for the given timeout in milliseconds) to `"hover"` (the user's cursor has entered the trigger):

```jsx
<Tooltip.Root delayType="hover">
```

## Controlled

To control the tooltip with external state, use the `open` and `onOpenChange` props:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
"delay": {
"description": "The delay in milliseconds until the popover popup is opened when <code>openOnHover</code> is <code>true</code>."
},
"delayType": {
"description": "The delay type to use when <code>openOnHover</code> is <code>true</code>. <code>rest</code> means the <code>delay</code> represents how long the user&#39;s cursor must rest on the trigger before the popover popup is opened. <code>hover</code> means the <code>delay</code> represents how long to wait as soon as the user&#39;s cursor has entered the trigger."
},
"onOpenChange": {
"description": "Callback fired when the popover popup is requested to be opened or closed. Use when controlled."
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
"delay": {
"description": "The delay in milliseconds until the preview card popup is opened when <code>openOnHover</code> is <code>true</code>."
},
"delayType": {
"description": "The delay type to use when the preview card is triggered by hover. <code>rest</code> means the <code>delay</code> represents how long the user&#39;s cursor must rest on the trigger before the preview card popup is opened. <code>hover</code> means the <code>delay</code> represents how long to wait as soon as the user&#39;s cursor has entered the trigger."
},
"onOpenChange": {
"description": "Callback fired when the preview card popup is requested to be opened or closed. Use when controlled."
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
"description": "Whether the tooltip popup is open by default. Use when uncontrolled."
},
"delay": { "description": "The delay in milliseconds until the tooltip popup is opened." },
"delayType": {
"description": "The delay type to use. <code>rest</code> means the <code>delay</code> represents how long the user&#39;s cursor must rest on the trigger before the tooltip popup is opened. <code>hover</code> means the <code>delay</code> represents how long to wait as soon as the user&#39;s cursor has entered the trigger."
},
"hoverable": {
"description": "Whether the user can move their cursor from the trigger element toward the tooltip popup element without it closing using a &quot;safe polygon&quot; technique."
},
Expand Down
26 changes: 0 additions & 26 deletions packages/mui-base/src/Popover/Root/PopoverRoot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,32 +263,6 @@ describe('<Popover.Root />', () => {

expect(screen.getByText('Content')).not.to.equal(null);
});

it('should open after delay with hover type', async () => {
await render(
<Root openOnHover delayType="hover">
<Popover.Trigger />
<Popover.Positioner>
<Popover.Popup>Content</Popover.Popup>
</Popover.Positioner>
</Root>,
);

const anchor = screen.getByRole('button');

fireEvent.mouseEnter(anchor);
clock.tick(OPEN_DELAY / 2);

await flushMicrotasks();

expect(screen.queryByText('Content')).to.equal(null);

clock.tick(OPEN_DELAY / 2);

await flushMicrotasks();

expect(screen.getByText('Content')).not.to.equal(null);
});
});

describe('prop: closeDelay', () => {
Expand Down
13 changes: 1 addition & 12 deletions packages/mui-base/src/Popover/Root/PopoverRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { OPEN_DELAY } from '../utils/constants';
* - [PopoverRoot API](https://base-ui.netlify.app/components/react-popover/#api-reference-PopoverRoot)
*/
const PopoverRoot: React.FC<PopoverRoot.Props> = function PopoverRoot(props) {
const { openOnHover = false, delayType = 'rest', delay, closeDelay = 0, animated = true } = props;
const { openOnHover = false, delay, closeDelay = 0, animated = true } = props;

const delayWithDefault = delay ?? OPEN_DELAY;

Expand All @@ -43,7 +43,6 @@ const PopoverRoot: React.FC<PopoverRoot.Props> = function PopoverRoot(props) {
} = usePopoverRoot({
openOnHover,
delay: delayWithDefault,
delayType,
closeDelay,
animated,
open: props.open,
Expand All @@ -55,7 +54,6 @@ const PopoverRoot: React.FC<PopoverRoot.Props> = function PopoverRoot(props) {
() => ({
openOnHover,
delay: delayWithDefault,
delayType,
closeDelay,
open,
setOpen,
Expand All @@ -79,7 +77,6 @@ const PopoverRoot: React.FC<PopoverRoot.Props> = function PopoverRoot(props) {
[
openOnHover,
delayWithDefault,
delayType,
closeDelay,
open,
setOpen,
Expand Down Expand Up @@ -145,14 +142,6 @@ PopoverRoot.propTypes /* remove-proptypes */ = {
* @default 300
*/
delay: PropTypes.number,
/**
* The delay type to use when `openOnHover` is `true`. `rest` means the `delay` represents how
* long the user's cursor must rest on the trigger before the popover popup is opened. `hover`
* means the `delay` represents how long to wait as soon as the user's cursor has entered the
* trigger.
* @default 'rest'
*/
delayType: PropTypes.oneOf(['hover', 'rest']),
/**
* Callback fired when the popover popup is requested to be opened or closed. Use when
* controlled.
Expand Down
1 change: 0 additions & 1 deletion packages/mui-base/src/Popover/Root/PopoverRootContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export interface PopoverRootContext {
popupRef: React.RefObject<HTMLElement | null>;
delay: number;
closeDelay: number;
delayType: 'rest' | 'hover';
instantType: 'dismiss' | 'click' | undefined;
mounted: boolean;
setMounted: React.Dispatch<React.SetStateAction<boolean>>;
Expand Down
17 changes: 1 addition & 16 deletions packages/mui-base/src/Popover/Root/usePopoverRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export function usePopoverRoot(params: usePopoverRoot.Parameters): usePopoverRoo
onOpenChange: onOpenChangeProp = () => {},
defaultOpen = false,
keepMounted = false,
delayType = 'rest',
delay,
closeDelay,
openOnHover = false,
Expand Down Expand Up @@ -96,12 +95,7 @@ export function usePopoverRoot(params: usePopoverRoot.Parameters): usePopoverRoo
},
});

const computedRestMs = delayType === 'rest' ? delayWithDefault : undefined;
let computedOpenDelay: number | undefined = delayType === 'hover' ? delayWithDefault : undefined;

if (delayType === 'hover') {
computedOpenDelay = delay == null ? delayWithDefault : delay;
}
const computedRestMs = delayWithDefault;

const hover = useHover(context, {
enabled: openOnHover,
Expand All @@ -110,7 +104,6 @@ export function usePopoverRoot(params: usePopoverRoot.Parameters): usePopoverRoo
handleClose: safePolygon(),
restMs: computedRestMs,
delay: {
open: computedOpenDelay,
close: closeDelayWithDefault,
},
});
Expand Down Expand Up @@ -191,14 +184,6 @@ export namespace usePopoverRoot {
* @default 0
*/
closeDelay?: number;
/**
* The delay type to use when `openOnHover` is `true`. `rest` means the `delay` represents how
* long the user's cursor must rest on the trigger before the popover popup is opened. `hover`
* means the `delay` represents how long to wait as soon as the user's cursor has entered the
* trigger.
* @default 'rest'
*/
delayType?: 'rest' | 'hover';
/**
* Whether the popover popup element stays mounted in the DOM when closed.
* @default false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export interface PreviewCardRootContext {
setPositionerElement: (el: HTMLElement | null) => void;
delay: number;
closeDelay: number;
delayType: 'rest' | 'hover';
mounted: boolean;
setMounted: React.Dispatch<React.SetStateAction<boolean>>;
getRootTriggerProps: (externalProps?: GenericHTMLProps) => GenericHTMLProps;
Expand Down
26 changes: 0 additions & 26 deletions packages/mui-base/src/PreviewCard/Root/PreviewCardRoot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,32 +330,6 @@ describe('<PreviewCard.Root />', () => {

expect(screen.getByText('Content')).not.to.equal(null);
});

it('should open after delay with hover type', async () => {
await render(
<Root delayType="hover">
<Trigger />
<PreviewCard.Positioner>
<PreviewCard.Popup>Content</PreviewCard.Popup>
</PreviewCard.Positioner>
</Root>,
);

const trigger = screen.getByRole('link');

fireEvent.mouseEnter(trigger);
clock.tick(OPEN_DELAY - 100);

await flushMicrotasks();

expect(screen.queryByText('Content')).to.equal(null);

clock.tick(100);

await flushMicrotasks();

expect(screen.getByText('Content')).not.to.equal(null);
});
});

describe('prop: closeDelay', () => {
Expand Down
13 changes: 1 addition & 12 deletions packages/mui-base/src/PreviewCard/Root/PreviewCardRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CLOSE_DELAY, OPEN_DELAY } from '../utils/constants';
* - [PreviewCardRoot API](https://base-ui.netlify.app/components/react-preview-card/#api-reference-PreviewCardRoot)
*/
const PreviewCardRoot: React.FC<PreviewCardRoot.Props> = function PreviewCardRoot(props) {
const { delayType = 'rest', delay, closeDelay, animated = true } = props;
const { delay, closeDelay, animated = true } = props;

const delayWithDefault = delay ?? OPEN_DELAY;
const closeDelayWithDefault = closeDelay ?? CLOSE_DELAY;
Expand All @@ -39,7 +39,6 @@ const PreviewCardRoot: React.FC<PreviewCardRoot.Props> = function PreviewCardRoo
} = usePreviewCardRoot({
animated,
delay,
delayType,
closeDelay,
open: props.open,
onOpenChange: props.onOpenChange,
Expand All @@ -49,7 +48,6 @@ const PreviewCardRoot: React.FC<PreviewCardRoot.Props> = function PreviewCardRoo
const contextValue = React.useMemo(
() => ({
delay: delayWithDefault,
delayType,
closeDelay: closeDelayWithDefault,
open,
setOpen,
Expand All @@ -68,7 +66,6 @@ const PreviewCardRoot: React.FC<PreviewCardRoot.Props> = function PreviewCardRoo
}),
[
delayWithDefault,
delayType,
closeDelayWithDefault,
open,
setOpen,
Expand Down Expand Up @@ -132,14 +129,6 @@ PreviewCardRoot.propTypes /* remove-proptypes */ = {
* @default 600
*/
delay: PropTypes.number,
/**
* The delay type to use when the preview card is triggered by hover. `rest` means the `delay`
* represents how long the user's cursor must rest on the trigger before the preview card popup is
* opened. `hover` means the `delay` represents how long to wait as soon as the user's cursor has
* entered the trigger.
* @default 'rest'
*/
delayType: PropTypes.oneOf(['hover', 'rest']),
/**
* Callback fired when the preview card popup is requested to be opened or closed. Use when
* controlled.
Expand Down
17 changes: 1 addition & 16 deletions packages/mui-base/src/PreviewCard/Root/usePreviewCardRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export function usePreviewCardRoot(
defaultOpen = false,
keepMounted = false,
animated = true,
delayType = 'rest',
delay,
closeDelay,
} = params;
Expand Down Expand Up @@ -98,20 +97,14 @@ export function usePreviewCardRoot(
});

const instantType = instantTypeState;
const computedRestMs = delayType === 'rest' ? delayWithDefault : undefined;
let computedOpenDelay: number | undefined = delayType === 'hover' ? delayWithDefault : undefined;

if (delayType === 'hover') {
computedOpenDelay = delay == null ? delayWithDefault : delay;
}
const computedRestMs = delayWithDefault;

const hover = useHover(context, {
mouseOnly: true,
move: false,
handleClose: safePolygon(),
restMs: computedRestMs,
delay: {
open: computedOpenDelay,
close: closeDelayWithDefault,
},
});
Expand Down Expand Up @@ -186,14 +179,6 @@ export namespace usePreviewCardRoot {
* @default 300
*/
closeDelay?: number;
/**
* The delay type to use when the preview card is triggered by hover. `rest` means the `delay`
* represents how long the user's cursor must rest on the trigger before the preview card popup is
* opened. `hover` means the `delay` represents how long to wait as soon as the user's cursor has
* entered the trigger.
* @default 'rest'
*/
delayType?: 'rest' | 'hover';
/**
* Whether the preview card popup element stays mounted in the DOM when closed.
* @default false
Expand Down
Loading

0 comments on commit 18256f6

Please sign in to comment.