From 398893cbb80d3156f11de2fcafc74c46be14e59c Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 29 Jun 2026 18:18:33 +0800 Subject: [PATCH 01/19] chore: update maintenance dependencies --- .github/dependabot.yml | 8 +++ README.md | 2 +- README.zh-CN.md | 2 +- docs/examples/customPopupRender.tsx | 8 +-- eslint.config.mjs | 79 +++++++++++++++++++++++++++++ global.d.ts | 58 +++++++++++++++++++++ package.json | 29 +++++++---- react-compat.d.ts | 16 ++++++ src/Menu.tsx | 2 +- tsconfig.json | 11 +++- 10 files changed, 197 insertions(+), 18 deletions(-) create mode 100644 eslint.config.mjs create mode 100644 global.d.ts create mode 100644 react-compat.d.ts diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 3b730ef9..5e6c7faa 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,6 +8,10 @@ updates: time: '21:00' timezone: Asia/Shanghai open-pull-requests-limit: 10 + groups: + npm-dependencies: + patterns: + - '*' - package-ecosystem: github-actions directory: '/' @@ -17,3 +21,7 @@ updates: time: '21:00' timezone: Asia/Shanghai open-pull-requests-limit: 10 + groups: + github-actions: + patterns: + - '*' diff --git a/README.md b/README.md index ac8052cc..309fe8e6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

@rc-component/menu

-

Ant Design Part of the Ant Design ecosystem.

+

Ant Design Part of the Ant Design ecosystem.

🧭 Accessible React menu primitives for navigation, command surfaces, and nested item trees.

diff --git a/README.zh-CN.md b/README.zh-CN.md index cfb19eb7..5b100362 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -1,6 +1,6 @@

@rc-component/menu

-

Ant Design Ant Design η”Ÿζ€ηš„δΈ€ιƒ¨εˆ†γ€‚

+

Ant Design Ant Design η”Ÿζ€ηš„δΈ€ιƒ¨εˆ†γ€‚

🧭 React θœε•η»„δ»ΆοΌŒζ”―ζŒζ°΄εΉ³γ€εž‚η›΄γ€ε†…θ”γ€εˆ†η»„ε’Œε­θœε•γ€‚

diff --git a/docs/examples/customPopupRender.tsx b/docs/examples/customPopupRender.tsx index cf2d7138..4444255d 100644 --- a/docs/examples/customPopupRender.tsx +++ b/docs/examples/customPopupRender.tsx @@ -67,10 +67,10 @@ const NavigationDemo = () => { ], }, ]; - const popupRender = (node: ReactElement) => ( + const popupRender = (node: ReactElement) => (

- {React.Children.map(node.props.children.props.children, child => ( + {React.Children.map(node.props.children.props.children, (child: ReactElement) => (
{React.cloneElement(child, { className: `${child.props.className || ''} navigation-menu-item`, @@ -85,13 +85,13 @@ const NavigationDemo = () => { }; const MixedPanelDemo = () => { - const totalPopupRender = (node: ReactElement, info: { item: any; keys: string[] }) => { + const totalPopupRender = (node: ReactElement, info: { item: any; keys: string[] }) => { const isSecondLevel = info.keys.length == 2; if (isSecondLevel) { return (
- {React.Children.map(node.props.children.props.children, child => ( + {React.Children.map(node.props.children.props.children, (child: ReactElement) => (
{React.cloneElement(child, { className: `${child.props.className || ''} navigation-menu-item`, diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 00000000..b25fb5dd --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,79 @@ +import { FlatCompat } from '@eslint/eslintrc'; +import js from '@eslint/js'; +import tsEslintPlugin from '@typescript-eslint/eslint-plugin'; +import { createRequire } from 'node:module'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const require = createRequire(import.meta.url); + +const compat = new FlatCompat({ + baseDirectory: __dirname, + recommendedConfig: js.configs.recommended, + allConfig: js.configs.all, +}); + +const recommendedTsRules = new Set(Object.keys(tsEslintPlugin.configs.recommended.rules || {})); +const noopRule = { + meta: { type: 'problem', docs: {}, schema: [] }, + create: () => ({}), +}; + +function normalizeConfig(config) { + const next = { ...config }; + + if (next.plugins?.['@typescript-eslint']) { + next.plugins = { + ...next.plugins, + '@typescript-eslint': { + ...next.plugins['@typescript-eslint'], + rules: { + ...next.plugins['@typescript-eslint'].rules, + 'ban-types': noopRule, + }, + }, + }; + } + + if (next.rules) { + next.rules = Object.fromEntries( + Object.entries(next.rules).filter(([ruleName]) => { + if (!ruleName.startsWith('@typescript-eslint/')) { + return true; + } + return recommendedTsRules.has(ruleName) || ruleName === '@typescript-eslint/ban-types'; + }), + ); + } + + return next; +} + +export default [ + { + ignores: [ + 'node_modules/', + 'coverage/', + 'es/', + 'lib/', + 'dist/', + 'docs-dist/', + '.dumi/', + '.doc/', + '.vercel/', + '.eslintrc.js', + 'src/index.d.ts', + ], + }, + ...compat.config(require('./.eslintrc.js')).map(normalizeConfig), + { + rules: { + '@typescript-eslint/ban-types': 'off', + '@typescript-eslint/no-empty-object-type': 'off', + '@typescript-eslint/no-unsafe-function-type': 'off', + '@typescript-eslint/no-unused-vars': 'off', + }, + }, +]; diff --git a/global.d.ts b/global.d.ts new file mode 100644 index 00000000..e4a99d8a --- /dev/null +++ b/global.d.ts @@ -0,0 +1,58 @@ +/// +/// +/// +/// +/// + +declare module '*.css'; +declare module '*.less'; +declare module 'jsonp'; + +declare namespace JSX { + type Element = React.JSX.Element; + interface ElementClass extends React.JSX.ElementClass {} + interface ElementAttributesProperty extends React.JSX.ElementAttributesProperty {} + interface ElementChildrenAttribute extends React.JSX.ElementChildrenAttribute {} + type LibraryManagedAttributes = React.JSX.LibraryManagedAttributes; + interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {} + interface IntrinsicClassAttributes extends React.JSX.IntrinsicClassAttributes {} + interface IntrinsicElements extends React.JSX.IntrinsicElements {} +} + +declare namespace jest { + interface Matchers { + lastCalledWith(...expected: unknown[]): R; + nthCalledWith(nthCall: number, ...expected: unknown[]): R; + toBeCalled(): R; + toBeCalledTimes(expected: number): R; + toBeCalledWith(...expected: unknown[]): R; + } +} + +declare const vi: { + fn: any = (...args: any[]) => any>( + implementation?: T, + ) => jest.MockedFunction; + mock: (moduleName: string, factory?: (importOriginal: () => Promise) => unknown) => void; + spyOn: typeof jest.spyOn; + useFakeTimers: () => void; + useRealTimers: () => void; + advanceTimersByTime: (msToRun: number) => void; + clearAllTimers: () => void; + runAllTimers: () => void; + importActual: (moduleName: string) => Promise; + clearAllMocks: () => void; + resetAllMocks: () => void; + restoreAllMocks: () => void; +}; + +declare const describe: any; +declare const it: any; +declare const test: any; +declare const beforeEach: any; +declare const afterEach: any; +declare const beforeAll: any; +declare const afterAll: any; +declare const expect: any; + +declare module 'moment/locale/zh-cn'; diff --git a/package.json b/package.json index 3fe3f9d4..effb67e9 100644 --- a/package.json +++ b/package.json @@ -56,26 +56,37 @@ "@rc-component/father-plugin": "^2.2.0", "@rc-component/np": "^1.0.4", "@testing-library/jest-dom": "^6.9.1", - "@testing-library/react": "^15.0.7", - "@types/jest": "^29.5.14", + "@testing-library/react": "^16.3.2", + "@types/jest": "^30.0.0", "@types/node": "^26.0.1", - "@types/react": "^18.3.31", - "@types/react-dom": "^18.3.7", + "@types/react": "^19.2.17", + "@types/react-dom": "^19.2.3", "@types/warning": "^3.0.4", "@umijs/fabric": "^4.0.1", "cross-env": "^10.1.0", "dumi": "^2.4.35", - "eslint": "^8.57.1", + "eslint": "^9.39.4", "father": "^4.6.23", "gh-pages": "^6.3.0", "husky": "^9.1.7", "less": "^4.6.7", - "lint-staged": "^16.4.0", + "lint-staged": "^17.0.8", "prettier": "^3.9.0", "rc-test": "^7.1.3", - "react": "^18.3.1", - "react-dom": "^18.3.1", - "typescript": "^5.9.3" + "react": "^19.2.7", + "react-dom": "^19.2.7", + "typescript": "^6.0.3", + "@eslint/eslintrc": "^3.3.5", + "@eslint/js": "^9.39.4", + "eslint-plugin-react": "^7.37.5", + "eslint-plugin-react-hooks": "^7.1.1", + "eslint-config-prettier": "^10.1.8", + "@babel/eslint-parser": "^7.29.7", + "@babel/eslint-plugin": "^7.29.7", + "@typescript-eslint/eslint-plugin": "^8.62.0", + "@typescript-eslint/parser": "^8.62.0", + "eslint-plugin-jest": "^29.15.3", + "eslint-plugin-unicorn": "^65.0.1" }, "peerDependencies": { "react": ">=16.9.0", diff --git a/react-compat.d.ts b/react-compat.d.ts new file mode 100644 index 00000000..ff05aa1b --- /dev/null +++ b/react-compat.d.ts @@ -0,0 +1,16 @@ +import * as React from 'react'; + +declare module 'react' { + type ReactText = string | number; + function useRef(): React.MutableRefObject; + function isValidElement

(object: {} | null | undefined): object is React.ReactElement

; + function cloneElement

( + element: React.ReactElement

, + props?: (Partial

& React.Attributes) | null, + ...children: React.ReactNode[] + ): React.ReactElement

; +} + +declare module 'react-dom' { + function hydrate(element: React.ReactNode, container: Element | DocumentFragment): void; +} diff --git a/src/Menu.tsx b/src/Menu.tsx index 8c701ba4..9597ce56 100644 --- a/src/Menu.tsx +++ b/src/Menu.tsx @@ -400,7 +400,7 @@ const Menu = React.forwardRef((props, ref) => { } else { shouldFocusKey = focusableElements[0] ? element2key.get(focusableElements[0]) - : childList.find(node => !node.props.disabled)?.key; + : childList.find((node: React.ReactElement) => !node.props.disabled)?.key; } const elementToFocus = key2element.get(shouldFocusKey); diff --git a/tsconfig.json b/tsconfig.json index 0f80b4f2..85411d0b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,8 +12,15 @@ "@@/*": [".dumi/tmp/*"], "@rc-component/menu": ["src/index.ts"] }, - "ignoreDeprecations": "5.0" + "ignoreDeprecations": "6.0", + "noImplicitAny": false, + "strictNullChecks": false, + "strictPropertyInitialization": false, + "strictFunctionTypes": false, + "strict": false, + "noImplicitThis": false, + "strictBindCallApply": false }, - "include": ["src", "docs", ".dumirc.ts", ".fatherrc.ts"], + "include": ["react-compat.d.ts", "global.d.ts", "src", "docs", ".dumirc.ts", ".fatherrc.ts"], "exclude": ["node_modules", "lib", "es", "dist", "docs-dist", ".dumi"] } From b4921cd6c640109463547f42f8624ab64133f641 Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Jun 2026 10:20:12 +0800 Subject: [PATCH 02/19] fix: align TypeScript and ESLint compatibility --- eslint.config.mjs | 24 ++++++++++++++---------- global.d.ts | 9 --------- tsconfig.json | 13 ++++++------- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index b25fb5dd..d85381ec 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -25,16 +25,8 @@ function normalizeConfig(config) { const next = { ...config }; if (next.plugins?.['@typescript-eslint']) { - next.plugins = { - ...next.plugins, - '@typescript-eslint': { - ...next.plugins['@typescript-eslint'], - rules: { - ...next.plugins['@typescript-eslint'].rules, - 'ban-types': noopRule, - }, - }, - }; + next.plugins = { ...next.plugins }; + delete next.plugins['@typescript-eslint']; } if (next.rules) { @@ -67,6 +59,18 @@ export default [ 'src/index.d.ts', ], }, + { + plugins: { + '@typescript-eslint': { + ...tsEslintPlugin, + rules: { + ...tsEslintPlugin.rules, + 'ban-types': noopRule, + 'consistent-type-exports': noopRule, + }, + }, + }, + }, ...compat.config(require('./.eslintrc.js')).map(normalizeConfig), { rules: { diff --git a/global.d.ts b/global.d.ts index e4a99d8a..85e4e4e7 100644 --- a/global.d.ts +++ b/global.d.ts @@ -46,13 +46,4 @@ declare const vi: { restoreAllMocks: () => void; }; -declare const describe: any; -declare const it: any; -declare const test: any; -declare const beforeEach: any; -declare const afterEach: any; -declare const beforeAll: any; -declare const afterAll: any; -declare const expect: any; - declare module 'moment/locale/zh-cn'; diff --git a/tsconfig.json b/tsconfig.json index 85411d0b..4f500c7b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,25 +1,24 @@ { "compilerOptions": { "target": "esnext", - "moduleResolution": "node", - "baseUrl": "./", + "moduleResolution": "bundler", "jsx": "react", "declaration": true, "skipLibCheck": true, "esModuleInterop": true, "paths": { - "@/*": ["src/*"], - "@@/*": [".dumi/tmp/*"], - "@rc-component/menu": ["src/index.ts"] + "@/*": ["./src/*"], + "@@/*": ["./.dumi/tmp/*"], + "@rc-component/menu": ["./src/index.ts"] }, - "ignoreDeprecations": "6.0", "noImplicitAny": false, "strictNullChecks": false, "strictPropertyInitialization": false, "strictFunctionTypes": false, "strict": false, "noImplicitThis": false, - "strictBindCallApply": false + "strictBindCallApply": false, + "module": "ESNext" }, "include": ["react-compat.d.ts", "global.d.ts", "src", "docs", ".dumirc.ts", ".fatherrc.ts"], "exclude": ["node_modules", "lib", "es", "dist", "docs-dist", ".dumi"] From a4a3814dfc5e7da290a3a636feefa18d5b618df3 Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Jun 2026 10:50:17 +0800 Subject: [PATCH 03/19] chore: use testing-library dom events --- package.json | 25 ++++++------ tests/Collapsed.spec.tsx | 83 ++++++++++----------------------------- tests/Focus.spec.tsx | 3 +- tests/Keyboard.spec.tsx | 3 +- tests/Menu.spec.tsx | 3 +- tests/MenuItem.spec.tsx | 3 +- tests/Responsive.spec.tsx | 3 +- tests/SubMenu.spec.tsx | 3 +- tests/semantic.spec.tsx | 3 +- 9 files changed, 48 insertions(+), 81 deletions(-) diff --git a/package.json b/package.json index effb67e9..5242324a 100644 --- a/package.json +++ b/package.json @@ -53,8 +53,13 @@ "clsx": "^2.1.1" }, "devDependencies": { + "@babel/eslint-parser": "^7.29.7", + "@babel/eslint-plugin": "^7.29.7", + "@eslint/eslintrc": "^3.3.5", + "@eslint/js": "^9.39.4", "@rc-component/father-plugin": "^2.2.0", "@rc-component/np": "^1.0.4", + "@testing-library/dom": "^10.4.1", "@testing-library/jest-dom": "^6.9.1", "@testing-library/react": "^16.3.2", "@types/jest": "^30.0.0", @@ -62,10 +67,17 @@ "@types/react": "^19.2.17", "@types/react-dom": "^19.2.3", "@types/warning": "^3.0.4", + "@typescript-eslint/eslint-plugin": "^8.62.0", + "@typescript-eslint/parser": "^8.62.0", "@umijs/fabric": "^4.0.1", "cross-env": "^10.1.0", "dumi": "^2.4.35", "eslint": "^9.39.4", + "eslint-config-prettier": "^10.1.8", + "eslint-plugin-jest": "^29.15.3", + "eslint-plugin-react": "^7.37.5", + "eslint-plugin-react-hooks": "^7.1.1", + "eslint-plugin-unicorn": "^65.0.1", "father": "^4.6.23", "gh-pages": "^6.3.0", "husky": "^9.1.7", @@ -75,18 +87,7 @@ "rc-test": "^7.1.3", "react": "^19.2.7", "react-dom": "^19.2.7", - "typescript": "^6.0.3", - "@eslint/eslintrc": "^3.3.5", - "@eslint/js": "^9.39.4", - "eslint-plugin-react": "^7.37.5", - "eslint-plugin-react-hooks": "^7.1.1", - "eslint-config-prettier": "^10.1.8", - "@babel/eslint-parser": "^7.29.7", - "@babel/eslint-plugin": "^7.29.7", - "@typescript-eslint/eslint-plugin": "^8.62.0", - "@typescript-eslint/parser": "^8.62.0", - "eslint-plugin-jest": "^29.15.3", - "eslint-plugin-unicorn": "^65.0.1" + "typescript": "^6.0.3" }, "peerDependencies": { "react": ">=16.9.0", diff --git a/tests/Collapsed.spec.tsx b/tests/Collapsed.spec.tsx index ee6f1c7d..16f9ffcd 100644 --- a/tests/Collapsed.spec.tsx +++ b/tests/Collapsed.spec.tsx @@ -1,5 +1,6 @@ +import { fireEvent } from '@testing-library/dom'; /* eslint-disable no-undef, react/no-multi-comp, react/jsx-curly-brace-presence */ -import { act, fireEvent, render } from '@testing-library/react'; +import { act, render } from '@testing-library/react'; import React from 'react'; import Menu, { MenuItem, SubMenu } from '../src'; @@ -27,24 +28,18 @@ describe('Menu.Collapsed', () => { const { container, rerender } = render(genMenu()); // Inline - expect(container.querySelector('ul.rc-menu-sub')).not.toHaveClass( - 'rc-menu-hidden', - ); + expect(container.querySelector('ul.rc-menu-sub')).not.toHaveClass('rc-menu-hidden'); // Vertical rerender(genMenu({ mode: 'vertical' })); act(() => { jest.runAllTimers(); }); - expect(container.querySelector('ul.rc-menu-sub')).not.toHaveClass( - 'rc-menu-hidden', - ); + expect(container.querySelector('ul.rc-menu-sub')).not.toHaveClass('rc-menu-hidden'); // Inline rerender(genMenu({ mode: 'inline' })); - expect(container.querySelector('ul.rc-menu-sub')).not.toHaveClass( - 'rc-menu-hidden', - ); + expect(container.querySelector('ul.rc-menu-sub')).not.toHaveClass('rc-menu-hidden'); }); it('should always follow submenu popup hidden when mode is switched', () => { @@ -61,9 +56,7 @@ describe('Menu.Collapsed', () => { const { container, rerender } = render(genMenu()); // Hover submenu1 - fireEvent.mouseEnter( - container.querySelectorAll('.rc-menu-submenu-title')[0], - ); + fireEvent.mouseEnter(container.querySelectorAll('.rc-menu-submenu-title')[0]); act(() => { jest.runAllTimers(); @@ -73,9 +66,7 @@ describe('Menu.Collapsed', () => { }); // Hover submenu1-1 - fireEvent.mouseEnter( - container.querySelectorAll('.rc-menu-submenu-title')[1], - ); + fireEvent.mouseEnter(container.querySelectorAll('.rc-menu-submenu-title')[1]); act(() => { jest.runAllTimers(); @@ -114,12 +105,8 @@ describe('Menu.Collapsed', () => { ); const { container, rerender } = render(genMenu()); - expect(container.querySelector('ul.rc-menu-sub')).toHaveClass( - 'rc-menu-inline', - ); - expect(container.querySelector('ul.rc-menu-sub')).not.toHaveClass( - 'rc-menu-hidden', - ); + expect(container.querySelector('ul.rc-menu-sub')).toHaveClass('rc-menu-inline'); + expect(container.querySelector('ul.rc-menu-sub')).not.toHaveClass('rc-menu-hidden'); rerender(genMenu({ inlineCollapsed: true })); // εŠ¨η”»η»“ζŸεŽε₯—样式; @@ -135,9 +122,7 @@ describe('Menu.Collapsed', () => { jest.runAllTimers(); }); - expect(container.querySelector('ul.rc-menu-root')).toHaveClass( - 'rc-menu-vertical', - ); + expect(container.querySelector('ul.rc-menu-root')).toHaveClass('rc-menu-vertical'); expect(container.querySelectorAll('ul.rc-menu-sub')).toHaveLength(0); rerender(genMenu({ inlineCollapsed: false })); @@ -145,12 +130,8 @@ describe('Menu.Collapsed', () => { jest.runAllTimers(); }); - expect(container.querySelector('ul.rc-menu-sub')).toHaveClass( - 'rc-menu-inline', - ); - expect(container.querySelector('ul.rc-menu-sub')).not.toHaveClass( - 'rc-menu-hidden', - ); + expect(container.querySelector('ul.rc-menu-sub')).toHaveClass('rc-menu-inline'); + expect(container.querySelector('ul.rc-menu-sub')).not.toHaveClass('rc-menu-hidden'); }); it('inlineCollapsed should works well when specify a not existed default openKeys', () => { @@ -199,20 +180,12 @@ describe('Menu.Collapsed', () => { jest.runAllTimers(); }); - expect(container.querySelector('.rc-menu-submenu')).toHaveClass( - 'rc-menu-submenu-vertical', - ); + expect(container.querySelector('.rc-menu-submenu')).toHaveClass('rc-menu-submenu-vertical'); - expect(container.querySelector('.rc-menu-submenu')).toHaveClass( - 'rc-menu-submenu-open', - ); + expect(container.querySelector('.rc-menu-submenu')).toHaveClass('rc-menu-submenu-open'); - expect(container.querySelector('ul.rc-menu-sub')).toHaveClass( - 'rc-menu-vertical', - ); - expect(container.querySelector('ul.rc-menu-sub')).not.toHaveClass( - 'rc-menu-hidden', - ); + expect(container.querySelector('ul.rc-menu-sub')).toHaveClass('rc-menu-vertical'); + expect(container.querySelector('ul.rc-menu-sub')).not.toHaveClass('rc-menu-hidden'); }); it('inlineCollapsed MenuItem Tooltip can be removed', () => { @@ -271,15 +244,11 @@ describe('Menu.Collapsed', () => { const { container, rerender } = render(genMenu()); // Default - expect( - container.querySelector('.rc-menu-item-selected').textContent, - ).toBe('Option 1'); + expect(container.querySelector('.rc-menu-item-selected').textContent).toBe('Option 1'); // Click to change select fireEvent.click(container.querySelectorAll('.rc-menu-item')[1]); - expect( - container.querySelector('.rc-menu-item-selected').textContent, - ).toBe('Option 2'); + expect(container.querySelector('.rc-menu-item-selected').textContent).toBe('Option 2'); // Collapse it rerender(genMenu({ inlineCollapsed: true })); @@ -292,20 +261,12 @@ describe('Menu.Collapsed', () => { // Expand it rerender(genMenu({ inlineCollapsed: false })); - expect( - container.querySelector('.rc-menu-item-selected').textContent, - ).toBe('Option 2'); + expect(container.querySelector('.rc-menu-item-selected').textContent).toBe('Option 2'); }); it('should hideMenu in initial state when collapsed', () => { const genMenu = (props?) => ( -

+ Option 1 Option 2 @@ -327,9 +288,7 @@ describe('Menu.Collapsed', () => { jest.runAllTimers(); }); - expect( - container.querySelector('.rc-menu-item-selected').textContent, - ).toBe('Option 1'); + expect(container.querySelector('.rc-menu-item-selected').textContent).toBe('Option 1'); }); it('vertical also support inlineCollapsed', () => { diff --git a/tests/Focus.spec.tsx b/tests/Focus.spec.tsx index 3d90507f..2df95c44 100644 --- a/tests/Focus.spec.tsx +++ b/tests/Focus.spec.tsx @@ -1,5 +1,6 @@ +import { fireEvent } from '@testing-library/dom'; /* eslint-disable no-undef */ -import { act, fireEvent, render } from '@testing-library/react'; +import { act, render } from '@testing-library/react'; import { spyElementPrototypes } from '@rc-component/util'; import React from 'react'; import Menu, { MenuItem, MenuItemGroup, MenuRef, SubMenu } from '../src'; diff --git a/tests/Keyboard.spec.tsx b/tests/Keyboard.spec.tsx index e1b89ef4..9feccf72 100644 --- a/tests/Keyboard.spec.tsx +++ b/tests/Keyboard.spec.tsx @@ -1,5 +1,6 @@ +import { fireEvent } from '@testing-library/dom'; /* eslint-disable no-undef, react/no-multi-comp, react/jsx-curly-brace-presence, max-classes-per-file */ -import { fireEvent, render } from '@testing-library/react'; +import { render } from '@testing-library/react'; import { KeyCode, spyElementPrototypes } from '@rc-component/util'; import React from 'react'; import { act } from 'react-dom/test-utils'; diff --git a/tests/Menu.spec.tsx b/tests/Menu.spec.tsx index 3f629082..ee51293a 100644 --- a/tests/Menu.spec.tsx +++ b/tests/Menu.spec.tsx @@ -1,6 +1,7 @@ +import { fireEvent } from '@testing-library/dom'; /* eslint-disable no-undef, react/no-multi-comp, react/jsx-curly-brace-presence, max-classes-per-file */ import type { MenuMode } from '@/interface'; -import { fireEvent, render } from '@testing-library/react'; +import { render } from '@testing-library/react'; import { KeyCode, resetWarned, spyElementPrototypes } from '@rc-component/util'; import React from 'react'; import { act } from 'react-dom/test-utils'; diff --git a/tests/MenuItem.spec.tsx b/tests/MenuItem.spec.tsx index 87966ef1..b1187f65 100644 --- a/tests/MenuItem.spec.tsx +++ b/tests/MenuItem.spec.tsx @@ -1,5 +1,6 @@ +import { fireEvent } from '@testing-library/dom'; /* eslint-disable no-undef */ -import { fireEvent, render } from '@testing-library/react'; +import { render } from '@testing-library/react'; import { KeyCode } from '@rc-component/util'; import React from 'react'; import Menu, { MenuItem, MenuItemGroup, SubMenu } from '../src'; diff --git a/tests/Responsive.spec.tsx b/tests/Responsive.spec.tsx index 96f2f9a7..f71efe1c 100644 --- a/tests/Responsive.spec.tsx +++ b/tests/Responsive.spec.tsx @@ -1,5 +1,6 @@ +import { fireEvent } from '@testing-library/dom'; /* eslint-disable no-undef, react/no-multi-comp, react/jsx-curly-brace-presence, max-classes-per-file */ -import { act, fireEvent, render } from '@testing-library/react'; +import { act, render } from '@testing-library/react'; import ResizeObserver from '@rc-component/resize-observer'; import { KeyCode, spyElementPrototype } from '@rc-component/util'; import React from 'react'; diff --git a/tests/SubMenu.spec.tsx b/tests/SubMenu.spec.tsx index 8f75f620..17246405 100644 --- a/tests/SubMenu.spec.tsx +++ b/tests/SubMenu.spec.tsx @@ -1,5 +1,6 @@ +import { fireEvent } from '@testing-library/dom'; /* eslint-disable no-undef */ -import { act, fireEvent, render } from '@testing-library/react'; +import { act, render } from '@testing-library/react'; import { resetWarned } from '@rc-component/util'; import React from 'react'; import Menu, { MenuItem, SubMenu } from '../src'; diff --git a/tests/semantic.spec.tsx b/tests/semantic.spec.tsx index 360c4639..afec19ad 100644 --- a/tests/semantic.spec.tsx +++ b/tests/semantic.spec.tsx @@ -1,5 +1,6 @@ +import { fireEvent } from '@testing-library/dom'; /* eslint-disable no-undef */ -import { act, fireEvent, render } from '@testing-library/react'; +import { act, render } from '@testing-library/react'; import React from 'react'; import Menu, { MenuItem, MenuItemGroup, SubMenu } from '../src'; describe('semantic', () => { From 500bbc843baf468d8ee0255b1512c363baa76a72 Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Jun 2026 11:15:31 +0800 Subject: [PATCH 04/19] test: keep react testing event behavior --- tests/Collapsed.spec.tsx | 3 +-- tests/Focus.spec.tsx | 3 +-- tests/Keyboard.spec.tsx | 3 +-- tests/Menu.spec.tsx | 3 +-- tests/MenuItem.spec.tsx | 3 +-- tests/Responsive.spec.tsx | 3 +-- tests/SubMenu.spec.tsx | 3 +-- tests/semantic.spec.tsx | 3 +-- 8 files changed, 8 insertions(+), 16 deletions(-) diff --git a/tests/Collapsed.spec.tsx b/tests/Collapsed.spec.tsx index 16f9ffcd..a74729c3 100644 --- a/tests/Collapsed.spec.tsx +++ b/tests/Collapsed.spec.tsx @@ -1,6 +1,5 @@ -import { fireEvent } from '@testing-library/dom'; /* eslint-disable no-undef, react/no-multi-comp, react/jsx-curly-brace-presence */ -import { act, render } from '@testing-library/react'; +import { act, fireEvent, render } from '@testing-library/react'; import React from 'react'; import Menu, { MenuItem, SubMenu } from '../src'; diff --git a/tests/Focus.spec.tsx b/tests/Focus.spec.tsx index 2df95c44..3d90507f 100644 --- a/tests/Focus.spec.tsx +++ b/tests/Focus.spec.tsx @@ -1,6 +1,5 @@ -import { fireEvent } from '@testing-library/dom'; /* eslint-disable no-undef */ -import { act, render } from '@testing-library/react'; +import { act, fireEvent, render } from '@testing-library/react'; import { spyElementPrototypes } from '@rc-component/util'; import React from 'react'; import Menu, { MenuItem, MenuItemGroup, MenuRef, SubMenu } from '../src'; diff --git a/tests/Keyboard.spec.tsx b/tests/Keyboard.spec.tsx index 9feccf72..e1b89ef4 100644 --- a/tests/Keyboard.spec.tsx +++ b/tests/Keyboard.spec.tsx @@ -1,6 +1,5 @@ -import { fireEvent } from '@testing-library/dom'; /* eslint-disable no-undef, react/no-multi-comp, react/jsx-curly-brace-presence, max-classes-per-file */ -import { render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; import { KeyCode, spyElementPrototypes } from '@rc-component/util'; import React from 'react'; import { act } from 'react-dom/test-utils'; diff --git a/tests/Menu.spec.tsx b/tests/Menu.spec.tsx index ee51293a..3f629082 100644 --- a/tests/Menu.spec.tsx +++ b/tests/Menu.spec.tsx @@ -1,7 +1,6 @@ -import { fireEvent } from '@testing-library/dom'; /* eslint-disable no-undef, react/no-multi-comp, react/jsx-curly-brace-presence, max-classes-per-file */ import type { MenuMode } from '@/interface'; -import { render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; import { KeyCode, resetWarned, spyElementPrototypes } from '@rc-component/util'; import React from 'react'; import { act } from 'react-dom/test-utils'; diff --git a/tests/MenuItem.spec.tsx b/tests/MenuItem.spec.tsx index b1187f65..87966ef1 100644 --- a/tests/MenuItem.spec.tsx +++ b/tests/MenuItem.spec.tsx @@ -1,6 +1,5 @@ -import { fireEvent } from '@testing-library/dom'; /* eslint-disable no-undef */ -import { render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; import { KeyCode } from '@rc-component/util'; import React from 'react'; import Menu, { MenuItem, MenuItemGroup, SubMenu } from '../src'; diff --git a/tests/Responsive.spec.tsx b/tests/Responsive.spec.tsx index f71efe1c..96f2f9a7 100644 --- a/tests/Responsive.spec.tsx +++ b/tests/Responsive.spec.tsx @@ -1,6 +1,5 @@ -import { fireEvent } from '@testing-library/dom'; /* eslint-disable no-undef, react/no-multi-comp, react/jsx-curly-brace-presence, max-classes-per-file */ -import { act, render } from '@testing-library/react'; +import { act, fireEvent, render } from '@testing-library/react'; import ResizeObserver from '@rc-component/resize-observer'; import { KeyCode, spyElementPrototype } from '@rc-component/util'; import React from 'react'; diff --git a/tests/SubMenu.spec.tsx b/tests/SubMenu.spec.tsx index 17246405..8f75f620 100644 --- a/tests/SubMenu.spec.tsx +++ b/tests/SubMenu.spec.tsx @@ -1,6 +1,5 @@ -import { fireEvent } from '@testing-library/dom'; /* eslint-disable no-undef */ -import { act, render } from '@testing-library/react'; +import { act, fireEvent, render } from '@testing-library/react'; import { resetWarned } from '@rc-component/util'; import React from 'react'; import Menu, { MenuItem, SubMenu } from '../src'; diff --git a/tests/semantic.spec.tsx b/tests/semantic.spec.tsx index afec19ad..360c4639 100644 --- a/tests/semantic.spec.tsx +++ b/tests/semantic.spec.tsx @@ -1,6 +1,5 @@ -import { fireEvent } from '@testing-library/dom'; /* eslint-disable no-undef */ -import { act, render } from '@testing-library/react'; +import { act, fireEvent, render } from '@testing-library/react'; import React from 'react'; import Menu, { MenuItem, MenuItemGroup, SubMenu } from '../src'; describe('semantic', () => { From 69b4e5c269848fc7be1089fe605f7facfd0ddfdc Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Jun 2026 19:03:18 +0800 Subject: [PATCH 05/19] chore: address review comments --- eslint.config.mjs | 22 +++++++--------------- react-compat.d.ts | 4 ---- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index d85381ec..e8504e27 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -15,11 +15,11 @@ const compat = new FlatCompat({ allConfig: js.configs.all, }); -const recommendedTsRules = new Set(Object.keys(tsEslintPlugin.configs.recommended.rules || {})); -const noopRule = { - meta: { type: 'problem', docs: {}, schema: [] }, - create: () => ({}), -}; +const recommendedTsRulesConfig = tsEslintPlugin.configs.recommended; +const recommendedTsRulesObject = Array.isArray(recommendedTsRulesConfig) + ? recommendedTsRulesConfig.reduce((rules, config) => ({ ...rules, ...(config.rules || {}) }), {}) + : recommendedTsRulesConfig?.rules || {}; +const recommendedTsRules = new Set(Object.keys(recommendedTsRulesObject)); function normalizeConfig(config) { const next = { ...config }; @@ -35,7 +35,7 @@ function normalizeConfig(config) { if (!ruleName.startsWith('@typescript-eslint/')) { return true; } - return recommendedTsRules.has(ruleName) || ruleName === '@typescript-eslint/ban-types'; + return recommendedTsRules.has(ruleName); }), ); } @@ -61,20 +61,12 @@ export default [ }, { plugins: { - '@typescript-eslint': { - ...tsEslintPlugin, - rules: { - ...tsEslintPlugin.rules, - 'ban-types': noopRule, - 'consistent-type-exports': noopRule, - }, - }, + '@typescript-eslint': tsEslintPlugin, }, }, ...compat.config(require('./.eslintrc.js')).map(normalizeConfig), { rules: { - '@typescript-eslint/ban-types': 'off', '@typescript-eslint/no-empty-object-type': 'off', '@typescript-eslint/no-unsafe-function-type': 'off', '@typescript-eslint/no-unused-vars': 'off', diff --git a/react-compat.d.ts b/react-compat.d.ts index ff05aa1b..c509fe40 100644 --- a/react-compat.d.ts +++ b/react-compat.d.ts @@ -10,7 +10,3 @@ declare module 'react' { ...children: React.ReactNode[] ): React.ReactElement

; } - -declare module 'react-dom' { - function hydrate(element: React.ReactNode, container: Element | DocumentFragment): void; -} From cb92685e77674f0059ba89ca39e04beb94b5e702 Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Jun 2026 19:16:06 +0800 Subject: [PATCH 06/19] fix: keep compatible eslint export rule --- eslint.config.mjs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index e8504e27..7f8ca4ce 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -20,6 +20,10 @@ const recommendedTsRulesObject = Array.isArray(recommendedTsRulesConfig) ? recommendedTsRulesConfig.reduce((rules, config) => ({ ...rules, ...(config.rules || {}) }), {}) : recommendedTsRulesConfig?.rules || {}; const recommendedTsRules = new Set(Object.keys(recommendedTsRulesObject)); +const noopRule = { + meta: { type: 'problem', docs: {}, schema: [] }, + create: () => ({}), +}; function normalizeConfig(config) { const next = { ...config }; @@ -61,7 +65,13 @@ export default [ }, { plugins: { - '@typescript-eslint': tsEslintPlugin, + '@typescript-eslint': { + ...tsEslintPlugin, + rules: { + ...tsEslintPlugin.rules, + 'consistent-type-exports': noopRule, + }, + }, }, }, ...compat.config(require('./.eslintrc.js')).map(normalizeConfig), From 7a43be27d48ee5a22a2648506db4633bf477629d Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 12:53:13 +0800 Subject: [PATCH 07/19] chore: preserve local eslint rule overrides --- eslint.config.mjs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 7f8ca4ce..42e86dba 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -15,11 +15,23 @@ const compat = new FlatCompat({ allConfig: js.configs.all, }); +const legacyConfig = require('./.eslintrc.js'); const recommendedTsRulesConfig = tsEslintPlugin.configs.recommended; const recommendedTsRulesObject = Array.isArray(recommendedTsRulesConfig) ? recommendedTsRulesConfig.reduce((rules, config) => ({ ...rules, ...(config.rules || {}) }), {}) : recommendedTsRulesConfig?.rules || {}; const recommendedTsRules = new Set(Object.keys(recommendedTsRulesObject)); + +function hasCurrentTsRule(ruleName) { + const tsRuleName = ruleName.replace('@typescript-eslint/', ''); + return Boolean(tsEslintPlugin.rules[tsRuleName]); +} +const localTsRules = new Set( + Object.keys(legacyConfig.rules || {}).filter( + ruleName => ruleName.startsWith('@typescript-eslint/') && hasCurrentTsRule(ruleName), + ), +); + const noopRule = { meta: { type: 'problem', docs: {}, schema: [] }, create: () => ({}), @@ -39,7 +51,7 @@ function normalizeConfig(config) { if (!ruleName.startsWith('@typescript-eslint/')) { return true; } - return recommendedTsRules.has(ruleName); + return recommendedTsRules.has(ruleName) || localTsRules.has(ruleName); }), ); } @@ -74,7 +86,7 @@ export default [ }, }, }, - ...compat.config(require('./.eslintrc.js')).map(normalizeConfig), + ...compat.config(legacyConfig).map(normalizeConfig), { rules: { '@typescript-eslint/no-empty-object-type': 'off', From 32b1bd989f3e15292454e4a1b6b50f540ef44693 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 13:22:14 +0800 Subject: [PATCH 08/19] docs: use ut install for local setup --- README.md | 4 ++-- README.zh-CN.md | 4 ++-- vercel.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 309fe8e6..b3f07cce 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ export default () => ( Run the local dumi site: ```bash -npm install +ut install npm start ``` @@ -161,7 +161,7 @@ type ItemType = ## Development ```bash -npm install +ut install npm start npm test npm run tsc diff --git a/README.zh-CN.md b/README.zh-CN.md index 5b100362..e94acff8 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -70,7 +70,7 @@ export default () => ( 运葌本地 dumi η«™η‚ΉοΌš ```bash -npm install +ut install npm start ``` @@ -161,7 +161,7 @@ type ItemType = ## ζœ¬εœ°εΌ€ε‘ ```bash -npm install +ut install npm start npm test npm run tsc diff --git a/vercel.json b/vercel.json index 5f9139ef..20b1714f 100644 --- a/vercel.json +++ b/vercel.json @@ -1,6 +1,6 @@ { "framework": "umijs", - "installCommand": "npm install", + "installCommand": "ut install", "buildCommand": "npm run build", "outputDirectory": "docs-dist" } From 54368a635619bafda40b9cb48441fb6e8ea7d717 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 13:29:42 +0800 Subject: [PATCH 09/19] chore: restore vercel install command --- vercel.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vercel.json b/vercel.json index 20b1714f..5f9139ef 100644 --- a/vercel.json +++ b/vercel.json @@ -1,6 +1,6 @@ { "framework": "umijs", - "installCommand": "ut install", + "installCommand": "npm install", "buildCommand": "npm run build", "outputDirectory": "docs-dist" } From c9dbe4f2ee655e165e8677911b98fc4ecaffe40f Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 14:02:10 +0800 Subject: [PATCH 10/19] chore: align maintenance dependencies --- docs/examples/debug.tsx | 2 +- docs/examples/items-ref.tsx | 14 +++++++------- eslint.config.mjs | 3 +++ package.json | 16 ++++++++-------- react-compat.d.ts | 12 ------------ src/Menu.tsx | 2 +- src/MenuItem.tsx | 4 ++-- src/SubMenu/PopupTrigger.tsx | 2 +- src/SubMenu/index.tsx | 4 ++-- src/hooks/useAccessibility.ts | 4 ++-- tsconfig.json | 2 +- 11 files changed, 28 insertions(+), 37 deletions(-) delete mode 100644 react-compat.d.ts diff --git a/docs/examples/debug.tsx b/docs/examples/debug.tsx index 0fca53ab..f1f9d2ab 100644 --- a/docs/examples/debug.tsx +++ b/docs/examples/debug.tsx @@ -52,7 +52,7 @@ export default () => { const [inlineCollapsed, setInlineCollapsed] = React.useState(false); const [forceRender, setForceRender] = React.useState(false); const [openKeys, setOpenKeys] = React.useState([]); - const menuRef = useRef(); + const menuRef = useRef(null); const onRootClick = (info: MenuInfo) => { console.log('Root Menu Item Click:', info); diff --git a/docs/examples/items-ref.tsx b/docs/examples/items-ref.tsx index dc18f9f1..b8736e92 100644 --- a/docs/examples/items-ref.tsx +++ b/docs/examples/items-ref.tsx @@ -5,13 +5,13 @@ import '../../assets/index.less'; import Menu from '../../src'; export default () => { - const ref1 = useRef(); - const ref2 = useRef(); - const ref3 = useRef(); - const ref4 = useRef(); - const ref5 = useRef(); - const ref6 = useRef(); - const ref7 = useRef(); + const ref1 = useRef(null); + const ref2 = useRef(null); + const ref3 = useRef(null); + const ref4 = useRef(null); + const ref5 = useRef(null); + const ref6 = useRef(null); + const ref7 = useRef(null); return ( <> diff --git a/eslint.config.mjs b/eslint.config.mjs index 42e86dba..8eabc428 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -48,6 +48,9 @@ function normalizeConfig(config) { if (next.rules) { next.rules = Object.fromEntries( Object.entries(next.rules).filter(([ruleName]) => { + if (ruleName.startsWith('@babel/')) { + return false; + } if (!ruleName.startsWith('@typescript-eslint/')) { return true; } diff --git a/package.json b/package.json index 5242324a..5d5444eb 100644 --- a/package.json +++ b/package.json @@ -67,31 +67,31 @@ "@types/react": "^19.2.17", "@types/react-dom": "^19.2.3", "@types/warning": "^3.0.4", - "@typescript-eslint/eslint-plugin": "^8.62.0", - "@typescript-eslint/parser": "^8.62.0", + "@typescript-eslint/eslint-plugin": "^8.62.1", + "@typescript-eslint/parser": "^8.62.1", "@umijs/fabric": "^4.0.1", "cross-env": "^10.1.0", - "dumi": "^2.4.35", + "dumi": "^2.4.38", "eslint": "^9.39.4", "eslint-config-prettier": "^10.1.8", - "eslint-plugin-jest": "^29.15.3", + "eslint-plugin-jest": "^29.15.4", "eslint-plugin-react": "^7.37.5", "eslint-plugin-react-hooks": "^7.1.1", "eslint-plugin-unicorn": "^65.0.1", - "father": "^4.6.23", + "father": "^4.6.24", "gh-pages": "^6.3.0", "husky": "^9.1.7", "less": "^4.6.7", "lint-staged": "^17.0.8", - "prettier": "^3.9.0", + "prettier": "^3.9.4", "rc-test": "^7.1.3", "react": "^19.2.7", "react-dom": "^19.2.7", "typescript": "^6.0.3" }, "peerDependencies": { - "react": ">=16.9.0", - "react-dom": ">=16.9.0" + "react": "^19.2.7", + "react-dom": "^19.2.7" }, "lint-staged": { "*": "prettier --write --ignore-unknown" diff --git a/react-compat.d.ts b/react-compat.d.ts deleted file mode 100644 index c509fe40..00000000 --- a/react-compat.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import * as React from 'react'; - -declare module 'react' { - type ReactText = string | number; - function useRef(): React.MutableRefObject; - function isValidElement

(object: {} | null | undefined): object is React.ReactElement

; - function cloneElement

( - element: React.ReactElement

, - props?: (Partial

& React.Attributes) | null, - ...children: React.ReactNode[] - ): React.ReactElement

; -} diff --git a/src/Menu.tsx b/src/Menu.tsx index 9597ce56..65a67ca3 100644 --- a/src/Menu.tsx +++ b/src/Menu.tsx @@ -257,7 +257,7 @@ const Menu = React.forwardRef((props, ref) => { const [mounted, setMounted] = React.useState(false); - const containerRef = React.useRef(); + const containerRef = React.useRef(null); const uuid = useId(id ? `rc-menu-uuid-${id}` : 'rc-menu-uuid'); diff --git a/src/MenuItem.tsx b/src/MenuItem.tsx index 74882518..cda3d0c4 100644 --- a/src/MenuItem.tsx +++ b/src/MenuItem.tsx @@ -117,8 +117,8 @@ const InternalMenuItem = React.forwardRef((props: MenuItemProps, ref: React.Ref< const itemCls = `${prefixCls}-item`; - const legacyMenuItemRef = React.useRef(); - const elementRef = React.useRef(); + const legacyMenuItemRef = React.useRef(null); + const elementRef = React.useRef(null); const mergedDisabled = contextDisabled || disabled; const mergedEleRef = useComposeRef(ref, elementRef); diff --git a/src/SubMenu/PopupTrigger.tsx b/src/SubMenu/PopupTrigger.tsx index 0cbea7f8..3392ede7 100644 --- a/src/SubMenu/PopupTrigger.tsx +++ b/src/SubMenu/PopupTrigger.tsx @@ -82,7 +82,7 @@ export default function PopupTrigger({ }; // Delay to change visible - const visibleRef = React.useRef(); + const visibleRef = React.useRef(undefined); React.useEffect(() => { visibleRef.current = raf(() => { setInnerVisible(visible); diff --git a/src/SubMenu/index.tsx b/src/SubMenu/index.tsx index 542da8c5..e95e96dd 100644 --- a/src/SubMenu/index.tsx +++ b/src/SubMenu/index.tsx @@ -117,8 +117,8 @@ const InternalSubMenu = React.forwardRef((props, re const subMenuPrefixCls = `${prefixCls}-submenu`; const mergedDisabled = contextDisabled || disabled; - const elementRef = React.useRef(); - const popupRef = React.useRef(); + const elementRef = React.useRef(null); + const popupRef = React.useRef(null); // ================================ Warn ================================ if (process.env.NODE_ENV !== 'production' && warnKey) { diff --git a/src/hooks/useAccessibility.ts b/src/hooks/useAccessibility.ts index 12ca3372..259130cb 100644 --- a/src/hooks/useAccessibility.ts +++ b/src/hooks/useAccessibility.ts @@ -177,9 +177,9 @@ export function useAccessibility( originOnKeyDown?: React.KeyboardEventHandler, ): React.KeyboardEventHandler { - const rafRef = React.useRef(); + const rafRef = React.useRef(undefined); - const activeRef = React.useRef(); + const activeRef = React.useRef(undefined); activeRef.current = activeKey; const cleanRaf = () => { diff --git a/tsconfig.json b/tsconfig.json index 4f500c7b..d55f5b17 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,6 +20,6 @@ "strictBindCallApply": false, "module": "ESNext" }, - "include": ["react-compat.d.ts", "global.d.ts", "src", "docs", ".dumirc.ts", ".fatherrc.ts"], + "include": ["global.d.ts", "src", "docs", ".dumirc.ts", ".fatherrc.ts"], "exclude": ["node_modules", "lib", "es", "dist", "docs-dist", ".dumi"] } From 525c01d54977b5ed92a5c6af71c7048e048f7287 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 14:24:15 +0800 Subject: [PATCH 11/19] chore: fix upgraded test tooling --- tests/__snapshots__/Keyboard.spec.tsx.snap | 2 +- tests/__snapshots__/Menu.spec.tsx.snap | 2 +- tests/__snapshots__/MenuItem.spec.tsx.snap | 2 +- tests/__snapshots__/Options.spec.tsx.snap | 2 +- tests/__snapshots__/Responsive.spec.tsx.snap | 2 +- tests/__snapshots__/SubMenu.spec.tsx.snap | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/__snapshots__/Keyboard.spec.tsx.snap b/tests/__snapshots__/Keyboard.spec.tsx.snap index 1230f1be..ed660858 100644 --- a/tests/__snapshots__/Keyboard.spec.tsx.snap +++ b/tests/__snapshots__/Keyboard.spec.tsx.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`Menu.Keyboard no data-menu-id by init 1`] = ` HTMLCollection [ diff --git a/tests/__snapshots__/Menu.spec.tsx.snap b/tests/__snapshots__/Menu.spec.tsx.snap index 7864c25c..0a912294 100644 --- a/tests/__snapshots__/Menu.spec.tsx.snap +++ b/tests/__snapshots__/Menu.spec.tsx.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`Menu render role listbox renders menu correctly 1`] = ` HTMLCollection [ diff --git a/tests/__snapshots__/MenuItem.spec.tsx.snap b/tests/__snapshots__/MenuItem.spec.tsx.snap index c4e28718..ec4292af 100644 --- a/tests/__snapshots__/MenuItem.spec.tsx.snap +++ b/tests/__snapshots__/MenuItem.spec.tsx.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`MenuItem overwrite default role should set extra to group option 1`] = `

  • Date: Wed, 1 Jul 2026 14:34:33 +0800 Subject: [PATCH 12/19] fix: preserve React peer dependency range --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5d5444eb..308ad41f 100644 --- a/package.json +++ b/package.json @@ -90,8 +90,8 @@ "typescript": "^6.0.3" }, "peerDependencies": { - "react": "^19.2.7", - "react-dom": "^19.2.7" + "react": ">=16.9.0", + "react-dom": ">=16.9.0" }, "lint-staged": { "*": "prettier --write --ignore-unknown" From 6474a1a64a2510ea102def367b4fde36a6c32306 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 18:29:18 +0800 Subject: [PATCH 13/19] fix: keep submenu item title type compatible --- src/interface.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/interface.ts b/src/interface.ts index 20d8885e..1e013c41 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -12,7 +12,6 @@ export interface SubMenuType extends ItemSharedProps { type?: 'submenu'; label?: React.ReactNode; - title?: string; children: ItemType[]; From 8bd7a5398f5f6ba6d07db5f62215d9bf5af66a3c Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 18:36:14 +0800 Subject: [PATCH 14/19] docs: use npm install in README --- README.md | 4 ++-- README.zh-CN.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b3f07cce..309fe8e6 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ export default () => ( Run the local dumi site: ```bash -ut install +npm install npm start ``` @@ -161,7 +161,7 @@ type ItemType = ## Development ```bash -ut install +npm install npm start npm test npm run tsc diff --git a/README.zh-CN.md b/README.zh-CN.md index e94acff8..5b100362 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -70,7 +70,7 @@ export default () => ( 运葌本地 dumi η«™η‚ΉοΌš ```bash -ut install +npm install npm start ``` @@ -161,7 +161,7 @@ type ItemType = ## ζœ¬εœ°εΌ€ε‘ ```bash -ut install +npm install npm start npm test npm run tsc From 3adabcae06132d8f71e2c826bd3c7bfe507a51a5 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 18:46:33 +0800 Subject: [PATCH 15/19] chore: remove redundant strict tsconfig flags --- tsconfig.json | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index d55f5b17..dfb2bd32 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,13 +11,7 @@ "@@/*": ["./.dumi/tmp/*"], "@rc-component/menu": ["./src/index.ts"] }, - "noImplicitAny": false, - "strictNullChecks": false, - "strictPropertyInitialization": false, - "strictFunctionTypes": false, "strict": false, - "noImplicitThis": false, - "strictBindCallApply": false, "module": "ESNext" }, "include": ["global.d.ts", "src", "docs", ".dumirc.ts", ".fatherrc.ts"], From 2221909803fdd847b257b350dad2430d442456a5 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 19:12:59 +0800 Subject: [PATCH 16/19] chore: remove manual global test declarations --- global.d.ts | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/global.d.ts b/global.d.ts index 85e4e4e7..e0bd355c 100644 --- a/global.d.ts +++ b/global.d.ts @@ -8,42 +8,4 @@ declare module '*.css'; declare module '*.less'; declare module 'jsonp'; -declare namespace JSX { - type Element = React.JSX.Element; - interface ElementClass extends React.JSX.ElementClass {} - interface ElementAttributesProperty extends React.JSX.ElementAttributesProperty {} - interface ElementChildrenAttribute extends React.JSX.ElementChildrenAttribute {} - type LibraryManagedAttributes = React.JSX.LibraryManagedAttributes; - interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {} - interface IntrinsicClassAttributes extends React.JSX.IntrinsicClassAttributes {} - interface IntrinsicElements extends React.JSX.IntrinsicElements {} -} - -declare namespace jest { - interface Matchers { - lastCalledWith(...expected: unknown[]): R; - nthCalledWith(nthCall: number, ...expected: unknown[]): R; - toBeCalled(): R; - toBeCalledTimes(expected: number): R; - toBeCalledWith(...expected: unknown[]): R; - } -} - -declare const vi: { - fn: any = (...args: any[]) => any>( - implementation?: T, - ) => jest.MockedFunction; - mock: (moduleName: string, factory?: (importOriginal: () => Promise) => unknown) => void; - spyOn: typeof jest.spyOn; - useFakeTimers: () => void; - useRealTimers: () => void; - advanceTimersByTime: (msToRun: number) => void; - clearAllTimers: () => void; - runAllTimers: () => void; - importActual: (moduleName: string) => Promise; - clearAllMocks: () => void; - resetAllMocks: () => void; - restoreAllMocks: () => void; -}; - declare module 'moment/locale/zh-cn'; From 1e8c3e5d6192f3be125a8c86e7add400895fd954 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 19:32:34 +0800 Subject: [PATCH 17/19] fix: address review type compatibility --- src/interface.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/interface.ts b/src/interface.ts index 1e013c41..84f95719 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -12,6 +12,7 @@ export interface SubMenuType extends ItemSharedProps { type?: 'submenu'; label?: React.ReactNode; + title?: React.ReactNode; children: ItemType[]; From 29a441d08ce06312c6c5365b3202f8006d014dc6 Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 2 Jul 2026 11:54:02 +0800 Subject: [PATCH 18/19] chore: migrate to native eslint flat config --- .eslintrc.js | 23 ------- eslint.config.mjs | 155 +++++++++++++++++++++++++--------------------- package.json | 11 +--- 3 files changed, 86 insertions(+), 103 deletions(-) delete mode 100644 .eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index feefc81a..00000000 --- a/.eslintrc.js +++ /dev/null @@ -1,23 +0,0 @@ -module.exports = { - extends: [require.resolve('@umijs/fabric/dist/eslint')], - rules: { - 'import/no-extraneous-dependencies': 0, - 'import/no-named-as-default': 0, - 'no-template-curly-in-string': 0, - 'prefer-promise-reject-errors': 0, - 'react/no-array-index-key': 0, - 'react/require-default-props': 0, - 'react/sort-comp': 0, - 'react/no-find-dom-node': 1, - '@typescript-eslint/no-explicit-any': 0, - 'jsx-a11y/label-has-associated-control': 0, - 'jsx-a11y/label-has-for': 0, - '@typescript-eslint/no-empty-interface': 0, - '@typescript-eslint/consistent-indexed-object-style': 0, - '@typescript-eslint/switch-exhaustiveness-check': 0, - '@typescript-eslint/no-parameter-properties': 0, - '@typescript-eslint/no-throw-literal': 0, - '@typescript-eslint/type-annotation-spacing': 0, - '@typescript-eslint/ban-types': 0, - }, -}; diff --git a/eslint.config.mjs b/eslint.config.mjs index 8eabc428..d19be2a6 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,68 +1,23 @@ -import { FlatCompat } from '@eslint/eslintrc'; import js from '@eslint/js'; -import tsEslintPlugin from '@typescript-eslint/eslint-plugin'; -import { createRequire } from 'node:module'; -import path from 'node:path'; -import { fileURLToPath } from 'node:url'; +import { defineConfig } from 'eslint/config'; +import prettier from 'eslint-config-prettier'; +import jest from 'eslint-plugin-jest'; +import react from 'eslint-plugin-react'; +import reactHooks from 'eslint-plugin-react-hooks'; +import globals from 'globals'; +import tseslint from 'typescript-eslint'; -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); -const require = createRequire(import.meta.url); - -const compat = new FlatCompat({ - baseDirectory: __dirname, - recommendedConfig: js.configs.recommended, - allConfig: js.configs.all, -}); - -const legacyConfig = require('./.eslintrc.js'); -const recommendedTsRulesConfig = tsEslintPlugin.configs.recommended; -const recommendedTsRulesObject = Array.isArray(recommendedTsRulesConfig) - ? recommendedTsRulesConfig.reduce((rules, config) => ({ ...rules, ...(config.rules || {}) }), {}) - : recommendedTsRulesConfig?.rules || {}; -const recommendedTsRules = new Set(Object.keys(recommendedTsRulesObject)); - -function hasCurrentTsRule(ruleName) { - const tsRuleName = ruleName.replace('@typescript-eslint/', ''); - return Boolean(tsEslintPlugin.rules[tsRuleName]); -} -const localTsRules = new Set( - Object.keys(legacyConfig.rules || {}).filter( - ruleName => ruleName.startsWith('@typescript-eslint/') && hasCurrentTsRule(ruleName), - ), -); - -const noopRule = { - meta: { type: 'problem', docs: {}, schema: [] }, - create: () => ({}), -}; - -function normalizeConfig(config) { - const next = { ...config }; - - if (next.plugins?.['@typescript-eslint']) { - next.plugins = { ...next.plugins }; - delete next.plugins['@typescript-eslint']; - } - - if (next.rules) { - next.rules = Object.fromEntries( - Object.entries(next.rules).filter(([ruleName]) => { - if (ruleName.startsWith('@babel/')) { - return false; - } - if (!ruleName.startsWith('@typescript-eslint/')) { - return true; - } - return recommendedTsRules.has(ruleName) || localTsRules.has(ruleName); - }), - ); - } - - return next; -} - -export default [ +export default defineConfig([ + { + plugins: { + '@typescript-eslint': tseslint.plugin, + }, + }, + { + linterOptions: { + reportUnusedDisableDirectives: 'off', + }, + }, { ignores: [ 'node_modules/', @@ -74,27 +29,83 @@ export default [ '.dumi/', '.doc/', '.vercel/', - '.eslintrc.js', 'src/index.d.ts', ], }, { + files: ['**/*.{js,jsx,ts,tsx}'], + extends: [ + js.configs.recommended, + react.configs.flat.recommended, + react.configs.flat['jsx-runtime'], + prettier, + ], plugins: { - '@typescript-eslint': { - ...tsEslintPlugin, - rules: { - ...tsEslintPlugin.rules, - 'consistent-type-exports': noopRule, - }, + 'react-hooks': reactHooks, + }, + languageOptions: { + globals: { + ...globals.browser, + ...globals.node, + }, + }, + settings: { + react: { + version: 'detect', }, }, + rules: { + 'no-async-promise-executor': 'off', + 'no-empty-pattern': 'off', + 'no-irregular-whitespace': 'off', + 'no-prototype-builtins': 'off', + 'no-useless-escape': 'off', + 'no-extra-boolean-cast': 'off', + 'no-undef': 'off', + 'no-unused-vars': 'off', + 'react/no-find-dom-node': 'off', + 'react/display-name': 'off', + 'react/no-unknown-property': 'off', + 'react/prop-types': 'off', + 'react-hooks/exhaustive-deps': 'warn', + 'react-hooks/rules-of-hooks': 'error', + }, }, - ...compat.config(legacyConfig).map(normalizeConfig), { + files: ['**/*.{ts,tsx}'], + extends: [...tseslint.configs.recommended], rules: { + '@typescript-eslint/ban-ts-comment': 'off', '@typescript-eslint/no-empty-object-type': 'off', + '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-unsafe-function-type': 'off', + '@typescript-eslint/no-unnecessary-type-constraint': 'off', '@typescript-eslint/no-unused-vars': 'off', }, }, -]; + { + files: ['src/**/*.{ts,tsx}'], + languageOptions: { + parserOptions: { + projectService: true, + tsconfigRootDir: import.meta.dirname, + }, + }, + }, + { + files: ['tests/**/*.{js,jsx,ts,tsx}', '**/*.{test,spec}.{js,jsx,ts,tsx}'], + extends: [jest.configs['flat/recommended']], + rules: { + 'jest/no-disabled-tests': 'off', + 'jest/no-done-callback': 'off', + 'jest/no-identical-title': 'off', + 'jest/expect-expect': 'off', + 'jest/no-alias-methods': 'off', + 'jest/no-conditional-expect': 'off', + 'jest/no-export': 'off', + 'jest/no-standalone-expect': 'off', + 'jest/valid-expect': 'off', + 'jest/valid-title': 'off', + }, + }, +]); diff --git a/package.json b/package.json index 308ad41f..76272dfe 100644 --- a/package.json +++ b/package.json @@ -53,9 +53,6 @@ "clsx": "^2.1.1" }, "devDependencies": { - "@babel/eslint-parser": "^7.29.7", - "@babel/eslint-plugin": "^7.29.7", - "@eslint/eslintrc": "^3.3.5", "@eslint/js": "^9.39.4", "@rc-component/father-plugin": "^2.2.0", "@rc-component/np": "^1.0.4", @@ -67,9 +64,6 @@ "@types/react": "^19.2.17", "@types/react-dom": "^19.2.3", "@types/warning": "^3.0.4", - "@typescript-eslint/eslint-plugin": "^8.62.1", - "@typescript-eslint/parser": "^8.62.1", - "@umijs/fabric": "^4.0.1", "cross-env": "^10.1.0", "dumi": "^2.4.38", "eslint": "^9.39.4", @@ -77,9 +71,9 @@ "eslint-plugin-jest": "^29.15.4", "eslint-plugin-react": "^7.37.5", "eslint-plugin-react-hooks": "^7.1.1", - "eslint-plugin-unicorn": "^65.0.1", "father": "^4.6.24", "gh-pages": "^6.3.0", + "globals": "^17.7.0", "husky": "^9.1.7", "less": "^4.6.7", "lint-staged": "^17.0.8", @@ -87,7 +81,8 @@ "rc-test": "^7.1.3", "react": "^19.2.7", "react-dom": "^19.2.7", - "typescript": "^6.0.3" + "typescript": "^6.0.3", + "typescript-eslint": "^8.62.1" }, "peerDependencies": { "react": ">=16.9.0", From 5e0f44b20a361968b02d45736cc905eb32e630a3 Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 3 Jul 2026 10:58:07 +0800 Subject: [PATCH 19/19] chore: address review comments --- eslint.config.mjs | 10 +++++++--- src/interface.ts | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index d19be2a6..40f08ec9 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,5 +1,7 @@ import js from '@eslint/js'; import { defineConfig } from 'eslint/config'; +import { dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; import prettier from 'eslint-config-prettier'; import jest from 'eslint-plugin-jest'; import react from 'eslint-plugin-react'; @@ -7,6 +9,8 @@ import reactHooks from 'eslint-plugin-react-hooks'; import globals from 'globals'; import tseslint from 'typescript-eslint'; +const tsconfigRootDir = dirname(fileURLToPath(import.meta.url)); + export default defineConfig([ { plugins: { @@ -15,7 +19,7 @@ export default defineConfig([ }, { linterOptions: { - reportUnusedDisableDirectives: 'off', + reportUnusedDisableDirectives: 'warn', }, }, { @@ -26,10 +30,10 @@ export default defineConfig([ 'lib/', 'dist/', 'docs-dist/', + '.docs-dist/', '.dumi/', '.doc/', '.vercel/', - 'src/index.d.ts', ], }, { @@ -88,7 +92,7 @@ export default defineConfig([ languageOptions: { parserOptions: { projectService: true, - tsconfigRootDir: import.meta.dirname, + tsconfigRootDir, }, }, }, diff --git a/src/interface.ts b/src/interface.ts index 84f95719..20d8885e 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -12,7 +12,7 @@ export interface SubMenuType extends ItemSharedProps { type?: 'submenu'; label?: React.ReactNode; - title?: React.ReactNode; + title?: string; children: ItemType[];