From 22f29ec9d4f929b314c0611ab807cc8420b88d30 Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 29 Jun 2026 18:19:19 +0800 Subject: [PATCH 1/4] chore: update maintenance dependencies --- .github/dependabot.yml | 8 ++++ README.md | 2 +- README.zh-CN.md | 2 +- eslint.config.mjs | 79 +++++++++++++++++++++++++++++++++++ global.d.ts | 58 +++++++++++++++++++++++++ package.json | 29 +++++++++---- react-compat.d.ts | 16 +++++++ src/utils/legacyUtil.ts | 8 ++-- src/utils/warningPropsUtil.ts | 26 ++++++------ tsconfig.json | 19 ++++++++- 10 files changed, 217 insertions(+), 30 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 e48b94ed..7906ed19 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

@rc-component/select

-

Ant Design Part of the Ant Design ecosystem.

+

Ant Design Part of the Ant Design ecosystem.

๐ŸŽฏ Composable Select component for React, with search, async-friendly option data, custom rendering, and virtual scrolling.

diff --git a/README.zh-CN.md b/README.zh-CN.md index b84b8763..63759d62 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -1,6 +1,6 @@

@rc-component/select

-

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/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 c0570d6d..400f93f8 100644 --- a/package.json +++ b/package.json @@ -59,26 +59,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", "@umijs/fabric": "^4.0.1", "babel-jest": "^29.7.0", "dumi": "^2.4.35", - "eslint": "^8.57.1", + "eslint": "^9.39.4", "father": "^4.6.23", "husky": "^9.1.7", "jsonp": "^0.2.1", "less": "^4.6.7", - "lint-staged": "^16.4.0", + "lint-staged": "^17.0.8", "prettier": "^3.9.0", "querystring": "^0.2.1", "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" }, "publishConfig": { "access": "public" 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/utils/legacyUtil.ts b/src/utils/legacyUtil.ts index 3e9a449a..cd069edb 100644 --- a/src/utils/legacyUtil.ts +++ b/src/utils/legacyUtil.ts @@ -3,12 +3,12 @@ import { toArray } from '@rc-component/util'; import type { BaseOptionType, DefaultOptionType } from '../Select'; function convertNodeToOption( - node: React.ReactElement, + node: React.ReactElement, ): OptionType { const { key, props: { children, value, ...restProps }, - } = node as React.ReactElement; + } = node as React.ReactElement; return { key, value: value !== undefined ? value : key, children, ...restProps }; } @@ -18,7 +18,7 @@ export function convertChildrenToData { + .map((node: React.ReactElement, index: number): OptionType | null => { if (!React.isValidElement(node) || !node.type) { return null; } @@ -27,7 +27,7 @@ export function convertChildrenToData & { type: { isSelectOptGroup?: boolean } }; if (optionOnly || !isSelectOptGroup) { return convertNodeToOption(node); diff --git a/src/utils/warningPropsUtil.ts b/src/utils/warningPropsUtil.ts index c5560894..e6f96ae3 100644 --- a/src/utils/warningPropsUtil.ts +++ b/src/utils/warningPropsUtil.ts @@ -116,19 +116,19 @@ function warningProps(props: SelectProps) { return false; } if (type.isSelectOptGroup) { - const allChildrenValid = toNodeArray(node.props.children).every( - (subNode: React.ReactElement) => { - if ( - !React.isValidElement(subNode) || - !node.type || - (subNode.type as { isSelectOption?: boolean }).isSelectOption - ) { - return true; - } - invalidateChildType = subNode.type; - return false; - }, - ); + const allChildrenValid = toNodeArray( + (node as React.ReactElement).props.children, + ).every((subNode: React.ReactElement) => { + if ( + !React.isValidElement(subNode) || + !node.type || + (subNode.type as { isSelectOption?: boolean }).isSelectOption + ) { + return true; + } + invalidateChildType = subNode.type; + return false; + }); if (allChildrenValid) { return false; diff --git a/tsconfig.json b/tsconfig.json index eec0a112..f8433c73 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,22 @@ "@@/*": [".dumi/tmp/*"], "@rc-component/select": ["src/index.ts"] }, - "ignoreDeprecations": "5.0" + "ignoreDeprecations": "6.0", + "noImplicitAny": false, + "strictNullChecks": false, + "strictPropertyInitialization": false, + "strictFunctionTypes": false, + "strict": false, + "noImplicitThis": false, + "strictBindCallApply": false }, - "include": [".dumirc.ts", ".fatherrc.ts", "src", "tests", "docs"] + "include": [ + "react-compat.d.ts", + "global.d.ts", + ".dumirc.ts", + ".fatherrc.ts", + "src", + "tests", + "docs" + ] } From 26d3e8e6f72fdd1455f80af10a84711b093ff065 Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Jun 2026 10:20:53 +0800 Subject: [PATCH 2/4] 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 f8433c73..31eb4b16 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,25 +1,24 @@ { "compilerOptions": { "target": "esnext", - "moduleResolution": "node", - "baseUrl": "./", + "moduleResolution": "bundler", "jsx": "preserve", "declaration": true, "skipLibCheck": true, "esModuleInterop": true, "paths": { - "@/*": ["src/*"], - "@@/*": [".dumi/tmp/*"], - "@rc-component/select": ["src/index.ts"] + "@/*": ["./src/*"], + "@@/*": ["./.dumi/tmp/*"], + "@rc-component/select": ["./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", From d0b16cc5dd7e334f9ea037fdd353b6b99b1e540f Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Jun 2026 10:51:05 +0800 Subject: [PATCH 3/4] chore: use testing-library dom events --- package.json | 25 +++++++++++++------------ tests/Accessibility.test.tsx | 3 ++- tests/BaseSelect.test.tsx | 3 ++- tests/Combobox.test.tsx | 3 ++- tests/Custom.test.tsx | 3 ++- tests/Field.test.tsx | 3 ++- tests/Group.test.tsx | 3 ++- tests/Multiple.test.tsx | 3 ++- tests/OptionList.test.tsx | 3 ++- tests/Popup.test.tsx | 3 ++- tests/Select.test.tsx | 9 ++------- tests/Tags.test.tsx | 3 ++- tests/components.test.tsx | 3 ++- tests/focus.test.tsx | 3 ++- tests/shared/allowClearTest.tsx | 3 ++- tests/shared/blurTest.tsx | 3 ++- tests/shared/hoverTest.tsx | 3 ++- tests/shared/inputFilterTest.tsx | 3 ++- tests/shared/keyDownTest.tsx | 3 ++- tests/utils/common.ts | 2 +- 20 files changed, 50 insertions(+), 37 deletions(-) diff --git a/package.json b/package.json index 400f93f8..4bf83498 100644 --- a/package.json +++ b/package.json @@ -55,19 +55,31 @@ "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/dialog": "^1.10.0", "@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", "@types/node": "^26.0.1", "@types/react": "^19.2.17", "@types/react-dom": "^19.2.3", + "@typescript-eslint/eslint-plugin": "^8.62.0", + "@typescript-eslint/parser": "^8.62.0", "@umijs/fabric": "^4.0.1", "babel-jest": "^29.7.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", "husky": "^9.1.7", "jsonp": "^0.2.1", @@ -78,18 +90,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" }, "publishConfig": { "access": "public" diff --git a/tests/Accessibility.test.tsx b/tests/Accessibility.test.tsx index ef8b90c1..ad3f02c7 100644 --- a/tests/Accessibility.test.tsx +++ b/tests/Accessibility.test.tsx @@ -1,8 +1,9 @@ +import { fireEvent } from '@testing-library/dom'; import * as React from 'react'; import { KeyCode } from '@rc-component/util'; import Select from '../src'; import { injectRunAllTimers, expectOpen, keyDown } from './utils/common'; -import { act, fireEvent, render } from '@testing-library/react'; +import { act, render } from '@testing-library/react'; describe('Select.Accessibility', () => { injectRunAllTimers(jest); diff --git a/tests/BaseSelect.test.tsx b/tests/BaseSelect.test.tsx index d107743d..075fe968 100644 --- a/tests/BaseSelect.test.tsx +++ b/tests/BaseSelect.test.tsx @@ -1,5 +1,6 @@ +import { fireEvent } from '@testing-library/dom'; import type { OptionListProps, RefOptionListProps } from '../src/OptionList'; -import { fireEvent, render } from '@testing-library/react'; +import { render } from '@testing-library/react'; import { forwardRef, act } from 'react'; import BaseSelect from '../src/BaseSelect'; import { waitFakeTimer } from './utils/common'; diff --git a/tests/Combobox.test.tsx b/tests/Combobox.test.tsx index 9b93fafc..a8ff04ad 100644 --- a/tests/Combobox.test.tsx +++ b/tests/Combobox.test.tsx @@ -1,7 +1,8 @@ +import { createEvent, fireEvent } from '@testing-library/dom'; /* eslint-disable max-classes-per-file */ import '@testing-library/jest-dom'; -import { createEvent, fireEvent, render } from '@testing-library/react'; +import { render } from '@testing-library/react'; import { KeyCode, resetWarned } from '@rc-component/util'; import React, { act } from 'react'; import type { SelectProps } from '../src'; diff --git a/tests/Custom.test.tsx b/tests/Custom.test.tsx index 5a60d839..ef6ea7b5 100644 --- a/tests/Custom.test.tsx +++ b/tests/Custom.test.tsx @@ -1,7 +1,8 @@ +import { fireEvent } from '@testing-library/dom'; import * as React from 'react'; import Select from '../src'; import { injectRunAllTimers, waitFakeTimer } from './utils/common'; -import { fireEvent, render } from '@testing-library/react'; +import { render } from '@testing-library/react'; describe('Select.Custom', () => { injectRunAllTimers(jest); diff --git a/tests/Field.test.tsx b/tests/Field.test.tsx index e9e0537e..11a49e4c 100644 --- a/tests/Field.test.tsx +++ b/tests/Field.test.tsx @@ -1,8 +1,9 @@ +import { fireEvent } from '@testing-library/dom'; import React, { act } from 'react'; import Select from '../src'; import type { SelectProps } from '../src'; import { injectRunAllTimers } from './utils/common'; -import { fireEvent, render } from '@testing-library/react'; +import { render } from '@testing-library/react'; describe('Select.Field', () => { injectRunAllTimers(jest); diff --git a/tests/Group.test.tsx b/tests/Group.test.tsx index 50f87178..f65fbb6c 100644 --- a/tests/Group.test.tsx +++ b/tests/Group.test.tsx @@ -1,6 +1,7 @@ +import { fireEvent } from '@testing-library/dom'; import * as React from 'react'; import Select, { OptGroup, Option } from '../src'; -import { fireEvent, render } from '@testing-library/react'; +import { render } from '@testing-library/react'; describe('Select.Group', () => { it('group name support search', () => { diff --git a/tests/Multiple.test.tsx b/tests/Multiple.test.tsx index e234ae83..39f20047 100644 --- a/tests/Multiple.test.tsx +++ b/tests/Multiple.test.tsx @@ -1,3 +1,4 @@ +import { fireEvent } from '@testing-library/dom'; import { KeyCode } from '@rc-component/util'; import React from 'react'; import Select, { Option, OptGroup } from '../src'; @@ -19,7 +20,7 @@ import { keyUp, } from './utils/common'; import allowClearTest from './shared/allowClearTest'; -import { act, fireEvent, render, screen } from '@testing-library/react'; +import { act, render, screen } from '@testing-library/react'; describe('Select.Multiple', () => { injectRunAllTimers(jest); diff --git a/tests/OptionList.test.tsx b/tests/OptionList.test.tsx index 745ca872..5654796e 100644 --- a/tests/OptionList.test.tsx +++ b/tests/OptionList.test.tsx @@ -1,3 +1,4 @@ +import { createEvent, fireEvent } from '@testing-library/dom'; import { KeyCode, spyElementPrototypes } from '@rc-component/util'; import React, { act } from 'react'; import { BaseSelectContext } from '../src/hooks/useBaseProps'; @@ -6,7 +7,7 @@ import OptionList from '../src/OptionList'; import SelectContext from '../src/SelectContext'; import { fillFieldNames, flattenOptions } from '../src/utils/valueUtil'; import { injectRunAllTimers } from './utils/common'; -import { createEvent, fireEvent, render, waitFor } from '@testing-library/react'; +import { render, waitFor } from '@testing-library/react'; import Select from '../src'; jest.mock('../src/utils/platformUtil'); diff --git a/tests/Popup.test.tsx b/tests/Popup.test.tsx index 8b2a371f..69b6f548 100644 --- a/tests/Popup.test.tsx +++ b/tests/Popup.test.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 Select from '../src'; import { injectRunAllTimers } from './utils/common'; diff --git a/tests/Select.test.tsx b/tests/Select.test.tsx index 922aa495..f91951ff 100644 --- a/tests/Select.test.tsx +++ b/tests/Select.test.tsx @@ -1,11 +1,6 @@ +import { createEvent, fireEvent } from '@testing-library/dom'; import type { LabelInValueType } from '@/Select'; -import { - createEvent, - fireEvent, - render, - render as testingRender, - act, -} from '@testing-library/react'; +import { render, render as testingRender, act } from '@testing-library/react'; import { KeyCode, resetWarned, spyElementPrototypes } from '@rc-component/util'; import type { ScrollConfig } from '@rc-component/virtual-list'; import React, { StrictMode } from 'react'; diff --git a/tests/Tags.test.tsx b/tests/Tags.test.tsx index 5a4ad6e6..246a0990 100644 --- a/tests/Tags.test.tsx +++ b/tests/Tags.test.tsx @@ -1,4 +1,5 @@ -import { createEvent, fireEvent, render } from '@testing-library/react'; +import { createEvent, fireEvent } from '@testing-library/dom'; +import { render } from '@testing-library/react'; import { KeyCode } from '@rc-component/util'; import { clsx } from 'clsx'; import * as React from 'react'; diff --git a/tests/components.test.tsx b/tests/components.test.tsx index 8d88e694..bc5b2339 100644 --- a/tests/components.test.tsx +++ b/tests/components.test.tsx @@ -1,4 +1,5 @@ -import { createEvent, fireEvent, render } from '@testing-library/react'; +import { createEvent, fireEvent } from '@testing-library/dom'; +import { render } from '@testing-library/react'; import React from 'react'; import Select from '../src'; import { injectRunAllTimers } from './utils/common'; diff --git a/tests/focus.test.tsx b/tests/focus.test.tsx index dc13cc52..13685a1b 100644 --- a/tests/focus.test.tsx +++ b/tests/focus.test.tsx @@ -1,6 +1,7 @@ +import { fireEvent } from '@testing-library/dom'; import React, { useState, act } from 'react'; import Select from '../src'; -import { fireEvent, render } from '@testing-library/react'; +import { render } from '@testing-library/react'; describe('Select.Focus', () => { beforeEach(() => { diff --git a/tests/shared/allowClearTest.tsx b/tests/shared/allowClearTest.tsx index 012f79fc..acdb63bf 100644 --- a/tests/shared/allowClearTest.tsx +++ b/tests/shared/allowClearTest.tsx @@ -1,6 +1,7 @@ +import { createEvent, fireEvent } from '@testing-library/dom'; import * as React from 'react'; import Select, { Option } from '../../src'; -import { createEvent, fireEvent, render } from '@testing-library/react'; +import { render } from '@testing-library/react'; export default function allowClearTest(mode: any, value: any) { describe('allowClear', () => { diff --git a/tests/shared/blurTest.tsx b/tests/shared/blurTest.tsx index 61c5503d..a953d8eb 100644 --- a/tests/shared/blurTest.tsx +++ b/tests/shared/blurTest.tsx @@ -1,8 +1,9 @@ +import { fireEvent, createEvent } from '@testing-library/dom'; import React from 'react'; import Option from '../../src/Option'; import Select from '../../src/Select'; import { injectRunAllTimers } from '../utils/common'; -import { type RenderResult, render, fireEvent, createEvent, act } from '@testing-library/react'; +import { type RenderResult, render, act } from '@testing-library/react'; export default function blurTest(mode: any) { describe(`blur of ${mode}`, () => { diff --git a/tests/shared/hoverTest.tsx b/tests/shared/hoverTest.tsx index 0c0f39ae..2e1821c7 100644 --- a/tests/shared/hoverTest.tsx +++ b/tests/shared/hoverTest.tsx @@ -1,6 +1,7 @@ +import { fireEvent } from '@testing-library/dom'; import * as React from 'react'; import Select, { Option } from '../../src'; -import { fireEvent, render } from '@testing-library/react'; +import { render } from '@testing-library/react'; export default function hoverTest(mode: any) { it('triggers mouseEnter and mouseLeave', () => { diff --git a/tests/shared/inputFilterTest.tsx b/tests/shared/inputFilterTest.tsx index f189f609..2a54e487 100644 --- a/tests/shared/inputFilterTest.tsx +++ b/tests/shared/inputFilterTest.tsx @@ -1,7 +1,8 @@ +import { fireEvent } from '@testing-library/dom'; import * as React from 'react'; import Option from '../../src/Option'; import Select from '../../src/Select'; -import { act, fireEvent, render } from '@testing-library/react'; +import { act, render } from '@testing-library/react'; export default function inputFilterTest(mode: any) { it('should keep input filter after select when autoClearSearchValue is false', () => { diff --git a/tests/shared/keyDownTest.tsx b/tests/shared/keyDownTest.tsx index 9061de54..28f6f77c 100644 --- a/tests/shared/keyDownTest.tsx +++ b/tests/shared/keyDownTest.tsx @@ -1,7 +1,8 @@ +import { fireEvent } from '@testing-library/dom'; import * as React from 'react'; import Option from '../../src/Option'; import Select from '../../src/Select'; -import { fireEvent, render } from '@testing-library/react'; +import { render } from '@testing-library/react'; export default function keyDownTest(mode: any) { it('triggers keyDown', () => { diff --git a/tests/utils/common.ts b/tests/utils/common.ts index a8da1cce..37060b9e 100644 --- a/tests/utils/common.ts +++ b/tests/utils/common.ts @@ -1,5 +1,5 @@ +import { createEvent, fireEvent } from '@testing-library/dom'; import { act } from 'react'; -import { createEvent, fireEvent } from '@testing-library/react'; export function expectOpen(wrapper: any, open: boolean = true) { if (wrapper instanceof HTMLElement) { From 5f5786a081a37723c39d7c422876e2110411155c Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Jun 2026 11:16:11 +0800 Subject: [PATCH 4/4] test: keep react testing event behavior --- tests/Accessibility.test.tsx | 3 +-- tests/BaseSelect.test.tsx | 3 +-- tests/Combobox.test.tsx | 3 +-- tests/Custom.test.tsx | 3 +-- tests/Field.test.tsx | 3 +-- tests/Group.test.tsx | 3 +-- tests/Multiple.test.tsx | 3 +-- tests/OptionList.test.tsx | 3 +-- tests/Popup.test.tsx | 3 +-- tests/Select.test.tsx | 9 +++++++-- tests/Tags.test.tsx | 3 +-- tests/__snapshots__/ssr.test.tsx.snap | 2 +- tests/components.test.tsx | 3 +-- tests/focus.test.tsx | 3 +-- tests/shared/allowClearTest.tsx | 3 +-- tests/shared/blurTest.tsx | 3 +-- tests/shared/hoverTest.tsx | 3 +-- tests/shared/inputFilterTest.tsx | 3 +-- tests/shared/keyDownTest.tsx | 3 +-- tests/utils/common.ts | 2 +- 20 files changed, 26 insertions(+), 38 deletions(-) diff --git a/tests/Accessibility.test.tsx b/tests/Accessibility.test.tsx index ad3f02c7..ef8b90c1 100644 --- a/tests/Accessibility.test.tsx +++ b/tests/Accessibility.test.tsx @@ -1,9 +1,8 @@ -import { fireEvent } from '@testing-library/dom'; import * as React from 'react'; import { KeyCode } from '@rc-component/util'; import Select from '../src'; import { injectRunAllTimers, expectOpen, keyDown } from './utils/common'; -import { act, render } from '@testing-library/react'; +import { act, fireEvent, render } from '@testing-library/react'; describe('Select.Accessibility', () => { injectRunAllTimers(jest); diff --git a/tests/BaseSelect.test.tsx b/tests/BaseSelect.test.tsx index 075fe968..d107743d 100644 --- a/tests/BaseSelect.test.tsx +++ b/tests/BaseSelect.test.tsx @@ -1,6 +1,5 @@ -import { fireEvent } from '@testing-library/dom'; import type { OptionListProps, RefOptionListProps } from '../src/OptionList'; -import { render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; import { forwardRef, act } from 'react'; import BaseSelect from '../src/BaseSelect'; import { waitFakeTimer } from './utils/common'; diff --git a/tests/Combobox.test.tsx b/tests/Combobox.test.tsx index a8ff04ad..9b93fafc 100644 --- a/tests/Combobox.test.tsx +++ b/tests/Combobox.test.tsx @@ -1,8 +1,7 @@ -import { createEvent, fireEvent } from '@testing-library/dom'; /* eslint-disable max-classes-per-file */ import '@testing-library/jest-dom'; -import { render } from '@testing-library/react'; +import { createEvent, fireEvent, render } from '@testing-library/react'; import { KeyCode, resetWarned } from '@rc-component/util'; import React, { act } from 'react'; import type { SelectProps } from '../src'; diff --git a/tests/Custom.test.tsx b/tests/Custom.test.tsx index ef6ea7b5..5a60d839 100644 --- a/tests/Custom.test.tsx +++ b/tests/Custom.test.tsx @@ -1,8 +1,7 @@ -import { fireEvent } from '@testing-library/dom'; import * as React from 'react'; import Select from '../src'; import { injectRunAllTimers, waitFakeTimer } from './utils/common'; -import { render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; describe('Select.Custom', () => { injectRunAllTimers(jest); diff --git a/tests/Field.test.tsx b/tests/Field.test.tsx index 11a49e4c..e9e0537e 100644 --- a/tests/Field.test.tsx +++ b/tests/Field.test.tsx @@ -1,9 +1,8 @@ -import { fireEvent } from '@testing-library/dom'; import React, { act } from 'react'; import Select from '../src'; import type { SelectProps } from '../src'; import { injectRunAllTimers } from './utils/common'; -import { render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; describe('Select.Field', () => { injectRunAllTimers(jest); diff --git a/tests/Group.test.tsx b/tests/Group.test.tsx index f65fbb6c..50f87178 100644 --- a/tests/Group.test.tsx +++ b/tests/Group.test.tsx @@ -1,7 +1,6 @@ -import { fireEvent } from '@testing-library/dom'; import * as React from 'react'; import Select, { OptGroup, Option } from '../src'; -import { render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; describe('Select.Group', () => { it('group name support search', () => { diff --git a/tests/Multiple.test.tsx b/tests/Multiple.test.tsx index 39f20047..e234ae83 100644 --- a/tests/Multiple.test.tsx +++ b/tests/Multiple.test.tsx @@ -1,4 +1,3 @@ -import { fireEvent } from '@testing-library/dom'; import { KeyCode } from '@rc-component/util'; import React from 'react'; import Select, { Option, OptGroup } from '../src'; @@ -20,7 +19,7 @@ import { keyUp, } from './utils/common'; import allowClearTest from './shared/allowClearTest'; -import { act, render, screen } from '@testing-library/react'; +import { act, fireEvent, render, screen } from '@testing-library/react'; describe('Select.Multiple', () => { injectRunAllTimers(jest); diff --git a/tests/OptionList.test.tsx b/tests/OptionList.test.tsx index 5654796e..745ca872 100644 --- a/tests/OptionList.test.tsx +++ b/tests/OptionList.test.tsx @@ -1,4 +1,3 @@ -import { createEvent, fireEvent } from '@testing-library/dom'; import { KeyCode, spyElementPrototypes } from '@rc-component/util'; import React, { act } from 'react'; import { BaseSelectContext } from '../src/hooks/useBaseProps'; @@ -7,7 +6,7 @@ import OptionList from '../src/OptionList'; import SelectContext from '../src/SelectContext'; import { fillFieldNames, flattenOptions } from '../src/utils/valueUtil'; import { injectRunAllTimers } from './utils/common'; -import { render, waitFor } from '@testing-library/react'; +import { createEvent, fireEvent, render, waitFor } from '@testing-library/react'; import Select from '../src'; jest.mock('../src/utils/platformUtil'); diff --git a/tests/Popup.test.tsx b/tests/Popup.test.tsx index 69b6f548..8b2a371f 100644 --- a/tests/Popup.test.tsx +++ b/tests/Popup.test.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 Select from '../src'; import { injectRunAllTimers } from './utils/common'; diff --git a/tests/Select.test.tsx b/tests/Select.test.tsx index f91951ff..922aa495 100644 --- a/tests/Select.test.tsx +++ b/tests/Select.test.tsx @@ -1,6 +1,11 @@ -import { createEvent, fireEvent } from '@testing-library/dom'; import type { LabelInValueType } from '@/Select'; -import { render, render as testingRender, act } from '@testing-library/react'; +import { + createEvent, + fireEvent, + render, + render as testingRender, + act, +} from '@testing-library/react'; import { KeyCode, resetWarned, spyElementPrototypes } from '@rc-component/util'; import type { ScrollConfig } from '@rc-component/virtual-list'; import React, { StrictMode } from 'react'; diff --git a/tests/Tags.test.tsx b/tests/Tags.test.tsx index 246a0990..5a4ad6e6 100644 --- a/tests/Tags.test.tsx +++ b/tests/Tags.test.tsx @@ -1,5 +1,4 @@ -import { createEvent, fireEvent } from '@testing-library/dom'; -import { render } from '@testing-library/react'; +import { createEvent, fireEvent, render } from '@testing-library/react'; import { KeyCode } from '@rc-component/util'; import { clsx } from 'clsx'; import * as React from 'react'; diff --git a/tests/__snapshots__/ssr.test.tsx.snap b/tests/__snapshots__/ssr.test.tsx.snap index 9f1c6c0f..52f5328b 100644 --- a/tests/__snapshots__/ssr.test.tsx.snap +++ b/tests/__snapshots__/ssr.test.tsx.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Select.SSR should work 1`] = `"

"`; +exports[`Select.SSR should work 1`] = `"
"`; diff --git a/tests/components.test.tsx b/tests/components.test.tsx index bc5b2339..8d88e694 100644 --- a/tests/components.test.tsx +++ b/tests/components.test.tsx @@ -1,5 +1,4 @@ -import { createEvent, fireEvent } from '@testing-library/dom'; -import { render } from '@testing-library/react'; +import { createEvent, fireEvent, render } from '@testing-library/react'; import React from 'react'; import Select from '../src'; import { injectRunAllTimers } from './utils/common'; diff --git a/tests/focus.test.tsx b/tests/focus.test.tsx index 13685a1b..dc13cc52 100644 --- a/tests/focus.test.tsx +++ b/tests/focus.test.tsx @@ -1,7 +1,6 @@ -import { fireEvent } from '@testing-library/dom'; import React, { useState, act } from 'react'; import Select from '../src'; -import { render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; describe('Select.Focus', () => { beforeEach(() => { diff --git a/tests/shared/allowClearTest.tsx b/tests/shared/allowClearTest.tsx index acdb63bf..012f79fc 100644 --- a/tests/shared/allowClearTest.tsx +++ b/tests/shared/allowClearTest.tsx @@ -1,7 +1,6 @@ -import { createEvent, fireEvent } from '@testing-library/dom'; import * as React from 'react'; import Select, { Option } from '../../src'; -import { render } from '@testing-library/react'; +import { createEvent, fireEvent, render } from '@testing-library/react'; export default function allowClearTest(mode: any, value: any) { describe('allowClear', () => { diff --git a/tests/shared/blurTest.tsx b/tests/shared/blurTest.tsx index a953d8eb..61c5503d 100644 --- a/tests/shared/blurTest.tsx +++ b/tests/shared/blurTest.tsx @@ -1,9 +1,8 @@ -import { fireEvent, createEvent } from '@testing-library/dom'; import React from 'react'; import Option from '../../src/Option'; import Select from '../../src/Select'; import { injectRunAllTimers } from '../utils/common'; -import { type RenderResult, render, act } from '@testing-library/react'; +import { type RenderResult, render, fireEvent, createEvent, act } from '@testing-library/react'; export default function blurTest(mode: any) { describe(`blur of ${mode}`, () => { diff --git a/tests/shared/hoverTest.tsx b/tests/shared/hoverTest.tsx index 2e1821c7..0c0f39ae 100644 --- a/tests/shared/hoverTest.tsx +++ b/tests/shared/hoverTest.tsx @@ -1,7 +1,6 @@ -import { fireEvent } from '@testing-library/dom'; import * as React from 'react'; import Select, { Option } from '../../src'; -import { render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; export default function hoverTest(mode: any) { it('triggers mouseEnter and mouseLeave', () => { diff --git a/tests/shared/inputFilterTest.tsx b/tests/shared/inputFilterTest.tsx index 2a54e487..f189f609 100644 --- a/tests/shared/inputFilterTest.tsx +++ b/tests/shared/inputFilterTest.tsx @@ -1,8 +1,7 @@ -import { fireEvent } from '@testing-library/dom'; import * as React from 'react'; import Option from '../../src/Option'; import Select from '../../src/Select'; -import { act, render } from '@testing-library/react'; +import { act, fireEvent, render } from '@testing-library/react'; export default function inputFilterTest(mode: any) { it('should keep input filter after select when autoClearSearchValue is false', () => { diff --git a/tests/shared/keyDownTest.tsx b/tests/shared/keyDownTest.tsx index 28f6f77c..9061de54 100644 --- a/tests/shared/keyDownTest.tsx +++ b/tests/shared/keyDownTest.tsx @@ -1,8 +1,7 @@ -import { fireEvent } from '@testing-library/dom'; import * as React from 'react'; import Option from '../../src/Option'; import Select from '../../src/Select'; -import { render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; export default function keyDownTest(mode: any) { it('triggers keyDown', () => { diff --git a/tests/utils/common.ts b/tests/utils/common.ts index 37060b9e..a8da1cce 100644 --- a/tests/utils/common.ts +++ b/tests/utils/common.ts @@ -1,5 +1,5 @@ -import { createEvent, fireEvent } from '@testing-library/dom'; import { act } from 'react'; +import { createEvent, fireEvent } from '@testing-library/react'; export function expectOpen(wrapper: any, open: boolean = true) { if (wrapper instanceof HTMLElement) {