From 63f19ab632a96caddf28a6dc7915c57a487516f3 Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 29 Jun 2026 18:17:30 +0800 Subject: [PATCH 01/17] chore: update maintenance dependencies --- .github/dependabot.yml | 8 +++++ README.md | 2 +- README.zh-CN.md | 2 +- eslint.config.mjs | 79 ++++++++++++++++++++++++++++++++++++++++++ examples/multiple.tsx | 8 ++--- global.d.ts | 56 ++++++++++++++++++++++++++++++ package.json | 34 +++++++++++------- react-compat.d.ts | 16 +++++++++ tests/index.spec.tsx | 14 ++++---- tsconfig.json | 10 ++++-- 10 files changed, 201 insertions(+), 28 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 bd393a23..13c61ba8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

@rc-component/cascader

-

Ant Design Part of the Ant Design ecosystem.

+

Ant Design Part of the Ant Design ecosystem.

🧭 React Cascader component for selecting values from hierarchical option trees, with search, multiple selection, async loading, and custom rendering.

diff --git a/README.zh-CN.md b/README.zh-CN.md index c94208fc..4d1329f2 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -1,6 +1,6 @@

@rc-component/cascader

-

Ant Design Ant Design 生态的一部分。

+

Ant Design Ant Design 生态的一部分。

🧭 React 级联选择组件,支持层级选项、搜索、多选、异步加载和自定义渲染。

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/examples/multiple.tsx b/examples/multiple.tsx index f88aaa47..bc6ed377 100644 --- a/examples/multiple.tsx +++ b/examples/multiple.tsx @@ -58,11 +58,11 @@ const Demo = () => { return ( ); diff --git a/global.d.ts b/global.d.ts new file mode 100644 index 00000000..e35e1773 --- /dev/null +++ b/global.d.ts @@ -0,0 +1,56 @@ +/// +/// +/// +/// +/// + +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 5b6f0ea2..0243f7aa 100644 --- a/package.json +++ b/package.json @@ -54,34 +54,42 @@ "@rc-component/form": "^1.4.0", "@rc-component/np": "^1.0.4", "@rc-component/trigger": "^3.0.0", - "@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", - "@typescript-eslint/eslint-plugin": "^5.62.0", - "@typescript-eslint/parser": "^5.62.0", + "@typescript-eslint/eslint-plugin": "^8.62.0", + "@typescript-eslint/parser": "^8.62.0", "@umijs/fabric": "^4.0.1", "array-tree-filter": "^3.0.2", "cheerio": "1.0.0-rc.12", "core-js": "^3.40.0", "cross-env": "^10.1.0", "dumi": "^2.4.35", - "eslint": "^8.57.1", - "eslint-plugin-jest": "^27.9.0", - "eslint-plugin-unicorn": "^56.0.1", + "eslint": "^9.39.4", + "eslint-plugin-jest": "^29.15.3", + "eslint-plugin-unicorn": "^65.0.1", "father": "^4.6.23", "gh-pages": "^6.3.0", "glob": "^13.0.6", "less": "^4.6.7", "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", "husky": "^9.1.7", - "lint-staged": "^16.4.0" + "lint-staged": "^17.0.8", + "@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", + "@testing-library/jest-dom": "^6.9.1" }, "peerDependencies": { "react": ">=18.0.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/tests/index.spec.tsx b/tests/index.spec.tsx index ec3ee811..39ba0ac7 100644 --- a/tests/index.spec.tsx +++ b/tests/index.spec.tsx @@ -100,8 +100,8 @@ describe('Cascader.Basic', () => { @@ -123,8 +123,8 @@ describe('Cascader.Basic', () => { @@ -864,10 +864,10 @@ describe('Cascader.Basic', () => { }, ], }, - ]} - value={[['parent'], ['normal', 'child']]} + ] as any} + value={[['parent'], ['normal', 'child']] as any} checkable - onChange={onTypeChange} + onChange={onTypeChange as any} />, ); diff --git a/tsconfig.json b/tsconfig.json index 2b912c63..d96692c3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,7 @@ "jsx": "react", "declaration": true, "skipLibCheck": true, - "strict": true, + "strict": false, "esModuleInterop": true, "paths": { "@/*": [ @@ -19,6 +19,12 @@ "src/index.ts" ] }, - "ignoreDeprecations": "5.0" + "ignoreDeprecations": "6.0", + "noImplicitAny": false, + "strictNullChecks": false, + "strictPropertyInitialization": false, + "strictFunctionTypes": false, + "noImplicitThis": false, + "strictBindCallApply": false } } From b475c12b67dbe6deef5f74d4065b7d4352c036a4 Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Jun 2026 10:19:21 +0800 Subject: [PATCH 02/17] fix: align TypeScript and ESLint compatibility --- eslint.config.mjs | 33 +++++++++++++++++++++------------ global.d.ts | 8 -------- tsconfig.json | 13 ++++++------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index b25fb5dd..f556e5a4 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -15,7 +15,9 @@ const compat = new FlatCompat({ allConfig: js.configs.all, }); -const recommendedTsRules = new Set(Object.keys(tsEslintPlugin.configs.recommended.rules || {})); +const recommendedTsRules = new Set( + Object.keys(tsEslintPlugin.configs.recommended.rules || {}), +); const noopRule = { meta: { type: 'problem', docs: {}, schema: [] }, create: () => ({}), @@ -25,16 +27,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) { @@ -43,7 +37,10 @@ function normalizeConfig(config) { if (!ruleName.startsWith('@typescript-eslint/')) { return true; } - return recommendedTsRules.has(ruleName) || ruleName === '@typescript-eslint/ban-types'; + return ( + recommendedTsRules.has(ruleName) || + ruleName === '@typescript-eslint/ban-types' + ); }), ); } @@ -67,6 +64,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 e35e1773..97e90a38 100644 --- a/global.d.ts +++ b/global.d.ts @@ -44,13 +44,5 @@ 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 d96692c3..c9b019f2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,7 @@ { "compilerOptions": { "target": "esnext", - "moduleResolution": "node", - "baseUrl": "./", + "moduleResolution": "bundler", "jsx": "react", "declaration": true, "skipLibCheck": true, @@ -10,21 +9,21 @@ "esModuleInterop": true, "paths": { "@/*": [ - "src/*" + "./src/*" ], "@@/*": [ - "src/.umi/*" + "./src/.umi/*" ], "@rc-component/cascader": [ - "src/index.ts" + "./src/index.ts" ] }, - "ignoreDeprecations": "6.0", "noImplicitAny": false, "strictNullChecks": false, "strictPropertyInitialization": false, "strictFunctionTypes": false, "noImplicitThis": false, - "strictBindCallApply": false + "strictBindCallApply": false, + "module": "ESNext" } } From 598615f2e0b79b96cc35620bca2f482282d5c1b5 Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Jun 2026 10:49:23 +0800 Subject: [PATCH 03/17] chore: use testing-library dom events --- package.json | 23 ++++++++++++----------- tests/Panel.spec.tsx | 3 ++- tests/checkable.spec.tsx | 3 ++- tests/fieldNames.spec.tsx | 3 ++- tests/index.spec.tsx | 3 ++- tests/keyboard.spec.tsx | 3 ++- tests/loadData.spec.tsx | 3 ++- tests/search.limit.spec.tsx | 3 ++- tests/search.spec.tsx | 3 ++- tests/selector.spec.tsx | 3 ++- tests/util.ts | 3 ++- 11 files changed, 32 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 0243f7aa..8f83d3b1 100644 --- a/package.json +++ b/package.json @@ -50,10 +50,16 @@ "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/form": "^1.4.0", "@rc-component/np": "^1.0.4", "@rc-component/trigger": "^3.0.0", + "@testing-library/dom": "^10.4.1", + "@testing-library/jest-dom": "^6.9.1", "@testing-library/react": "^16.3.2", "@types/jest": "^30.0.0", "@types/node": "^26.0.1", @@ -69,27 +75,22 @@ "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", "glob": "^13.0.6", + "husky": "^9.1.7", "less": "^4.6.7", + "lint-staged": "^17.0.8", "prettier": "^3.9.0", "rc-test": "^7.1.3", "react": "^19.2.7", "react-dom": "^19.2.7", - "typescript": "^6.0.3", - "husky": "^9.1.7", - "lint-staged": "^17.0.8", - "@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", - "@testing-library/jest-dom": "^6.9.1" + "typescript": "^6.0.3" }, "peerDependencies": { "react": ">=18.0.0", diff --git a/tests/Panel.spec.tsx b/tests/Panel.spec.tsx index 10a1e5f1..b21f3750 100644 --- a/tests/Panel.spec.tsx +++ b/tests/Panel.spec.tsx @@ -1,4 +1,5 @@ -import { fireEvent, render } from '@testing-library/react'; +import { fireEvent } from '@testing-library/dom'; +import { render } from '@testing-library/react'; import React from 'react'; import Cascader, { type CascaderProps } from '../src'; diff --git a/tests/checkable.spec.tsx b/tests/checkable.spec.tsx index 6cea7c03..5345e26b 100644 --- a/tests/checkable.spec.tsx +++ b/tests/checkable.spec.tsx @@ -1,4 +1,5 @@ -import { fireEvent, render } from '@testing-library/react'; +import { fireEvent } from '@testing-library/dom'; +import { render } from '@testing-library/react'; import React from 'react'; import Cascader from '../src'; import { addressOptions } from './demoOptions'; diff --git a/tests/fieldNames.spec.tsx b/tests/fieldNames.spec.tsx index 6732a281..6f7535ef 100644 --- a/tests/fieldNames.spec.tsx +++ b/tests/fieldNames.spec.tsx @@ -1,5 +1,6 @@ +import { fireEvent } from '@testing-library/dom'; import React from 'react'; -import { fireEvent, render } from '@testing-library/react'; +import { render } from '@testing-library/react'; import Cascader from '../src'; import { clickOption, expectOpen } from './util'; diff --git a/tests/index.spec.tsx b/tests/index.spec.tsx index 39ba0ac7..11c18735 100644 --- a/tests/index.spec.tsx +++ b/tests/index.spec.tsx @@ -1,10 +1,11 @@ +import { fireEvent } from '@testing-library/dom'; import { spyElementPrototypes } from '@rc-component/util'; import React, { useEffect, useState } from 'react'; import type { CascaderRef, BaseOptionType, CascaderProps } from '../src'; import Cascader from '../src'; import { addressOptions, addressOptionsForUneven, optionsForActiveMenuItems } from './demoOptions'; import * as commonUtil from '../src/utils/commonUtil'; -import { act, fireEvent, render } from '@testing-library/react'; +import { act, render } from '@testing-library/react'; import { KeyCode } from '@rc-component/util'; import { expectOpen, selectOption, isOpen, clickOption } from './util'; diff --git a/tests/keyboard.spec.tsx b/tests/keyboard.spec.tsx index 3c91c0f8..002ea15b 100644 --- a/tests/keyboard.spec.tsx +++ b/tests/keyboard.spec.tsx @@ -1,4 +1,5 @@ -import { act, fireEvent, render } from '@testing-library/react'; +import { fireEvent } from '@testing-library/dom'; +import { act, render } from '@testing-library/react'; import { KeyCode } from '@rc-component/util'; import type { CascaderProps } from '../src'; import Cascader from '../src'; diff --git a/tests/loadData.spec.tsx b/tests/loadData.spec.tsx index cb0ebfab..e2a6f799 100644 --- a/tests/loadData.spec.tsx +++ b/tests/loadData.spec.tsx @@ -1,5 +1,6 @@ +import { fireEvent } from '@testing-library/dom'; import React from 'react'; -import { act, fireEvent, render } from '@testing-library/react'; +import { act, render } from '@testing-library/react'; import type { CascaderProps } from '../src'; import Cascader from '../src'; import { clickOption } from './util'; diff --git a/tests/search.limit.spec.tsx b/tests/search.limit.spec.tsx index 5cc2c483..1cc6c74e 100644 --- a/tests/search.limit.spec.tsx +++ b/tests/search.limit.spec.tsx @@ -1,5 +1,6 @@ +import { fireEvent } from '@testing-library/dom'; import React from 'react'; -import { fireEvent, render } from '@testing-library/react'; +import { render } from '@testing-library/react'; import Cascader from '../src'; describe('Cascader.Search', () => { diff --git a/tests/search.spec.tsx b/tests/search.spec.tsx index a130cecf..9e850c63 100644 --- a/tests/search.spec.tsx +++ b/tests/search.spec.tsx @@ -1,4 +1,5 @@ -import { fireEvent, render } from '@testing-library/react'; +import { fireEvent } from '@testing-library/dom'; +import { render } from '@testing-library/react'; import { KeyCode, resetWarned } from '@rc-component/util'; import React from 'react'; import Cascader, { type DefaultOptionType } from '../src'; diff --git a/tests/selector.spec.tsx b/tests/selector.spec.tsx index 73e4dca9..3d6b4747 100644 --- a/tests/selector.spec.tsx +++ b/tests/selector.spec.tsx @@ -1,5 +1,6 @@ +import { fireEvent } from '@testing-library/dom'; import React, { useState } from 'react'; -import { fireEvent, render } from '@testing-library/react'; +import { render } from '@testing-library/react'; import Cascader from '../src'; import { addressOptions } from './demoOptions'; import { expectOpen, clickOption } from './util'; diff --git a/tests/util.ts b/tests/util.ts index b76ee202..4f9df9cb 100644 --- a/tests/util.ts +++ b/tests/util.ts @@ -1,4 +1,5 @@ -import { act, createEvent, fireEvent } from '@testing-library/react'; +import { createEvent, fireEvent } from '@testing-library/dom'; +import { act } from '@testing-library/react'; export function expectOpen(dom: HTMLElement, open = true) { act(() => { From 363aa609b85111f6c859595a3b1b5fccb786e3b4 Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Jun 2026 11:14:36 +0800 Subject: [PATCH 04/17] test: keep react testing event behavior --- tests/Panel.spec.tsx | 3 +-- tests/checkable.spec.tsx | 3 +-- tests/fieldNames.spec.tsx | 3 +-- tests/index.spec.tsx | 3 +-- tests/keyboard.spec.tsx | 3 +-- tests/loadData.spec.tsx | 3 +-- tests/search.limit.spec.tsx | 3 +-- tests/search.spec.tsx | 3 +-- tests/selector.spec.tsx | 3 +-- tests/util.ts | 3 +-- 10 files changed, 10 insertions(+), 20 deletions(-) diff --git a/tests/Panel.spec.tsx b/tests/Panel.spec.tsx index b21f3750..10a1e5f1 100644 --- a/tests/Panel.spec.tsx +++ b/tests/Panel.spec.tsx @@ -1,5 +1,4 @@ -import { fireEvent } from '@testing-library/dom'; -import { render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; import React from 'react'; import Cascader, { type CascaderProps } from '../src'; diff --git a/tests/checkable.spec.tsx b/tests/checkable.spec.tsx index 5345e26b..6cea7c03 100644 --- a/tests/checkable.spec.tsx +++ b/tests/checkable.spec.tsx @@ -1,5 +1,4 @@ -import { fireEvent } from '@testing-library/dom'; -import { render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; import React from 'react'; import Cascader from '../src'; import { addressOptions } from './demoOptions'; diff --git a/tests/fieldNames.spec.tsx b/tests/fieldNames.spec.tsx index 6f7535ef..6732a281 100644 --- a/tests/fieldNames.spec.tsx +++ b/tests/fieldNames.spec.tsx @@ -1,6 +1,5 @@ -import { fireEvent } from '@testing-library/dom'; import React from 'react'; -import { render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; import Cascader from '../src'; import { clickOption, expectOpen } from './util'; diff --git a/tests/index.spec.tsx b/tests/index.spec.tsx index 11c18735..39ba0ac7 100644 --- a/tests/index.spec.tsx +++ b/tests/index.spec.tsx @@ -1,11 +1,10 @@ -import { fireEvent } from '@testing-library/dom'; import { spyElementPrototypes } from '@rc-component/util'; import React, { useEffect, useState } from 'react'; import type { CascaderRef, BaseOptionType, CascaderProps } from '../src'; import Cascader from '../src'; import { addressOptions, addressOptionsForUneven, optionsForActiveMenuItems } from './demoOptions'; import * as commonUtil from '../src/utils/commonUtil'; -import { act, render } from '@testing-library/react'; +import { act, fireEvent, render } from '@testing-library/react'; import { KeyCode } from '@rc-component/util'; import { expectOpen, selectOption, isOpen, clickOption } from './util'; diff --git a/tests/keyboard.spec.tsx b/tests/keyboard.spec.tsx index 002ea15b..3c91c0f8 100644 --- a/tests/keyboard.spec.tsx +++ b/tests/keyboard.spec.tsx @@ -1,5 +1,4 @@ -import { fireEvent } from '@testing-library/dom'; -import { act, render } from '@testing-library/react'; +import { act, fireEvent, render } from '@testing-library/react'; import { KeyCode } from '@rc-component/util'; import type { CascaderProps } from '../src'; import Cascader from '../src'; diff --git a/tests/loadData.spec.tsx b/tests/loadData.spec.tsx index e2a6f799..cb0ebfab 100644 --- a/tests/loadData.spec.tsx +++ b/tests/loadData.spec.tsx @@ -1,6 +1,5 @@ -import { fireEvent } from '@testing-library/dom'; import React from 'react'; -import { act, render } from '@testing-library/react'; +import { act, fireEvent, render } from '@testing-library/react'; import type { CascaderProps } from '../src'; import Cascader from '../src'; import { clickOption } from './util'; diff --git a/tests/search.limit.spec.tsx b/tests/search.limit.spec.tsx index 1cc6c74e..5cc2c483 100644 --- a/tests/search.limit.spec.tsx +++ b/tests/search.limit.spec.tsx @@ -1,6 +1,5 @@ -import { fireEvent } from '@testing-library/dom'; import React from 'react'; -import { render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; import Cascader from '../src'; describe('Cascader.Search', () => { diff --git a/tests/search.spec.tsx b/tests/search.spec.tsx index 9e850c63..a130cecf 100644 --- a/tests/search.spec.tsx +++ b/tests/search.spec.tsx @@ -1,5 +1,4 @@ -import { fireEvent } from '@testing-library/dom'; -import { render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; import { KeyCode, resetWarned } from '@rc-component/util'; import React from 'react'; import Cascader, { type DefaultOptionType } from '../src'; diff --git a/tests/selector.spec.tsx b/tests/selector.spec.tsx index 3d6b4747..73e4dca9 100644 --- a/tests/selector.spec.tsx +++ b/tests/selector.spec.tsx @@ -1,6 +1,5 @@ -import { fireEvent } from '@testing-library/dom'; import React, { useState } from 'react'; -import { render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; import Cascader from '../src'; import { addressOptions } from './demoOptions'; import { expectOpen, clickOption } from './util'; diff --git a/tests/util.ts b/tests/util.ts index 4f9df9cb..b76ee202 100644 --- a/tests/util.ts +++ b/tests/util.ts @@ -1,5 +1,4 @@ -import { createEvent, fireEvent } from '@testing-library/dom'; -import { act } from '@testing-library/react'; +import { act, createEvent, fireEvent } from '@testing-library/react'; export function expectOpen(dom: HTMLElement, open = true) { act(() => { From dce8a81f97ceb69576295a3d72cdc93e63a7a6ab Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Jun 2026 19:02:27 +0800 Subject: [PATCH 05/17] chore: address review comments --- eslint.config.mjs | 30 ++++++++++-------------------- react-compat.d.ts | 4 ---- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index f556e5a4..3166a6d9 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -15,13 +15,14 @@ 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 }; @@ -37,10 +38,7 @@ function normalizeConfig(config) { if (!ruleName.startsWith('@typescript-eslint/')) { return true; } - return ( - recommendedTsRules.has(ruleName) || - ruleName === '@typescript-eslint/ban-types' - ); + return recommendedTsRules.has(ruleName); }), ); } @@ -66,20 +64,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 2dc8994a9a78ec949fe44c79416f2076da141622 Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Jun 2026 19:15:11 +0800 Subject: [PATCH 06/17] 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 3166a6d9..0e70eed9 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -23,6 +23,10 @@ const recommendedTsRulesObject = Array.isArray(recommendedTsRulesConfig) ) : recommendedTsRulesConfig?.rules || {}; const recommendedTsRules = new Set(Object.keys(recommendedTsRulesObject)); +const noopRule = { + meta: { type: 'problem', docs: {}, schema: [] }, + create: () => ({}), +}; function normalizeConfig(config) { const next = { ...config }; @@ -64,7 +68,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 e799706018b58142dda288437480d8caaa70b4cf Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 12:56:40 +0800 Subject: [PATCH 07/17] chore: tighten cascader generic usage --- examples/multiple.tsx | 13 +++--- tests/index.spec.tsx | 92 ++++++++++++++++++++++++------------------- 2 files changed, 58 insertions(+), 47 deletions(-) diff --git a/examples/multiple.tsx b/examples/multiple.tsx index bc6ed377..60983a33 100644 --- a/examples/multiple.tsx +++ b/examples/multiple.tsx @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-shadow */ import React, { useState } from 'react'; import '../assets/index.less'; import type { CascaderProps } from '../src'; @@ -7,7 +6,7 @@ import type { Option2 } from './utils'; const { SHOW_CHILD } = Cascader; -const optionLists = [ +const optionLists: Option2[] = [ { value: 'zhejiang', label: 'Zhejiang', @@ -56,13 +55,13 @@ const Demo = () => { // 直接选中一级选项,但是此时二级选项没有全部选中 return ( - checkable - options={options as any} + options={options} showCheckedStrategy={SHOW_CHILD} - loadData={loadData as any} - value={value as any} - onChange={onChange as any} + loadData={loadData} + value={value} + onChange={onChange} changeOnSelect /> ); diff --git a/tests/index.spec.tsx b/tests/index.spec.tsx index 39ba0ac7..4f080fdc 100644 --- a/tests/index.spec.tsx +++ b/tests/index.spec.tsx @@ -63,7 +63,9 @@ describe('Cascader.Basic', () => { selectOption(container, 0, 0); expect( - container.querySelector('.rc-cascader-menu-item')!.classList.contains('rc-cascader-menu-item-active') + container + .querySelector('.rc-cascader-menu-item')! + .classList.contains('rc-cascader-menu-item-active'), ).toBeTruthy(); // Menu 2 @@ -79,7 +81,7 @@ describe('Cascader.Basic', () => { container .querySelectorAll('.rc-cascader-menu')[1] .querySelector('.rc-cascader-menu-item')! - .classList.contains('rc-cascader-menu-item-active') + .classList.contains('rc-cascader-menu-item-active'), ).toBeTruthy(); // Menu 3 @@ -97,11 +99,11 @@ describe('Cascader.Basic', () => { it('should support showCheckedStrategy parent', () => { const { container } = render( - checkable changeOnSelect - options={addressOptions as any} - onChange={onMultipleChange as any} + options={addressOptions} + onChange={onMultipleChange} showCheckedStrategy={'SHOW_PARENT'} > @@ -189,7 +191,7 @@ describe('Cascader.Basic', () => { container .querySelectorAll('.rc-cascader-menu')[0] .querySelector('.rc-cascader-menu-item')! - .classList.contains('rc-cascader-menu-item-active') + .classList.contains('rc-cascader-menu-item-active'), ).toBeTruthy(); // Menu 2 @@ -208,7 +210,7 @@ describe('Cascader.Basic', () => { container .querySelectorAll('.rc-cascader-menu')[1] .querySelector('.rc-cascader-menu-item')! - .classList.contains('rc-cascader-menu-item-active') + .classList.contains('rc-cascader-menu-item-active'), ).toBeTruthy(); // Menu 3 @@ -353,7 +355,7 @@ describe('Cascader.Basic', () => { rerender( - + , ); expect(container.querySelector('.rc-cascader-menu-item')!.textContent).toEqual('BambooLight'); }); @@ -399,7 +401,9 @@ describe('Cascader.Basic', () => { fireEvent.click(menu1Items[0]); expect( - container.querySelector('.rc-cascader-menu-item')!.classList.contains('rc-cascader-menu-item-disabled'), + container + .querySelector('.rc-cascader-menu-item')! + .classList.contains('rc-cascader-menu-item-disabled'), ).toBe(true); menus = container.querySelectorAll('.rc-cascader-menu'); expect(menus.length).toBe(1); @@ -420,12 +424,13 @@ describe('Cascader.Basic', () => { />, ); - expect(container.querySelector('.rc-cascader-selection-item-disabled')!.textContent).toEqual('福州'); + expect(container.querySelector('.rc-cascader-selection-item-disabled')!.textContent).toEqual( + '福州', + ); expect( container .querySelector('.rc-cascader-selection-item:not(.rc-cascader-selection-item-disabled)')! - .querySelector('.rc-cascader-selection-item-content')! - .textContent, + .querySelector('.rc-cascader-selection-item-content')!.textContent, ).toEqual('朝阳区'); }); }); @@ -720,8 +725,12 @@ describe('Cascader.Basic', () => { clickOption(container, 1, 0); expect(container.querySelectorAll('li.rc-cascader-menu-item-active')).toHaveLength(2); - expect(container.querySelectorAll('li.rc-cascader-menu-item-active')[0].textContent).toEqual('Bamboo'); - expect(container.querySelectorAll('li.rc-cascader-menu-item-active')[1].textContent).toEqual('Little'); + expect(container.querySelectorAll('li.rc-cascader-menu-item-active')[0].textContent).toEqual( + 'Bamboo', + ); + expect(container.querySelectorAll('li.rc-cascader-menu-item-active')[1].textContent).toEqual( + 'Little', + ); }); it('expandTrigger: hover', () => { @@ -749,7 +758,9 @@ describe('Cascader.Basic', () => { clickOption(container, 1, 0, 'mouseEnter'); expect(container.querySelectorAll('li.rc-cascader-menu-item-active')).toHaveLength(1); - expect(container.querySelectorAll('li.rc-cascader-menu-item-active')[0].textContent).toEqual('Bamboo'); + expect(container.querySelectorAll('li.rc-cascader-menu-item-active')[0].textContent).toEqual( + 'Bamboo', + ); }); describe('the defaultValue should be activated the first time it is opened', () => { @@ -837,37 +848,38 @@ describe('Cascader.Basic', () => { />, ); - expect(container.querySelector('.rc-cascader-content')!.textContent).toEqual('Normal / Child'); + expect(container.querySelector('.rc-cascader-content')!.textContent).toEqual( + 'Normal / Child', + ); }); it('multiple', () => { - const onTypeChange: ( - values: string[][], - options: { label: React.ReactNode; value: string }[][], - ) => void = jest.fn(); - - const { container } = render( - Parent, value: 'parent' }, + const onTypeChange: CascaderProps['onChange'] = jest.fn(); + const options: BaseOptionType[] = [ + { label: Parent, value: 'parent' }, + { + label: 'Normal', + value: 'normal', + children: [ { - label: 'Normal', - value: 'normal', - children: [ - { - label: Child, - value: 'child', - }, - { - label: 'Child2', - value: 'child2', - }, - ], + label: Child, + value: 'child', + }, + { + label: 'Child2', + value: 'child2', }, - ] as any} - value={[['parent'], ['normal', 'child']] as any} + ], + }, + ]; + const value: string[][] = [['parent'], ['normal', 'child']]; + + const { container } = render( + + options={options} + value={value} checkable - onChange={onTypeChange as any} + onChange={onTypeChange} />, ); From bdd9087eb4a5f901bb6c78c4350536d9b924bc7e Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 13:13:28 +0800 Subject: [PATCH 08/17] chore: enable strict type checking --- tsconfig.json | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index c9b019f2..caff830c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,25 +5,13 @@ "jsx": "react", "declaration": true, "skipLibCheck": true, - "strict": false, + "strict": true, "esModuleInterop": true, "paths": { - "@/*": [ - "./src/*" - ], - "@@/*": [ - "./src/.umi/*" - ], - "@rc-component/cascader": [ - "./src/index.ts" - ] + "@/*": ["./src/*"], + "@@/*": ["./src/.umi/*"], + "@rc-component/cascader": ["./src/index.ts"] }, - "noImplicitAny": false, - "strictNullChecks": false, - "strictPropertyInitialization": false, - "strictFunctionTypes": false, - "noImplicitThis": false, - "strictBindCallApply": false, "module": "ESNext" } } From 5047a62e6423ea6ebf7fd4a21b5c1adca64f4105 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 13:21:14 +0800 Subject: [PATCH 09/17] docs: use ut install for local setup --- README.md | 5 +-- README.zh-CN.md | 103 ++++++++++++++++++++++++------------------------ vercel.json | 2 +- 3 files changed, 54 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 13c61ba8..eb9e5418 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,6 @@

English | 简体中文

- ## Highlights | Area | Support | @@ -68,7 +67,7 @@ export default () => ( Run the local dumi site: ```bash -npm install +ut install npm start ``` @@ -137,7 +136,7 @@ Then open `http://localhost:8000`. ## Development ```bash -npm install +ut install npm start ``` diff --git a/README.zh-CN.md b/README.zh-CN.md index 4d1329f2..c464dae4 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -15,15 +15,14 @@

English | 简体中文

- ## 特性 -| 范围 | 支持 | -| --------- | ---------------------------------------------------------------- | -| 数据 | 嵌套选项、字段名映射和禁用节点 | -| 选择 | 单选、多选、勾选和逐级选择流程 | -| 搜索 | 受控搜索、自定义过滤、自定义排序和自定义渲染 | -| 加载 | 通过 `loadData` 异步加载选项 | +| 范围 | 支持 | +| ---- | -------------------------------------------- | +| 数据 | 嵌套选项、字段名映射和禁用节点 | +| 选择 | 单选、多选、勾选和逐级选择流程 | +| 搜索 | 受控搜索、自定义过滤、自定义排序和自定义渲染 | +| 加载 | 通过 `loadData` 异步加载选项 | | 渲染 | 自定义选项标签、下拉内容、图标和展开触发方式 | ## 安装 @@ -68,7 +67,7 @@ export default () => ( 运行本地 dumi 站点: ```bash -npm install +ut install npm start ``` @@ -78,66 +77,66 @@ npm start ### Cascader -| 参数 | 类型 | 默认值 | 说明 | -| -------------------- | ------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- | +| 参数 | 类型 | 默认值 | 说明 | +| -------------------- | ------------------------------------------------------- | ---------------------------------------------------------- | -------------------------------------------------- | | autoClearSearchValue | boolean | true | 已弃用。请改用 `showSearch.autoClearSearchValue`。 | | builtinPlacements | BuildInPlacements | - | 自定义弹层位置。 | -| changeOnSelect | boolean | false | 选择每个级别时触发 `onChange`。 | -| checkable | boolean \| ReactNode | false | 启用带复选框 UI 的多选。 | -| children | ReactElement | - | 触发元素。 | -| classNames | Semantic class name map | - | 选择器和弹层元素的语义 className。 | -| defaultValue | string[] \| number[] \| Array | - | 初始选中值。 | -| displayRender | `(label, selectedOptions) => ReactNode` | - | 渲染选定的标签。 | -| expandIcon | ReactNode | `>` | 自定义展开图标。 | -| expandTrigger | `click` \| `hover` | `click` | 触发扩展下一个选项级别的操作。 | -| fieldNames | `{ label?: string; value?: string; children?: string }` | `{ label: 'label', value: 'value', children: 'children' }` | 自定义选项字段名称。 | -| loadData | `(selectedOptions) => void` | - | 异步加载子选项。 | -| loadingIcon | ReactNode | - | 自定义加载图标。 | -| onChange | `(value, selectedOptions) => void` | - | 选择更改时调用。 | -| onPopupVisibleChange | `(open: boolean) => void` | - | 当弹层窗口可见性发生变化时调用。 | +| changeOnSelect | boolean | false | 选择每个级别时触发 `onChange`。 | +| checkable | boolean \| ReactNode | false | 启用带复选框 UI 的多选。 | +| children | ReactElement | - | 触发元素。 | +| classNames | Semantic class name map | - | 选择器和弹层元素的语义 className。 | +| defaultValue | string[] \| number[] \| Array | - | 初始选中值。 | +| displayRender | `(label, selectedOptions) => ReactNode` | - | 渲染选定的标签。 | +| expandIcon | ReactNode | `>` | 自定义展开图标。 | +| expandTrigger | `click` \| `hover` | `click` | 触发扩展下一个选项级别的操作。 | +| fieldNames | `{ label?: string; value?: string; children?: string }` | `{ label: 'label', value: 'value', children: 'children' }` | 自定义选项字段名称。 | +| loadData | `(selectedOptions) => void` | - | 异步加载子选项。 | +| loadingIcon | ReactNode | - | 自定义加载图标。 | +| onChange | `(value, selectedOptions) => void` | - | 选择更改时调用。 | +| onPopupVisibleChange | `(open: boolean) => void` | - | 当弹层窗口可见性发生变化时调用。 | | onSearch | `(value: string) => void` | - | 已弃用。请改用 `showSearch.onSearch`。 | -| open | boolean | - | 受控的弹层窗口可见性。 | -| optionRender | `(option) => ReactNode` | - | 自定义选项渲染器。 | -| options | Option[] | - | 分层选项数据。 | -| placement | Select placement | - | 弹层窗口放置。 | -| popupClassName | string | - | 弹层 className。 | -| popupMenuColumnStyle | CSSProperties | - | 每个弹出菜单列的样式。 | -| prefixCls | string | `rc-cascader` | className 前缀。 | +| open | boolean | - | 受控的弹层窗口可见性。 | +| optionRender | `(option) => ReactNode` | - | 自定义选项渲染器。 | +| options | Option[] | - | 分层选项数据。 | +| placement | Select placement | - | 弹层窗口放置。 | +| popupClassName | string | - | 弹层 className。 | +| popupMenuColumnStyle | CSSProperties | - | 每个弹出菜单列的样式。 | +| prefixCls | string | `rc-cascader` | className 前缀。 | | searchValue | string | - | 已弃用。请改用 `showSearch.searchValue`。 | -| showCheckedStrategy | `SHOW_PARENT` \| `SHOW_CHILD` | `SHOW_PARENT` | 在多种模式下渲染检查值的策略。 | -| showSearch | boolean \| SearchConfig | false | 启用并配置搜索。 | -| styles | Semantic style map | - | 选择器和弹层元素的语义样式。 | -| value | string[] \| number[] \| Array | - | 受控选中值。 | +| showCheckedStrategy | `SHOW_PARENT` \| `SHOW_CHILD` | `SHOW_PARENT` | 在多种模式下渲染检查值的策略。 | +| showSearch | boolean \| SearchConfig | false | 启用并配置搜索。 | +| styles | Semantic style map | - | 选择器和弹层元素的语义样式。 | +| value | string[] \| number[] \| Array | - | 受控选中值。 | `Cascader` 还接受来自 `@rc-component/select` `BaseSelect` 的公共属性,但私有仅选择属性除外,例如 `mode` 、 `labelInValue` 、 `showSearch` 和 `tokenSeparators`。 ### SearchConfig -| 参数 | 类型 | 默认值 | 说明 | -| -------------------- | -------------------------------------------------------- | ------- | ---------------------------------------------------------- | -| autoClearSearchValue | boolean | true | 选择项目后清除搜索文本。 | -| filter | `(inputValue, options, fieldNames) => boolean` | - | 返回 `true` 以在搜索结果中包含选项路径。 | -| limit | number \| false | 50 | 限制过滤项目的数量。 | -| matchInputWidth | boolean | true | 搜索结果宽度是否与输入宽度匹配。 | -| onSearch | `(value: string) => void` | - | 当搜索文本更改时调用。 | -| render | `(inputValue, path, prefixCls, fieldNames) => ReactNode` | - | 渲染过滤后的选项路径。 | -| searchValue | string | - | 受控搜索文本。 | -| sort | `(a, b, inputValue, fieldNames) => number` | - | 对过滤后的选项路径进行排序。 | +| 参数 | 类型 | 默认值 | 说明 | +| -------------------- | -------------------------------------------------------- | ------ | ---------------------------------------- | +| autoClearSearchValue | boolean | true | 选择项目后清除搜索文本。 | +| filter | `(inputValue, options, fieldNames) => boolean` | - | 返回 `true` 以在搜索结果中包含选项路径。 | +| limit | number \| false | 50 | 限制过滤项目的数量。 | +| matchInputWidth | boolean | true | 搜索结果宽度是否与输入宽度匹配。 | +| onSearch | `(value: string) => void` | - | 当搜索文本更改时调用。 | +| render | `(inputValue, path, prefixCls, fieldNames) => ReactNode` | - | 渲染过滤后的选项路径。 | +| searchValue | string | - | 受控搜索文本。 | +| sort | `(a, b, inputValue, fieldNames) => number` | - | 对过滤后的选项路径进行排序。 | ### 选项 -| 参数 | 类型 | 默认值 | 说明 | -| --------------- | ------------------------ | ------- | ------------------------------------------------ | -| children | Option[] | - | 子选项。 | -| disabled | boolean | false | 禁用此选项。 | -| disableCheckbox | boolean | false | 在多种模式下禁用此选项的复选框。 | -| label | ReactNode | - | 显示标签。 | -| value | string \| number \| null | - | 选项值。 | +| 参数 | 类型 | 默认值 | 说明 | +| --------------- | ------------------------ | ------ | -------------------------------- | +| children | Option[] | - | 子选项。 | +| disabled | boolean | false | 禁用此选项。 | +| disableCheckbox | boolean | false | 在多种模式下禁用此选项的复选框。 | +| label | ReactNode | - | 显示标签。 | +| value | string \| number \| null | - | 选项值。 | ## 本地开发 ```bash -npm install +ut install npm start ``` 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 6541e925cc9e779872d7c2ffb7915ffa011ae199 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 13:28:48 +0800 Subject: [PATCH 10/17] 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 a6c5db048bb684c4d957a6c8779f6ca294345a98 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 14:00:50 +0800 Subject: [PATCH 11/17] chore: align maintenance dependencies --- eslint.config.mjs | 8 ++++---- package.json | 16 ++++++++-------- react-compat.d.ts | 12 ------------ 3 files changed, 12 insertions(+), 24 deletions(-) delete mode 100644 react-compat.d.ts diff --git a/eslint.config.mjs b/eslint.config.mjs index 0e70eed9..76ab8dac 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -17,10 +17,7 @@ const compat = new FlatCompat({ const recommendedTsRulesConfig = tsEslintPlugin.configs.recommended; const recommendedTsRulesObject = Array.isArray(recommendedTsRulesConfig) - ? recommendedTsRulesConfig.reduce( - (rules, config) => ({ ...rules, ...(config.rules || {}) }), - {}, - ) + ? recommendedTsRulesConfig.reduce((rules, config) => ({ ...rules, ...(config.rules || {}) }), {}) : recommendedTsRulesConfig?.rules || {}; const recommendedTsRules = new Set(Object.keys(recommendedTsRulesObject)); const noopRule = { @@ -39,6 +36,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 8f83d3b1..e475e853 100644 --- a/package.json +++ b/package.json @@ -66,35 +66,35 @@ "@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", "array-tree-filter": "^3.0.2", "cheerio": "1.0.0-rc.12", "core-js": "^3.40.0", "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", "glob": "^13.0.6", "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": ">=18.0.0", - "react-dom": ">=18.0.0" + "react": "^19.2.7", + "react-dom": "^19.2.7" }, "publishConfig": { "access": "public" 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

; -} From d7fd67bf93f625bc73e2641bea8242a24ad5a327 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 14:23:22 +0800 Subject: [PATCH 12/17] chore: fix upgraded test tooling --- tests/__snapshots__/index.spec.tsx.snap | 2 +- tests/__snapshots__/search.spec.tsx.snap | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/__snapshots__/index.spec.tsx.snap b/tests/__snapshots__/index.spec.tsx.snap index 17ebb6e1..da0604c7 100644 --- a/tests/__snapshots__/index.spec.tsx.snap +++ b/tests/__snapshots__/index.spec.tsx.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`Cascader.Basic should not show title when title is falsy 1`] = `

    From 7debb094f52decf0140e306ed61f07daaddedf12 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 14:33:29 +0800 Subject: [PATCH 13/17] 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 e475e853..aee0a977 100644 --- a/package.json +++ b/package.json @@ -93,8 +93,8 @@ "typescript": "^6.0.3" }, "peerDependencies": { - "react": "^19.2.7", - "react-dom": "^19.2.7" + "react": ">=18.0.0", + "react-dom": ">=18.0.0" }, "publishConfig": { "access": "public" From 633301e4319e1c244cc6d0e638a1d430536bfa82 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 18:34:55 +0800 Subject: [PATCH 14/17] 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 eb9e5418..30e6c44e 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ export default () => ( Run the local dumi site: ```bash -ut install +npm install npm start ``` @@ -136,7 +136,7 @@ Then open `http://localhost:8000`. ## Development ```bash -ut install +npm install npm start ``` diff --git a/README.zh-CN.md b/README.zh-CN.md index c464dae4..a0792e9a 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -67,7 +67,7 @@ export default () => ( 运行本地 dumi 站点: ```bash -ut install +npm install npm start ``` @@ -136,7 +136,7 @@ npm start ## 本地开发 ```bash -ut install +npm install npm start ``` From d4e8441d393f15175505b12136ffcad38c335add Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 1 Jul 2026 19:12:01 +0800 Subject: [PATCH 15/17] chore: remove manual global test declarations --- global.d.ts | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/global.d.ts b/global.d.ts index 97e90a38..e0bd355c 100644 --- a/global.d.ts +++ b/global.d.ts @@ -8,41 +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 e5ecdbd7bb686c2fb38fe08c030b9c44e4ae01f8 Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 2 Jul 2026 11:53:57 +0800 Subject: [PATCH 16/17] chore: migrate to native eslint flat config --- .eslintrc.js | 17 ------ eslint.config.mjs | 143 +++++++++++++++++++++++++++------------------- package.json | 11 +--- 3 files changed, 86 insertions(+), 85 deletions(-) delete mode 100644 .eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 6e0fa311..00000000 --- a/.eslintrc.js +++ /dev/null @@ -1,17 +0,0 @@ -const base = require('@umijs/fabric/dist/eslint'); - -module.exports = { - ...base, - rules: { - ...base.rules, - 'no-template-curly-in-string': 0, - 'prefer-promise-reject-errors': 0, - 'react/no-array-index-key': 0, - 'react/sort-comp': 0, - '@typescript-eslint/no-explicit-any': 0, - 'jsx-a11y/label-has-associated-control': 0, - 'jsx-a11y/label-has-for': 0, - 'import/no-extraneous-dependencies': 0, - 'no-shadow': 0 - }, -}; diff --git a/eslint.config.mjs b/eslint.config.mjs index 76ab8dac..d19be2a6 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,56 +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 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)); -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); - }), - ); - } - - return next; -} - -export default [ +export default defineConfig([ + { + plugins: { + '@typescript-eslint': tseslint.plugin, + }, + }, + { + linterOptions: { + reportUnusedDisableDirectives: 'off', + }, + }, { ignores: [ 'node_modules/', @@ -62,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(require('./.eslintrc.js')).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 aee0a977..06f272ca 100644 --- a/package.json +++ b/package.json @@ -50,9 +50,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/form": "^1.4.0", @@ -66,9 +63,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", "array-tree-filter": "^3.0.2", "cheerio": "1.0.0-rc.12", "core-js": "^3.40.0", @@ -79,10 +73,10 @@ "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", "glob": "^13.0.6", + "globals": "^17.7.0", "husky": "^9.1.7", "less": "^4.6.7", "lint-staged": "^17.0.8", @@ -90,7 +84,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": ">=18.0.0", From 1cb502770de62f268b4807a95fed774cf9d38dbf Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 3 Jul 2026 10:58:02 +0800 Subject: [PATCH 17/17] chore: address review comments --- eslint.config.mjs | 10 +++++++--- tests/index.spec.tsx | 4 ++-- 2 files changed, 9 insertions(+), 5 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/tests/index.spec.tsx b/tests/index.spec.tsx index 4f080fdc..66508ff3 100644 --- a/tests/index.spec.tsx +++ b/tests/index.spec.tsx @@ -125,8 +125,8 @@ describe('Cascader.Basic', () => {