diff --git a/docs/examples/case.tsx b/docs/examples/case.tsx index 060a220b..ca8c785c 100644 --- a/docs/examples/case.tsx +++ b/docs/examples/case.tsx @@ -58,7 +58,7 @@ function useControl(valuePropName: string, defaultValue: T): [T, any] { const LabelItem: React.FC<{ title: React.ReactNode; - children: React.ReactElement; + children: React.ReactElement; [prop: string]: any; }> = ({ title, children, ...rest }) => { const { type } = children; diff --git a/docs/examples/container.tsx b/docs/examples/container.tsx index 07c4380f..b3f3892d 100644 --- a/docs/examples/container.tsx +++ b/docs/examples/container.tsx @@ -64,9 +64,9 @@ export default () => { const [scale, setScale] = React.useState('1'); const [targetVisible, setTargetVisible] = React.useState(true); - const rootRef = React.useRef(); - const popHolderRef = React.useRef(); - const scrollRef = React.useRef(); + const rootRef = React.useRef(null); + const popHolderRef = React.useRef(null); + const scrollRef = React.useRef(null); React.useEffect(() => { scrollRef.current.scrollLeft = window.innerWidth; diff --git a/docs/examples/inside.tsx b/docs/examples/inside.tsx index 42c19d40..9efea425 100644 --- a/docs/examples/inside.tsx +++ b/docs/examples/inside.tsx @@ -100,7 +100,7 @@ const popupPlacement = 'bottomLeft'; export default () => { const [popupHeight, setPopupHeight] = React.useState(60); - const containerRef = React.useRef(); + const containerRef = React.useRef(null); React.useEffect(() => { containerRef.current.scrollLeft = document.defaultView.innerWidth; diff --git a/docs/examples/large-popup.tsx b/docs/examples/large-popup.tsx index e132cb0e..687db804 100644 --- a/docs/examples/large-popup.tsx +++ b/docs/examples/large-popup.tsx @@ -24,7 +24,7 @@ const builtinPlacements = { }; export default () => { - const containerRef = React.useRef(); + const containerRef = React.useRef(null); React.useEffect(() => { console.clear(); diff --git a/docs/examples/nested.tsx b/docs/examples/nested.tsx index fbd60f70..0040744c 100644 --- a/docs/examples/nested.tsx +++ b/docs/examples/nested.tsx @@ -54,8 +54,8 @@ const OuterContent = ({ getContainer }) => { }; const Test = () => { - const containerRef = React.useRef(); - const outerDivRef = React.useRef(); + const containerRef = React.useRef(null); + const outerDivRef = React.useRef(null); const innerTrigger = (
diff --git a/docs/examples/visible-fallback.tsx b/docs/examples/visible-fallback.tsx index 0c1e1ea0..8c59d881 100644 --- a/docs/examples/visible-fallback.tsx +++ b/docs/examples/visible-fallback.tsx @@ -28,7 +28,7 @@ const builtinPlacements: Record = { export default () => { const [enoughTop, setEnoughTop] = React.useState(true); - const triggerRef = React.useRef(); + const triggerRef = React.useRef(null); React.useEffect(() => { triggerRef.current?.forceAlign(); diff --git a/package.json b/package.json index 1a1e3ce5..bac6bdd3 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,13 @@ "coverage": "rc-test --coverage", "now-build": "npm run build" }, + "dependencies": { + "@rc-component/motion": "^1.1.4", + "@rc-component/portal": "^2.0.0", + "@rc-component/resize-observer": "^1.0.0", + "@rc-component/util": "^1.2.1", + "classnames": "^2.3.2" + }, "devDependencies": { "@rc-component/father-plugin": "^2.0.0", "@rc-component/np": "^1.0.3", @@ -48,7 +55,7 @@ "@types/classnames": "^2.2.10", "@types/jest": "^29.5.2", "@types/node": "^22.0.2", - "@types/react": "^18.0.0", + "@types/react": "^19.1.2", "@types/react-dom": "^19.1.2", "@umijs/fabric": "^4.0.1", "cross-env": "^7.0.1", @@ -58,20 +65,13 @@ "less": "^4.2.0", "prettier": "^3.3.3", "rc-test": "^7.0.13", - "react": "^18.0.0", - "react-dom": "^18.0.0", + "react": "^19.1.0", + "react-dom": "^19.1.0", "regenerator-runtime": "^0.14.0", "typescript": "^5.1.6" }, - "dependencies": { - "@rc-component/motion": "^1.1.4", - "@rc-component/portal": "^2.0.0", - "@rc-component/resize-observer": "^1.0.0", - "@rc-component/util": "^1.2.1", - "classnames": "^2.3.2" - }, "peerDependencies": { - "react": ">=16.9.0", - "react-dom": ">=16.9.0" + "react": ">=18.0.0", + "react-dom": ">=18.0.0" } -} \ No newline at end of file +} diff --git a/src/Popup/Arrow.tsx b/src/Popup/Arrow.tsx index c61c49eb..d6b82290 100644 --- a/src/Popup/Arrow.tsx +++ b/src/Popup/Arrow.tsx @@ -15,7 +15,7 @@ export default function Arrow(props: ArrowProps) { const { className, content } = arrow || {}; const { x = 0, y = 0 } = arrowPos; - const arrowRef = React.useRef(); + const arrowRef = React.useRef(null); // Skip if no align if (!align || !align.points) { diff --git a/src/Popup/PopupContent.tsx b/src/Popup/PopupContent.tsx index eb96dff6..12e9723b 100644 --- a/src/Popup/PopupContent.tsx +++ b/src/Popup/PopupContent.tsx @@ -6,7 +6,7 @@ export interface PopupContentProps { } const PopupContent = React.memo( - ({ children }: PopupContentProps) => children as React.ReactElement, + ({ children }: PopupContentProps) => children as React.ReactElement, (_, next) => next.cache, ); diff --git a/src/TriggerWrapper.tsx b/src/TriggerWrapper.tsx index f6c34610..66472b25 100644 --- a/src/TriggerWrapper.tsx +++ b/src/TriggerWrapper.tsx @@ -9,7 +9,7 @@ import type { TriggerProps } from '.'; export interface TriggerWrapperProps { getTriggerDOMNode?: TriggerProps['getTriggerDOMNode']; - children: React.ReactElement; + children: React.ReactElement; } const TriggerWrapper = React.forwardRef( @@ -20,18 +20,19 @@ const TriggerWrapper = React.forwardRef( // When use `getTriggerDOMNode`, we should do additional work to get the real dom const setRef = React.useCallback( - (node) => { + (node: React.ReactInstance) => { fillRef(ref, getTriggerDOMNode ? getTriggerDOMNode(node) : node); }, [getTriggerDOMNode], ); - const mergedRef = useComposeRef(setRef, getNodeRef(children)); + const mergedRef = useComposeRef( + setRef, + getNodeRef(children), + ); return canUseRef - ? React.cloneElement(children, { - ref: mergedRef, - }) + ? React.cloneElement(children, { ref: mergedRef }) : children; }, ); diff --git a/src/hooks/useAlign.ts b/src/hooks/useAlign.ts index f352a33d..f5e51941 100644 --- a/src/hooks/useAlign.ts +++ b/src/hooks/useAlign.ts @@ -131,7 +131,7 @@ export default function useAlign( scaleY: 1, align: builtinPlacements[placement] || {}, }); - const alignCountRef = React.useRef(0); + const alignCountRef = React.useRef(0); const scrollerList = React.useMemo(() => { if (!popupEle) { diff --git a/src/hooks/useWinClick.ts b/src/hooks/useWinClick.ts index e14bb482..cfafa5b9 100644 --- a/src/hooks/useWinClick.ts +++ b/src/hooks/useWinClick.ts @@ -13,10 +13,10 @@ export default function useWinClick( inPopupOrChild: (target: EventTarget) => boolean, triggerOpen: (open: boolean) => void, ) { - const openRef = React.useRef(open); + const openRef = React.useRef(open); openRef.current = open; - const popupPointerDownRef = React.useRef(false); + const popupPointerDownRef = React.useRef(false); // Click to hide is special action since click popup element should not hide React.useEffect(() => { diff --git a/src/index.tsx b/src/index.tsx index 2b5a696e..455ff408 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -46,7 +46,7 @@ export interface TriggerRef { // New version will not wrap popup with `rc-trigger-popup-content` when multiple children export interface TriggerProps { - children: React.ReactElement; + children: React.ReactElement; action?: ActionType | ActionType[]; showAction?: ActionType[]; hideAction?: ActionType[]; @@ -248,7 +248,7 @@ export function generateTrigger( }); // ========================== Children ========================== - const child = React.Children.only(children) as React.ReactElement; + const child = React.Children.only(children); const originChildProps = child?.props || {}; const cloneProps: typeof originChildProps = {}; @@ -311,7 +311,7 @@ export function generateTrigger( }); // Trigger for delay - const delayRef = React.useRef(); + const delayRef = React.useRef>(null); const clearDelay = () => { clearTimeout(delayRef.current); diff --git a/src/mock.tsx b/src/mock.tsx index d5d088ab..8a8c0a12 100644 --- a/src/mock.tsx +++ b/src/mock.tsx @@ -4,7 +4,7 @@ import { generateTrigger } from './index'; interface MockPortalProps { open?: boolean; autoDestroy?: boolean; - children: React.ReactElement; + children: React.ReactElement; getContainer?: () => HTMLElement; } diff --git a/tests/basic.test.jsx b/tests/basic.test.jsx index 8edea894..04d274b3 100644 --- a/tests/basic.test.jsx +++ b/tests/basic.test.jsx @@ -1,5 +1,4 @@ /* 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 React, { StrictMode, createRef } from 'react'; @@ -697,7 +696,7 @@ describe('Trigger.Basic', () => { let effectCalled = false; function Demo() { - const popupRef = React.useRef(); + const popupRef = React.useRef(null); React.useLayoutEffect(() => { effectCalled = true;