Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
"@rc-component/motion": "^1.1.4",
"@rc-component/portal": "^2.2.0",
"@rc-component/resize-observer": "^1.1.1",
"@rc-component/util": "^1.2.1",
"@rc-component/util": "^1.11.1",
"clsx": "^2.1.1"
},
"devDependencies": {
"@rc-component/father-plugin": "^2.0.0",
"@rc-component/father-plugin": "^2.2.0",
"@rc-component/np": "^1.0.3",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^16.0.0",
Expand Down
4 changes: 1 addition & 3 deletions src/Popup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import CSSMotion from '@rc-component/motion';
import ResizeObserver, {
type ResizeObserverProps,
} from '@rc-component/resize-observer';
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
import { composeRef } from '@rc-component/util/lib/ref';
import { composeRef, useEvent, useLayoutEffect } from '@rc-component/util';
import * as React from 'react';
import type { TriggerProps } from '../';
import type { AlignType, ArrowPos, ArrowTypeOuter } from '../interface';
import Arrow from './Arrow';
import Mask from './Mask';
import PopupContent from './PopupContent';
import useOffsetStyle from '../hooks/useOffsetStyle';
import { useEvent } from '@rc-component/util';
import type { PortalProps } from '@rc-component/portal';

export interface MobileConfig {
Expand Down
3 changes: 1 addition & 2 deletions src/UniqueProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import TriggerContext, {
import useDelay from '../hooks/useDelay';
import useAlign from '../hooks/useAlign';
import Popup from '../Popup';
import { useEvent } from '@rc-component/util';
import { isDOM, useEvent } from '@rc-component/util';
import useTargetState from './useTargetState';
import { isDOM } from '@rc-component/util/lib/Dom/findDOMNode';
import UniqueContainer from './UniqueContainer';
import { clsx } from 'clsx';
import { getAlignPopupClassName } from '../util';
Expand Down
10 changes: 6 additions & 4 deletions src/hooks/useAlign.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { isDOM } from '@rc-component/util/lib/Dom/findDOMNode';
import isVisible from '@rc-component/util/lib/Dom/isVisible';
import useEvent from '@rc-component/util/lib/hooks/useEvent';
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
import {
isDOM,
isVisible,
useEvent,
useLayoutEffect,
} from '@rc-component/util';
import * as React from 'react';
import type { TriggerProps } from '..';
import type {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useWatch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
import { useLayoutEffect } from '@rc-component/util';
import { collectScroller, getWin } from '../util';

export default function useWatch(
Expand Down
3 changes: 1 addition & 2 deletions src/hooks/useWinClick.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getShadowRoot } from '@rc-component/util/lib/Dom/shadow';
import { warning } from '@rc-component/util/lib/warning';
import { getShadowRoot, warning } from '@rc-component/util';
import * as React from 'react';
import { getWin } from '../util';

Expand Down
61 changes: 52 additions & 9 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ import Portal from '@rc-component/portal';
import { clsx } from 'clsx';
import type { CSSMotionProps } from '@rc-component/motion';
import { useResizeObserver } from '@rc-component/resize-observer';
import { getDOM, isDOM } from '@rc-component/util/lib/Dom/findDOMNode';
import { getShadowRoot } from '@rc-component/util/lib/Dom/shadow';
import { getNodeRef, useComposeRef } from '@rc-component/util/lib/ref';
import useEvent from '@rc-component/util/lib/hooks/useEvent';
import useId from '@rc-component/util/lib/hooks/useId';
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
import {
getDOM,
getNodeRef,
getShadowRoot,
isDOM,
supportRef,
useComposeRef,
useControlledState,
useEvent,
useId,
useLayoutEffect,
} from '@rc-component/util';
import * as React from 'react';
import Popup, { type MobileConfig } from './Popup';
import type { TriggerContextProps } from './context';
Expand All @@ -22,6 +28,7 @@ import type { PortalProps } from '@rc-component/portal';
import type {
ActionType,
AlignType,
AnimationType,
ArrowPos,
ArrowTypeOuter,
BuildInPlacements,
Expand All @@ -31,12 +38,12 @@ import { getAlignPopupClassName } from './util';
export type {
ActionType,
AlignType,
AnimationType,
ArrowTypeOuter as ArrowType,
BuildInPlacements,
};

import UniqueProvider, { type UniqueProviderProps } from './UniqueProvider';
import { useControlledState } from '@rc-component/util';
import { flushSync } from 'react-dom';

export { UniqueProvider };
Expand Down Expand Up @@ -791,13 +798,17 @@ export function generateTrigger(
useResizeObserver(mergedOpen, targetEle, onTargetResize);

// Compose refs
const mergedRef = useComposeRef(setTargetRef, getNodeRef(child));
const childSupportRef = supportRef(child);
const mergedRef = useComposeRef(
setTargetRef,
childSupportRef ? getNodeRef(child) : null,
);

// Child Node
const triggerNode = React.cloneElement(child, {
...mergedChildrenProps,
...passedProps,
ref: mergedRef,
ref: childSupportRef ? mergedRef : undefined,
});

// Render
Expand Down Expand Up @@ -869,4 +880,36 @@ export function generateTrigger(
return Trigger;
}

interface MockPortalProps {
open?: boolean;
autoDestroy?: boolean;
children: React.ReactElement<any>;
getContainer?: () => HTMLElement;
}

const MockPortal: React.FC<MockPortalProps> = ({
open,
autoDestroy,
children,
getContainer,
}) => {
const [visible, setVisible] = React.useState(open);

React.useEffect(() => {
getContainer?.();
});
Comment thread
QDyanbing marked this conversation as resolved.
Outdated

React.useEffect(() => {
if (open) {
setVisible(true);
} else if (autoDestroy) {
setVisible(false);
}
}, [open, autoDestroy]);

return visible ? children : null;
};

export const MockTrigger = generateTrigger(MockPortal);

export default generateTrigger(Portal);
37 changes: 1 addition & 36 deletions src/mock.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1 @@
import * as React from 'react';
import { generateTrigger, UniqueProvider } from './index';

interface MockPortalProps {
open?: boolean;
autoDestroy?: boolean;
children: React.ReactElement<any>;
getContainer?: () => HTMLElement;
}

const MockPortal: React.FC<MockPortalProps> = ({
open,
autoDestroy,
children,
getContainer,
}) => {
const [visible, setVisible] = React.useState(open);

React.useEffect(() => {
getContainer?.();
});

React.useEffect(() => {
if (open) {
setVisible(true);
} else if (autoDestroy) {
setVisible(false);
}
}, [open, autoDestroy]);

return visible ? children : null;
};

export default generateTrigger(MockPortal);

export { UniqueProvider };
export { MockTrigger as default, UniqueProvider } from './index';
2 changes: 1 addition & 1 deletion tests/align.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { act, cleanup, fireEvent, render } from '@testing-library/react';
import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
import { spyElementPrototypes } from '@rc-component/util';
import React from 'react';
import type { TriggerProps, TriggerRef } from '../src';
import Trigger from '../src';
Expand Down
5 changes: 1 addition & 4 deletions tests/arrow.test.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/* eslint-disable max-classes-per-file */

import { act, cleanup, render } from '@testing-library/react';
import {
spyElementPrototype,
spyElementPrototypes,
} from '@rc-component/util/lib/test/domHook';
import { spyElementPrototype, spyElementPrototypes } from '@rc-component/util';
import Trigger from '../src';

describe('Trigger.Arrow', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/basic.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable max-classes-per-file */
import { act, cleanup, fireEvent, render } from '@testing-library/react';
import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
import { spyElementPrototypes } from '@rc-component/util';
import React, { StrictMode, createRef } from 'react';
import ReactDOM, { createPortal } from 'react-dom';
import Trigger from '../src';
Expand Down
2 changes: 1 addition & 1 deletion tests/flip-visibleFirst.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-invalid-this */
import { act, cleanup, render } from '@testing-library/react';
import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
import { spyElementPrototypes } from '@rc-component/util';
import * as React from 'react';
import type { AlignType, TriggerProps, TriggerRef } from '../src';
import Trigger from '../src';
Expand Down
2 changes: 1 addition & 1 deletion tests/flip.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, cleanup, render } from '@testing-library/react';
import { _rs } from '@rc-component/resize-observer';
import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
import { spyElementPrototypes } from '@rc-component/util';
import * as React from 'react';
import type { AlignType, TriggerProps } from '../src';
import Trigger from '../src';
Expand Down
2 changes: 1 addition & 1 deletion tests/flipShift.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { act, cleanup, render } from '@testing-library/react';
import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
import { spyElementPrototypes } from '@rc-component/util';
import React from 'react';
import Trigger from '../src';

Expand Down
2 changes: 1 addition & 1 deletion tests/mobile.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { act, fireEvent, render } from '@testing-library/react';
import isMobile from '@rc-component/util/lib/isMobile';
import { isMobile } from '@rc-component/util';
import React from 'react';
import Trigger, { type TriggerProps } from '../src';
import { placementAlignMap } from './util';
Expand Down
2 changes: 1 addition & 1 deletion tests/open-change.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { act, cleanup, fireEvent, render } from '@testing-library/react';
import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
import { spyElementPrototypes } from '@rc-component/util';
import * as React from 'react';
import Trigger from '../src';

Expand Down
2 changes: 1 addition & 1 deletion tests/perf.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cleanup, fireEvent, render } from '@testing-library/react';
import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
import { spyElementPrototypes } from '@rc-component/util';
import React from 'react';
import Trigger, { type TriggerProps } from '../src';
import { awaitFakeTimer, placementAlignMap } from './util';
Expand Down
2 changes: 1 addition & 1 deletion tests/portal.test.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable max-classes-per-file */

import { act, cleanup, fireEvent, render } from '@testing-library/react';
import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
import { spyElementPrototypes } from '@rc-component/util';
import React from 'react';
import ReactDOM from 'react-dom';
import Trigger from '../src';
Expand Down
2 changes: 1 addition & 1 deletion tests/rect.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cleanup, render } from '@testing-library/react';
import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
import { spyElementPrototypes } from '@rc-component/util';
import React from 'react';
import Trigger from '../src';
import { awaitFakeTimer } from './util';
Expand Down
2 changes: 1 addition & 1 deletion tests/ref.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable max-classes-per-file */

import { cleanup, render } from '@testing-library/react';
import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
import { spyElementPrototypes } from '@rc-component/util';
import React from 'react';
import Trigger, { type TriggerRef } from '../src';

Expand Down
2 changes: 1 addition & 1 deletion tests/shadow.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { act, fireEvent } from '@testing-library/react';
import { resetWarned } from '@rc-component/util/lib/warning';
import { resetWarned } from '@rc-component/util';
import React from 'react';
import { createRoot } from 'react-dom/client';
import Trigger from '../src';
Expand Down
Loading