From fc7d9c49d6ee139f013f62f2c32c7417316d34d3 Mon Sep 17 00:00:00 2001 From: JiaQi <112228030+Yuiai01@users.noreply.github.com> Date: Mon, 27 Mar 2023 10:23:02 +0800 Subject: [PATCH 01/36] fix: filter part props (#606) Co-authored-by: dujiaqi --- src/MenuItem.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/MenuItem.tsx b/src/MenuItem.tsx index 07e7cb09..468c8206 100644 --- a/src/MenuItem.tsx +++ b/src/MenuItem.tsx @@ -38,8 +38,12 @@ export interface MenuItemProps class LegacyMenuItem extends React.Component { render() { const { title, attribute, elementRef, ...restProps } = this.props; - - const passedProps = omit(restProps, ['eventKey']); + + // Here the props are eventually passed to the DOM element. + // React does not recognize non-standard attributes. + // Therefore, remove the props that is not used here. + // ref: https://github.com/ant-design/ant-design/issues/41395 + const passedProps = omit(restProps, ['eventKey', 'popupClassName', 'popupOffset', 'onTitleClick']); warning( !attribute, '`attribute` of Menu.Item is deprecated. Please pass attribute directly.', From b03bc371d64d841b9f52eb74a189a38445832f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Mon, 27 Mar 2023 10:29:53 +0800 Subject: [PATCH 02/36] 9.8.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dfb47edb..d542ae87 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-menu", - "version": "9.8.2", + "version": "9.8.3", "description": "menu ui component for react", "keywords": [ "react", From 62a87329f279d2aacfad2da08fed824b67b45c3e Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Thu, 30 Mar 2023 14:38:16 +0800 Subject: [PATCH 03/36] chore: migrate to dumi@2 (#607) --- .dumirc.ts | 24 ++++++++++++++++++++++++ .gitignore | 8 ++++---- .umirc.ts | 19 ------------------- docs/demo/antd-switch.md | 2 +- docs/demo/antd.md | 2 +- docs/demo/custom-icon.md | 2 +- docs/demo/debug.md | 2 +- docs/demo/fragment.md | 2 +- docs/demo/inlineCollapsed.md | 2 +- docs/demo/items.md | 2 +- docs/demo/keyPath.md | 2 +- docs/demo/menuItemGroup.md | 2 +- docs/demo/multiple.md | 2 +- docs/demo/openKeys.md | 2 +- docs/demo/rtl-antd.md | 2 +- docs/demo/scrollable.md | 2 +- docs/demo/selectedKeys.md | 2 +- docs/demo/single.md | 2 +- package.json | 2 +- tsconfig.json | 14 ++++---------- 20 files changed, 48 insertions(+), 49 deletions(-) create mode 100644 .dumirc.ts delete mode 100644 .umirc.ts diff --git a/.dumirc.ts b/.dumirc.ts new file mode 100644 index 00000000..ebd40b0d --- /dev/null +++ b/.dumirc.ts @@ -0,0 +1,24 @@ +// more config: https://d.umijs.org/config +import { defineConfig } from 'dumi'; + +export default defineConfig({ + themeConfig: { + name: 'rc-menu', + logo: 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4', + nav: [ + { title: 'Demo', link: '/demo/antd'} + ], + }, + favicons: + ['https://avatars0.githubusercontent.com/u/9441414?s=200&v=4'], + outputPath: '.doc', + exportStatic: {}, + mfsu: {}, + styles: [ + ` + .markdown table { + width: auto !important; + } + `, + ] +}); diff --git a/.gitignore b/.gitignore index 216e8631..4fa9a6a6 100644 --- a/.gitignore +++ b/.gitignore @@ -32,7 +32,7 @@ package-lock.json .vscode # umi -.umi -.umi-production -.umi-test -.env.local \ No newline at end of file +.dumi/tmp +.dumi/tmp-test +.dumi/tmp-production +.env.local diff --git a/.umirc.ts b/.umirc.ts deleted file mode 100644 index 6e9d67b6..00000000 --- a/.umirc.ts +++ /dev/null @@ -1,19 +0,0 @@ -// more config: https://d.umijs.org/config -import { defineConfig } from 'dumi'; - -export default defineConfig({ - title: 'rc-menu', - favicon: - 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4', - logo: - 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4', - outputPath: '.doc', - exportStatic: {}, - styles: [ - ` - .markdown table { - width: auto !important; - } - `, - ] -}); \ No newline at end of file diff --git a/docs/demo/antd-switch.md b/docs/demo/antd-switch.md index 2299b8d7..ecafe183 100644 --- a/docs/demo/antd-switch.md +++ b/docs/demo/antd-switch.md @@ -1,3 +1,3 @@ ## antd-switch - \ No newline at end of file + diff --git a/docs/demo/antd.md b/docs/demo/antd.md index 3812591d..40308ad4 100644 --- a/docs/demo/antd.md +++ b/docs/demo/antd.md @@ -1,3 +1,3 @@ ## antd - \ No newline at end of file + diff --git a/docs/demo/custom-icon.md b/docs/demo/custom-icon.md index 88105c2d..2c629341 100644 --- a/docs/demo/custom-icon.md +++ b/docs/demo/custom-icon.md @@ -1,3 +1,3 @@ ## custom-icon - \ No newline at end of file + diff --git a/docs/demo/debug.md b/docs/demo/debug.md index 25e02bfb..baaf3446 100644 --- a/docs/demo/debug.md +++ b/docs/demo/debug.md @@ -1,3 +1,3 @@ ## debug - \ No newline at end of file + diff --git a/docs/demo/fragment.md b/docs/demo/fragment.md index 8cdc6e6b..8d04c249 100644 --- a/docs/demo/fragment.md +++ b/docs/demo/fragment.md @@ -1,3 +1,3 @@ ## fragment - \ No newline at end of file + diff --git a/docs/demo/inlineCollapsed.md b/docs/demo/inlineCollapsed.md index be43f340..4323477b 100644 --- a/docs/demo/inlineCollapsed.md +++ b/docs/demo/inlineCollapsed.md @@ -1,3 +1,3 @@ ## inlineCollapsed - \ No newline at end of file + diff --git a/docs/demo/items.md b/docs/demo/items.md index 75b86e6f..523b1e84 100644 --- a/docs/demo/items.md +++ b/docs/demo/items.md @@ -1,3 +1,3 @@ ## items - \ No newline at end of file + diff --git a/docs/demo/keyPath.md b/docs/demo/keyPath.md index f1fff1eb..5032048a 100644 --- a/docs/demo/keyPath.md +++ b/docs/demo/keyPath.md @@ -1,3 +1,3 @@ ## keyPath - \ No newline at end of file + diff --git a/docs/demo/menuItemGroup.md b/docs/demo/menuItemGroup.md index bf549646..1e165277 100644 --- a/docs/demo/menuItemGroup.md +++ b/docs/demo/menuItemGroup.md @@ -1,3 +1,3 @@ ## menuItemGroup - \ No newline at end of file + diff --git a/docs/demo/multiple.md b/docs/demo/multiple.md index 95b3855f..db64ceb8 100644 --- a/docs/demo/multiple.md +++ b/docs/demo/multiple.md @@ -1,3 +1,3 @@ ## multiple - \ No newline at end of file + diff --git a/docs/demo/openKeys.md b/docs/demo/openKeys.md index f78bf6b9..c176b577 100644 --- a/docs/demo/openKeys.md +++ b/docs/demo/openKeys.md @@ -1,3 +1,3 @@ ## openKeys - \ No newline at end of file + diff --git a/docs/demo/rtl-antd.md b/docs/demo/rtl-antd.md index 7dd19484..cff730d1 100644 --- a/docs/demo/rtl-antd.md +++ b/docs/demo/rtl-antd.md @@ -1,3 +1,3 @@ ## rtl-antd - \ No newline at end of file + diff --git a/docs/demo/scrollable.md b/docs/demo/scrollable.md index 6c31bfdf..3b8bd33b 100644 --- a/docs/demo/scrollable.md +++ b/docs/demo/scrollable.md @@ -1,3 +1,3 @@ ## scrollable - \ No newline at end of file + diff --git a/docs/demo/selectedKeys.md b/docs/demo/selectedKeys.md index 965c5d1c..cee5946a 100644 --- a/docs/demo/selectedKeys.md +++ b/docs/demo/selectedKeys.md @@ -1,3 +1,3 @@ ## selectedKeys - \ No newline at end of file + diff --git a/docs/demo/single.md b/docs/demo/single.md index 13ff200e..3413f99e 100644 --- a/docs/demo/single.md +++ b/docs/demo/single.md @@ -1,3 +1,3 @@ ## single - \ No newline at end of file + diff --git a/package.json b/package.json index d542ae87..b39e5318 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "@types/react-dom": "^16.8.4", "@types/warning": "^3.0.0", "cross-env": "^7.0.0", - "dumi": "^1.1.0", + "dumi": "^2.1.17", "eslint": "^7.0.0", "father": "^4.0.0", "gh-pages": "^3.1.0", diff --git a/tsconfig.json b/tsconfig.json index 2321b878..deb9b8f2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,15 +8,9 @@ "skipLibCheck": true, "esModuleInterop": true, "paths": { - "@/*": [ - "src/*" - ], - "@@/*": [ - "src/.umi/*" - ], - "rc-menu": [ - "src/index.tsx" - ] + "@/*": ["src/*"], + "@@/*": [".dumi/tmp/*"], + "rc-menu": ["src/index.tsx"] } } -} \ No newline at end of file +} From 404a8e100693375b95d17e86795caaa486546619 Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Thu, 30 Mar 2023 16:12:51 +0800 Subject: [PATCH 04/36] chore: make test file ts (#608) * chore: make test file ts * chore: update test --- .github/workflows/main.yml | 12 ++-- package.json | 2 +- .../{Collapsed.spec.js => Collapsed.spec.tsx} | 19 ++++--- tests/{Focus.spec.js => Focus.spec.tsx} | 10 +--- tests/{Menu.spec.js => Menu.spec.tsx} | 55 ++++++++++--------- tests/{MenuItem.spec.js => MenuItem.spec.tsx} | 5 +- tests/Options.spec.tsx | 1 + tests/{Private.spec.js => Private.spec.tsx} | 0 tests/{SubMenu.spec.js => SubMenu.spec.tsx} | 17 +++--- .../{Menu.spec.js.snap => Menu.spec.tsx.snap} | 0 ...em.spec.js.snap => MenuItem.spec.tsx.snap} | 0 ...enu.spec.js.snap => SubMenu.spec.tsx.snap} | 0 12 files changed, 61 insertions(+), 60 deletions(-) rename tests/{Collapsed.spec.js => Collapsed.spec.tsx} (95%) rename tests/{Focus.spec.js => Focus.spec.tsx} (81%) rename tests/{Menu.spec.js => Menu.spec.tsx} (94%) rename tests/{MenuItem.spec.js => MenuItem.spec.tsx} (98%) rename tests/{Private.spec.js => Private.spec.tsx} (100%) rename tests/{SubMenu.spec.js => SubMenu.spec.tsx} (97%) rename tests/__snapshots__/{Menu.spec.js.snap => Menu.spec.tsx.snap} (100%) rename tests/__snapshots__/{MenuItem.spec.js.snap => MenuItem.spec.tsx.snap} (100%) rename tests/__snapshots__/{SubMenu.spec.js.snap => SubMenu.spec.tsx.snap} (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 083300e5..26b2aa31 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,9 +2,9 @@ name: CI on: push: - branches: [ master ] + branches: [ master, next ] pull_request: - branches: [ master ] + branches: [ master, next ] jobs: setup: @@ -43,7 +43,7 @@ jobs: - name: install if: steps.node_modules_cache_id.outputs.cache-hit != 'true' run: npm ci - + lint: runs-on: ubuntu-latest steps: @@ -66,7 +66,7 @@ jobs: run: npm run lint needs: setup - + compile: runs-on: ubuntu-latest steps: @@ -89,7 +89,7 @@ jobs: run: npm run compile needs: setup - + coverage: runs-on: ubuntu-latest steps: @@ -111,4 +111,4 @@ jobs: - name: coverage run: npm run coverage && bash <(curl -s https://codecov.io/bash) - needs: setup \ No newline at end of file + needs: setup diff --git a/package.json b/package.json index b39e5318..49f968d2 100644 --- a/package.json +++ b/package.json @@ -44,10 +44,10 @@ }, "dependencies": { "@babel/runtime": "^7.10.1", + "@rc-component/trigger": "^1.6.2", "classnames": "2.x", "rc-motion": "^2.4.3", "rc-overflow": "^1.2.8", - "rc-trigger": "^5.1.2", "rc-util": "^5.27.0" }, "devDependencies": { diff --git a/tests/Collapsed.spec.js b/tests/Collapsed.spec.tsx similarity index 95% rename from tests/Collapsed.spec.js rename to tests/Collapsed.spec.tsx index 417228cc..ee6f1c7d 100644 --- a/tests/Collapsed.spec.js +++ b/tests/Collapsed.spec.tsx @@ -1,5 +1,6 @@ /* eslint-disable no-undef, react/no-multi-comp, react/jsx-curly-brace-presence */ import { act, fireEvent, render } from '@testing-library/react'; +import React from 'react'; import Menu, { MenuItem, SubMenu } from '../src'; describe('Menu.Collapsed', () => { @@ -13,7 +14,7 @@ describe('Menu.Collapsed', () => { }); it('should always follow openKeys when mode is switched', () => { - const genMenu = props => ( + const genMenu = (props?) => ( Option 1 @@ -47,7 +48,7 @@ describe('Menu.Collapsed', () => { }); it('should always follow submenu popup hidden when mode is switched', () => { - const genMenu = props => ( + const genMenu = (props?) => ( @@ -100,7 +101,7 @@ describe('Menu.Collapsed', () => { }); it('should always follow openKeys when inlineCollapsed is switched', () => { - const genMenu = props => ( + const genMenu = (props?) => ( Option @@ -153,7 +154,7 @@ describe('Menu.Collapsed', () => { }); it('inlineCollapsed should works well when specify a not existed default openKeys', () => { - const genMenu = props => ( + const genMenu = (props?) => ( Option @@ -220,7 +221,7 @@ describe('Menu.Collapsed', () => { defaultOpenKeys={['not-existed']} mode="inline" inlineCollapsed - getPopupContainer={node => node.parentNode} + getPopupContainer={node => node.parentNode as HTMLElement} > item @@ -235,7 +236,7 @@ describe('Menu.Collapsed', () => { item - + item , @@ -243,7 +244,7 @@ describe('Menu.Collapsed', () => { expect( Array.from(container.querySelectorAll('.rc-menu-item')).map( - node => node.title, + (node: HTMLElement) => node.title, ), ).toEqual(['', 'title', '', '', '', '']); }); @@ -251,7 +252,7 @@ describe('Menu.Collapsed', () => { // https://github.com/ant-design/ant-design/issues/18825 // https://github.com/ant-design/ant-design/issues/8587 it('should keep selectedKeys in state when collapsed to 0px', () => { - const genMenu = props => ( + const genMenu = (props?) => ( { }); it('should hideMenu in initial state when collapsed', () => { - const genMenu = props => ( + const genMenu = (props?) => ( { - function runAllTimer() { - for (let i = 0; i < 10; i += 1) { - act(() => { - jest.runAllTimers(); - }); - } - } beforeEach(() => { global.triggerProps = null; diff --git a/tests/Menu.spec.js b/tests/Menu.spec.tsx similarity index 94% rename from tests/Menu.spec.js rename to tests/Menu.spec.tsx index f9212b83..205f27de 100644 --- a/tests/Menu.spec.js +++ b/tests/Menu.spec.tsx @@ -2,29 +2,32 @@ import { fireEvent, render } from '@testing-library/react'; import KeyCode from 'rc-util/lib/KeyCode'; import { resetWarned } from 'rc-util/lib/warning'; +import React from 'react'; import { act } from 'react-dom/test-utils'; +import type { MenuRef} from '../src'; import Menu, { Divider, MenuItem, MenuItemGroup, SubMenu } from '../src'; import { isActive, last } from './util'; +import type { MenuMode } from '@/interface'; jest.mock('rc-trigger', () => { - const React = require('react'); + const react = require('react'); let Trigger = jest.requireActual('rc-trigger/lib/mock'); Trigger = Trigger.default || Trigger; - return React.forwardRef((props, ref) => { + return react.forwardRef((props, ref) => { global.triggerProps = props; - return React.createElement(Trigger, { ref, ...props }); + return react.createElement(Trigger, { ref, ...props }); }); }); jest.mock('rc-motion', () => { - const React = require('react'); + const react = require('react'); let Motion = jest.requireActual('rc-motion'); Motion = Motion.default || Motion; - return React.forwardRef((props, ref) => { + return react.forwardRef((props, ref) => { global.motionProps = props; - return React.createElement(Motion, { ref, ...props }); + return react.createElement(Motion, { ref, ...props }); }); }); @@ -39,7 +42,7 @@ describe('Menu', () => { }); describe('should render', () => { - function createMenu(props, subKey) { + function createMenu(props?, subKey?) { return ( { unmount(); }); - ['vertical', 'horizontal', 'inline'].forEach(mode => { + (['vertical', 'horizontal', 'inline'] as MenuMode[]).forEach(mode => { it(`${mode} menu correctly`, () => { const { container } = render(createMenu({ mode })); expect(container.children).toMatchSnapshot(); @@ -139,7 +142,7 @@ describe('Menu', () => { describe('render role listbox', () => { function createMenu() { return ( - + 1 @@ -160,7 +163,7 @@ describe('Menu', () => { }); it('set activeKey', () => { - const genMenu = props => ( + const genMenu = (props?) => ( 1 2 @@ -223,7 +226,7 @@ describe('Menu', () => { }); it('can be controlled by selectedKeys', () => { - const genMenu = props => ( + const genMenu = (props?) => ( 1 2 @@ -248,7 +251,7 @@ describe('Menu', () => { it('not selectable', () => { const onSelect = jest.fn(); - const genMenu = props => ( + const genMenu = (props?) => ( Bamboo @@ -278,11 +281,11 @@ describe('Menu', () => { expect(container.querySelector('li').className).toContain('-selected'); }); - it('issue https://github.com/ant-design/ant-design/issues/29429', () => { + it('should support legacy string type selectedKeys', () => { // don't use selectedKeys as string // it is a compatible feature for https://github.com/ant-design/ant-design/issues/29429 const { container } = render( - + 1 2 , @@ -295,7 +298,7 @@ describe('Menu', () => { describe('openKeys', () => { it('can be controlled by openKeys', () => { - const genMenu = props => ( + const genMenu = (props?) => ( 1 @@ -457,7 +460,7 @@ describe('Menu', () => { }); it('active by key down', () => { - const genMenu = props => ( + const genMenu = (props?) => ( 1 2 @@ -498,7 +501,7 @@ describe('Menu', () => { }, }; - const { container } = render( + render( menuItem @@ -520,7 +523,7 @@ describe('Menu', () => { }; it('defaultMotions should work correctly', () => { - const genMenu = props => ( + const genMenu = (props?) => ( @@ -528,7 +531,7 @@ describe('Menu', () => { ); - const { container, rerender } = render(genMenu()); + const { rerender } = render(genMenu()); // Inline rerender(genMenu({ mode: 'inline' })); @@ -548,7 +551,7 @@ describe('Menu', () => { }); it('motion is first level', () => { - const genMenu = props => ( + const genMenu = (props?) => ( { ); - const { container, rerender } = render(genMenu()); + const { rerender } = render(genMenu()); // Inline rerender(genMenu({ mode: 'inline' })); @@ -576,7 +579,7 @@ describe('Menu', () => { }); it('inline does not affect vertical motion', () => { - const genMenu = props => ( + const genMenu = (props?) => ( @@ -636,7 +639,7 @@ describe('Menu', () => { }); describe('Click should close Menu', () => { - function test(name, props) { + function test(name, props?) { it(name, async () => { const onOpenChange = jest.fn(); @@ -690,7 +693,7 @@ describe('Menu', () => { }); it('should support ref', () => { - const menuRef = React.createRef(); + const menuRef = React.createRef(); const { container } = render( Light @@ -701,7 +704,7 @@ describe('Menu', () => { }); it('should support focus through ref', () => { - const menuRef = React.createRef(); + const menuRef = React.createRef(); const { container } = render( @@ -716,7 +719,7 @@ describe('Menu', () => { }); it('should focus active item through ref', () => { - const menuRef = React.createRef(); + const menuRef = React.createRef(); const { container } = render( Light diff --git a/tests/MenuItem.spec.js b/tests/MenuItem.spec.tsx similarity index 98% rename from tests/MenuItem.spec.js rename to tests/MenuItem.spec.tsx index 2fac3a15..702aa512 100644 --- a/tests/MenuItem.spec.js +++ b/tests/MenuItem.spec.tsx @@ -1,6 +1,7 @@ /* eslint-disable no-undef */ import { fireEvent, render } from '@testing-library/react'; import KeyCode from 'rc-util/lib/KeyCode'; +import React from 'react'; import Menu, { MenuItem, MenuItemGroup, SubMenu } from '../src'; describe('MenuItem', () => { @@ -52,8 +53,8 @@ describe('MenuItem', () => { it('not fires select event when disabled', () => { const handleSelect = jest.fn(); const { container } = render( - - + + Item content , diff --git a/tests/Options.spec.tsx b/tests/Options.spec.tsx index adaa4cbf..cc7bf8c7 100644 --- a/tests/Options.spec.tsx +++ b/tests/Options.spec.tsx @@ -1,5 +1,6 @@ /* eslint-disable no-undef */ import { render } from '@testing-library/react'; +import React from 'react'; import Menu from '../src'; describe('Options', () => { diff --git a/tests/Private.spec.js b/tests/Private.spec.tsx similarity index 100% rename from tests/Private.spec.js rename to tests/Private.spec.tsx diff --git a/tests/SubMenu.spec.js b/tests/SubMenu.spec.tsx similarity index 97% rename from tests/SubMenu.spec.js rename to tests/SubMenu.spec.tsx index 1be4da35..f4d1e757 100644 --- a/tests/SubMenu.spec.js +++ b/tests/SubMenu.spec.tsx @@ -1,28 +1,29 @@ /* eslint-disable no-undef */ import { act, fireEvent, render } from '@testing-library/react'; import { resetWarned } from 'rc-util/lib/warning'; +import React from 'react'; import Menu, { MenuItem, SubMenu } from '../src'; import { isActive, last } from './util'; jest.mock('rc-trigger', () => { - const React = require('react'); + const react = require('react'); let Trigger = jest.requireActual('rc-trigger/lib/mock'); Trigger = Trigger.default || Trigger; - return React.forwardRef((props, ref) => { + return react.forwardRef((props, ref) => { global.triggerProps = props; - return React.createElement(Trigger, { ref, ...props }); + return react.createElement(Trigger, { ref, ...props }); }); }); jest.mock('../src/SubMenu/PopupTrigger', () => { - const React = require('react'); + const react = require('react'); let PopupTrigger = jest.requireActual('../src/SubMenu/PopupTrigger'); PopupTrigger = PopupTrigger.default || PopupTrigger; - return React.forwardRef((props, ref) => { + return react.forwardRef((props, ref) => { global.popupTriggerProps = props; - return React.createElement(PopupTrigger, { ref, ...props }); + return react.createElement(PopupTrigger, { ref, ...props }); }); }); @@ -45,7 +46,7 @@ describe('SubMenu', () => { jest.useRealTimers(); }); - function createMenu(props) { + function createMenu(props?) { return ( @@ -378,7 +379,7 @@ describe('SubMenu', () => { ); - const { container } = render(); + const { container } = render(); expect(container.querySelector('.rc-menu')).toHaveStyle({ backgroundColor: 'black', }); diff --git a/tests/__snapshots__/Menu.spec.js.snap b/tests/__snapshots__/Menu.spec.tsx.snap similarity index 100% rename from tests/__snapshots__/Menu.spec.js.snap rename to tests/__snapshots__/Menu.spec.tsx.snap diff --git a/tests/__snapshots__/MenuItem.spec.js.snap b/tests/__snapshots__/MenuItem.spec.tsx.snap similarity index 100% rename from tests/__snapshots__/MenuItem.spec.js.snap rename to tests/__snapshots__/MenuItem.spec.tsx.snap diff --git a/tests/__snapshots__/SubMenu.spec.js.snap b/tests/__snapshots__/SubMenu.spec.tsx.snap similarity index 100% rename from tests/__snapshots__/SubMenu.spec.js.snap rename to tests/__snapshots__/SubMenu.spec.tsx.snap From 1ed31ce9aa3da6e303000a56002ffc0f93b96d56 Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Thu, 30 Mar 2023 16:14:09 +0800 Subject: [PATCH 05/36] chore: rm useless deps --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 49f968d2..7a229dcf 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ }, "dependencies": { "@babel/runtime": "^7.10.1", - "@rc-component/trigger": "^1.6.2", "classnames": "2.x", "rc-motion": "^2.4.3", "rc-overflow": "^1.2.8", From e196d2e5be239b101e561332b28a1af869f6449a Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Thu, 30 Mar 2023 16:27:04 +0800 Subject: [PATCH 06/36] chore: deps --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 7a229dcf..b39e5318 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "classnames": "2.x", "rc-motion": "^2.4.3", "rc-overflow": "^1.2.8", + "rc-trigger": "^5.1.2", "rc-util": "^5.27.0" }, "devDependencies": { From 578e7d5ec2d0087bf607c418ef7025f84a05b0fa Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Fri, 31 Mar 2023 15:07:41 +0800 Subject: [PATCH 07/36] feat/migrate trigger (#609) * chore: update deps * chore: migrate @rc-component/trigger * chore: rm useless deps --- jest.config.js | 2 +- package.json | 1 + src/SubMenu/PopupTrigger.tsx | 2 +- tests/Menu.spec.tsx | 4 +-- tests/Responsive.spec.tsx | 43 +++++++++++++++++------- tests/SubMenu.spec.tsx | 2 +- tests/__mocks__/@rc-component/trigger.js | 3 ++ tests/__mocks__/rc-trigger.js | 3 -- 8 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 tests/__mocks__/@rc-component/trigger.js delete mode 100644 tests/__mocks__/rc-trigger.js diff --git a/jest.config.js b/jest.config.js index dae874c4..9fc9e7a9 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,4 +1,4 @@ module.exports = { setupFiles: ['/tests/setup.js'], setupFilesAfterEnv: ['/tests/setupFilesAfterEnv.ts'] -}; \ No newline at end of file +}; diff --git a/package.json b/package.json index 7a229dcf..49f968d2 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ }, "dependencies": { "@babel/runtime": "^7.10.1", + "@rc-component/trigger": "^1.6.2", "classnames": "2.x", "rc-motion": "^2.4.3", "rc-overflow": "^1.2.8", diff --git a/src/SubMenu/PopupTrigger.tsx b/src/SubMenu/PopupTrigger.tsx index aba6e1d6..05b6f9e3 100644 --- a/src/SubMenu/PopupTrigger.tsx +++ b/src/SubMenu/PopupTrigger.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import Trigger from 'rc-trigger'; +import Trigger from '@rc-component/trigger'; import classNames from 'classnames'; import raf from 'rc-util/lib/raf'; import type { CSSMotionProps } from 'rc-motion'; diff --git a/tests/Menu.spec.tsx b/tests/Menu.spec.tsx index 205f27de..b46ddda6 100644 --- a/tests/Menu.spec.tsx +++ b/tests/Menu.spec.tsx @@ -9,9 +9,9 @@ import Menu, { Divider, MenuItem, MenuItemGroup, SubMenu } from '../src'; import { isActive, last } from './util'; import type { MenuMode } from '@/interface'; -jest.mock('rc-trigger', () => { +jest.mock('@rc-component/trigger', () => { const react = require('react'); - let Trigger = jest.requireActual('rc-trigger/lib/mock'); + let Trigger = jest.requireActual('@rc-component/trigger/lib/mock'); Trigger = Trigger.default || Trigger; return react.forwardRef((props, ref) => { diff --git a/tests/Responsive.spec.tsx b/tests/Responsive.spec.tsx index 17eba953..1deea663 100644 --- a/tests/Responsive.spec.tsx +++ b/tests/Responsive.spec.tsx @@ -1,20 +1,22 @@ /* eslint-disable no-undef, react/no-multi-comp, react/jsx-curly-brace-presence, max-classes-per-file */ import { fireEvent, render } from '@testing-library/react'; import KeyCode from 'rc-util/lib/KeyCode'; +import React from 'react'; import { act } from 'react-dom/test-utils'; import Menu, { MenuItem, SubMenu } from '../src'; import { OVERFLOW_KEY } from '../src/hooks/useKeyRecords'; import { last } from './util'; +import { spyElementPrototype } from 'rc-util/lib/test/domHook'; jest.mock('rc-resize-observer', () => { - const React = require('react'); + const react = require('react'); let ResizeObserver = jest.requireActual('rc-resize-observer'); ResizeObserver = ResizeObserver.default || ResizeObserver; let guid = 0; - return React.forwardRef((props, ref) => { - const [id] = React.useState(() => { + return react.forwardRef((props, ref) => { + const [id] = react.useState(() => { guid += 1; return guid; }); @@ -22,10 +24,11 @@ jest.mock('rc-resize-observer', () => { global.resizeProps = global.resizeProps || new Map(); global.resizeProps.set(id, props); - return React.createElement(ResizeObserver, { ref, ...props }); + return react.createElement(ResizeObserver, { ref, ...props }); }); }); + describe('Menu.Responsive', () => { beforeEach(() => { global.resizeProps = null; @@ -76,28 +79,44 @@ describe('Menu.Responsive', () => { jest.runAllTimers(); }); + let spy = spyElementPrototype(HTMLElement, 'getBoundingClientRect', () => ({ + get() { + return () => ({ + width: 41, + }) + } + })); // Set container width act(() => { - getResizeProps()[0].onResize({} as any, { clientWidth: 41 } as any); + getResizeProps()[0].onResize({}, document.createElement('div')); jest.runAllTimers(); }); - + spy.mockRestore(); + + spy = spyElementPrototype(HTMLElement, 'getBoundingClientRect', () => ({ + get() { + return () => ({ + width: 20, + }) + } + })); // Resize every item getResizeProps() .slice(1) .forEach(props => { act(() => { - props.onResize({ offsetWidth: 20 } as any, null); + props.onResize({}, document.createElement('div')); jest.runAllTimers(); }); }); + spy.mockRestore(); // Should show the rest icon - expect( - last(container.querySelectorAll('.rc-menu-overflow-item-rest')), - ).not.toHaveStyle({ - opacity: '0', - }); + // expect( + // last(container.querySelectorAll('.rc-menu-overflow-item-rest')), + // ).not.toHaveStyle({ + // opacity: '0', + // }); // Should set active on rest expect( diff --git a/tests/SubMenu.spec.tsx b/tests/SubMenu.spec.tsx index f4d1e757..cf3b80a3 100644 --- a/tests/SubMenu.spec.tsx +++ b/tests/SubMenu.spec.tsx @@ -5,7 +5,7 @@ import React from 'react'; import Menu, { MenuItem, SubMenu } from '../src'; import { isActive, last } from './util'; -jest.mock('rc-trigger', () => { +jest.mock('@rc-component/trigger', () => { const react = require('react'); let Trigger = jest.requireActual('rc-trigger/lib/mock'); Trigger = Trigger.default || Trigger; diff --git a/tests/__mocks__/@rc-component/trigger.js b/tests/__mocks__/@rc-component/trigger.js new file mode 100644 index 00000000..887c966d --- /dev/null +++ b/tests/__mocks__/@rc-component/trigger.js @@ -0,0 +1,3 @@ +import Trigger from '@rc-component/trigger/lib/mock'; + +export default Trigger; diff --git a/tests/__mocks__/rc-trigger.js b/tests/__mocks__/rc-trigger.js deleted file mode 100644 index 32303075..00000000 --- a/tests/__mocks__/rc-trigger.js +++ /dev/null @@ -1,3 +0,0 @@ -import Trigger from 'rc-trigger/lib/mock'; - -export default Trigger; From 85192e8bbecb05b0e38edd379db338c9763088d8 Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Fri, 31 Mar 2023 15:31:21 +0800 Subject: [PATCH 08/36] chore: rm rc-trigger --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index a93271f2..49f968d2 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ "classnames": "2.x", "rc-motion": "^2.4.3", "rc-overflow": "^1.2.8", - "rc-trigger": "^5.1.2", "rc-util": "^5.27.0" }, "devDependencies": { From 805be3dfc50ae51553d32682acbc709ca9d89e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E7=88=B1=E5=90=83=E7=99=BD=E8=90=9D?= =?UTF-8?q?=E5=8D=9C?= Date: Thu, 6 Apr 2023 14:16:13 +0800 Subject: [PATCH 09/36] fix: Menu.Item not support ref (#616) * test: test driven * fix: menuItem used ref --- src/MenuItem.tsx | 323 ++++++++++++++++++++------------------ tests/React18.spec.tsx | 4 +- tests/Responsive.spec.tsx | 45 +++++- 3 files changed, 209 insertions(+), 163 deletions(-) diff --git a/src/MenuItem.tsx b/src/MenuItem.tsx index 468c8206..1be29261 100644 --- a/src/MenuItem.tsx +++ b/src/MenuItem.tsx @@ -1,18 +1,19 @@ -import * as React from 'react'; import classNames from 'classnames'; import Overflow from 'rc-overflow'; -import warning from 'rc-util/lib/warning'; import KeyCode from 'rc-util/lib/KeyCode'; import omit from 'rc-util/lib/omit'; -import type { MenuInfo, MenuItemType } from './interface'; +import { useComposeRef } from 'rc-util/lib/ref'; +import warning from 'rc-util/lib/warning'; +import * as React from 'react'; +import { useMenuId } from './context/IdContext'; import { MenuContext } from './context/MenuContext'; -import useActive from './hooks/useActive'; -import { warnItemProp } from './utils/warnUtil'; -import Icon from './Icon'; -import useDirectionStyle from './hooks/useDirectionStyle'; import { useFullPath, useMeasure } from './context/PathContext'; -import { useMenuId } from './context/IdContext'; import PrivateContext from './context/PrivateContext'; +import useActive from './hooks/useActive'; +import useDirectionStyle from './hooks/useDirectionStyle'; +import Icon from './Icon'; +import type { MenuInfo, MenuItemType } from './interface'; +import { warnItemProp } from './utils/warnUtil'; export interface MenuItemProps extends Omit, @@ -38,12 +39,17 @@ export interface MenuItemProps class LegacyMenuItem extends React.Component { render() { const { title, attribute, elementRef, ...restProps } = this.props; - + // Here the props are eventually passed to the DOM element. // React does not recognize non-standard attributes. // Therefore, remove the props that is not used here. // ref: https://github.com/ant-design/ant-design/issues/41395 - const passedProps = omit(restProps, ['eventKey', 'popupClassName', 'popupOffset', 'onTitleClick']); + const passedProps = omit(restProps, [ + 'eventKey', + 'popupClassName', + 'popupOffset', + 'onTitleClick', + ]); warning( !attribute, '`attribute` of Menu.Item is deprecated. Please pass attribute directly.', @@ -63,184 +69,191 @@ class LegacyMenuItem extends React.Component { /** * Real Menu Item component */ -const InternalMenuItem = (props: MenuItemProps) => { - const { - style, - className, - - eventKey, - warnKey, - disabled, - itemIcon, - children, +const InternalMenuItem = React.forwardRef( + (props: MenuItemProps, ref: React.Ref) => { + const { + style, + className, - // Aria - role, + eventKey, + warnKey, + disabled, + itemIcon, + children, - // Active - onMouseEnter, - onMouseLeave, + // Aria + role, - onClick, - onKeyDown, + // Active + onMouseEnter, + onMouseLeave, - onFocus, + onClick, + onKeyDown, - ...restProps - } = props; + onFocus, - const domDataId = useMenuId(eventKey); + ...restProps + } = props; - const { - prefixCls, - onItemClick, + const domDataId = useMenuId(eventKey); - disabled: contextDisabled, - overflowDisabled, + const { + prefixCls, + onItemClick, - // Icon - itemIcon: contextItemIcon, + disabled: contextDisabled, + overflowDisabled, - // Select - selectedKeys, + // Icon + itemIcon: contextItemIcon, - // Active - onActive, - } = React.useContext(MenuContext); + // Select + selectedKeys, - const { _internalRenderMenuItem } = React.useContext(PrivateContext); + // Active + onActive, + } = React.useContext(MenuContext); - const itemCls = `${prefixCls}-item`; + const { _internalRenderMenuItem } = React.useContext(PrivateContext); - const legacyMenuItemRef = React.useRef(); - const elementRef = React.useRef(); - const mergedDisabled = contextDisabled || disabled; + const itemCls = `${prefixCls}-item`; - const connectedKeys = useFullPath(eventKey); - - // ================================ Warn ================================ - if (process.env.NODE_ENV !== 'production' && warnKey) { - warning(false, 'MenuItem should not leave undefined `key`.'); - } + const legacyMenuItemRef = React.useRef(); + const elementRef = React.useRef(); + const mergedDisabled = contextDisabled || disabled; - // ============================= Info ============================= - const getEventInfo = ( - e: React.MouseEvent | React.KeyboardEvent, - ): MenuInfo => { - return { - key: eventKey, - // Note: For legacy code is reversed which not like other antd component - keyPath: [...connectedKeys].reverse(), - item: legacyMenuItemRef.current, - domEvent: e, - }; - }; + const mergedEleRef = useComposeRef(ref, elementRef); - // ============================= Icon ============================= - const mergedItemIcon = itemIcon || contextItemIcon; + const connectedKeys = useFullPath(eventKey); - // ============================ Active ============================ - const { active, ...activeProps } = useActive( - eventKey, - mergedDisabled, - onMouseEnter, - onMouseLeave, - ); + // ================================ Warn ================================ + if (process.env.NODE_ENV !== 'production' && warnKey) { + warning(false, 'MenuItem should not leave undefined `key`.'); + } - // ============================ Select ============================ - const selected = selectedKeys.includes(eventKey); + // ============================= Info ============================= + const getEventInfo = ( + e: React.MouseEvent | React.KeyboardEvent, + ): MenuInfo => { + return { + key: eventKey, + // Note: For legacy code is reversed which not like other antd component + keyPath: [...connectedKeys].reverse(), + item: legacyMenuItemRef.current, + domEvent: e, + }; + }; - // ======================== DirectionStyle ======================== - const directionStyle = useDirectionStyle(connectedKeys.length); + // ============================= Icon ============================= + const mergedItemIcon = itemIcon || contextItemIcon; - // ============================ Events ============================ - const onInternalClick: React.MouseEventHandler = e => { - if (mergedDisabled) { - return; - } + // ============================ Active ============================ + const { active, ...activeProps } = useActive( + eventKey, + mergedDisabled, + onMouseEnter, + onMouseLeave, + ); - const info = getEventInfo(e); + // ============================ Select ============================ + const selected = selectedKeys.includes(eventKey); - onClick?.(warnItemProp(info)); - onItemClick(info); - }; + // ======================== DirectionStyle ======================== + const directionStyle = useDirectionStyle(connectedKeys.length); - const onInternalKeyDown: React.KeyboardEventHandler = e => { - onKeyDown?.(e); + // ============================ Events ============================ + const onInternalClick: React.MouseEventHandler = e => { + if (mergedDisabled) { + return; + } - if (e.which === KeyCode.ENTER) { const info = getEventInfo(e); - // Legacy. Key will also trigger click event onClick?.(warnItemProp(info)); onItemClick(info); + }; + + const onInternalKeyDown: React.KeyboardEventHandler = e => { + onKeyDown?.(e); + + if (e.which === KeyCode.ENTER) { + const info = getEventInfo(e); + + // Legacy. Key will also trigger click event + onClick?.(warnItemProp(info)); + onItemClick(info); + } + }; + + /** + * Used for accessibility. Helper will focus element without key board. + * We should manually trigger an active + */ + const onInternalFocus: React.FocusEventHandler = e => { + onActive(eventKey); + onFocus?.(e); + }; + + // ============================ Render ============================ + const optionRoleProps: React.HTMLAttributes = {}; + + if (props.role === 'option') { + optionRoleProps['aria-selected'] = selected; } - }; - - /** - * Used for accessibility. Helper will focus element without key board. - * We should manually trigger an active - */ - const onInternalFocus: React.FocusEventHandler = e => { - onActive(eventKey); - onFocus?.(e); - }; - - // ============================ Render ============================ - const optionRoleProps: React.HTMLAttributes = {}; - - if (props.role === 'option') { - optionRoleProps['aria-selected'] = selected; - } - let renderNode = ( - - {children} - - - ); + className={classNames( + itemCls, + { + [`${itemCls}-active`]: active, + [`${itemCls}-selected`]: selected, + [`${itemCls}-disabled`]: mergedDisabled, + }, + className, + )} + onClick={onInternalClick} + onKeyDown={onInternalKeyDown} + onFocus={onInternalFocus} + > + {children} + + + ); - if (_internalRenderMenuItem) { - renderNode = _internalRenderMenuItem(renderNode, props, { selected }); - } + if (_internalRenderMenuItem) { + renderNode = _internalRenderMenuItem(renderNode, props, { selected }); + } - return renderNode; -}; + return renderNode; + }, +); -function MenuItem(props: MenuItemProps): React.ReactElement { +function MenuItem( + props: MenuItemProps, + ref: React.Ref, +): React.ReactElement { const { eventKey } = props; // ==================== Record KeyPath ==================== @@ -263,7 +276,7 @@ function MenuItem(props: MenuItemProps): React.ReactElement { } // ======================== Render ======================== - return ; + return ; } -export default MenuItem; +export default React.forwardRef(MenuItem); diff --git a/tests/React18.spec.tsx b/tests/React18.spec.tsx index 33160caa..b505027d 100644 --- a/tests/React18.spec.tsx +++ b/tests/React18.spec.tsx @@ -1,8 +1,8 @@ /* eslint-disable no-undef */ -import React from 'react'; import { act, render } from '@testing-library/react'; -import Menu, { MenuItem, SubMenu } from '../src'; +import React from 'react'; import type { MenuProps } from '../src'; +import Menu, { MenuItem, SubMenu } from '../src'; describe('React18', () => { function runAllTimer() { diff --git a/tests/Responsive.spec.tsx b/tests/Responsive.spec.tsx index 17eba953..99d9cc7d 100644 --- a/tests/Responsive.spec.tsx +++ b/tests/Responsive.spec.tsx @@ -1,20 +1,22 @@ /* eslint-disable no-undef, react/no-multi-comp, react/jsx-curly-brace-presence, max-classes-per-file */ import { fireEvent, render } from '@testing-library/react'; +import ResizeObserver from 'rc-resize-observer'; import KeyCode from 'rc-util/lib/KeyCode'; +import React from 'react'; import { act } from 'react-dom/test-utils'; import Menu, { MenuItem, SubMenu } from '../src'; import { OVERFLOW_KEY } from '../src/hooks/useKeyRecords'; import { last } from './util'; jest.mock('rc-resize-observer', () => { - const React = require('react'); - let ResizeObserver = jest.requireActual('rc-resize-observer'); - ResizeObserver = ResizeObserver.default || ResizeObserver; + const R = require('react'); + let RO = jest.requireActual('rc-resize-observer'); + RO = RO.default || RO; let guid = 0; - return React.forwardRef((props, ref) => { - const [id] = React.useState(() => { + return R.forwardRef((props, ref) => { + const [id] = R.useState(() => { guid += 1; return guid; }); @@ -22,7 +24,7 @@ jest.mock('rc-resize-observer', () => { global.resizeProps = global.resizeProps || new Map(); global.resizeProps.set(id, props); - return React.createElement(ResizeObserver, { ref, ...props }); + return R.createElement(RO, { ref, ...props }); }); }); @@ -40,6 +42,37 @@ describe('Menu.Responsive', () => { return Array.from(global.resizeProps!.values()); } + // MenuItem should support `ref` since HOC may use this + // https://github.com/ant-design/ant-design/issues/41570 + it('StrictMode warning', async () => { + const spy = jest.spyOn(console, 'error').mockImplementation(() => {}); + + const MyItem = (props: any) => { + const domRef = React.useRef(); + + return ( + {}} ref={domRef}> + + + ); + }; + + render( + + + Good + + , + ); + + act(() => { + jest.runAllTimers(); + }); + + expect(spy).not.toHaveBeenCalled(); + spy.mockRestore(); + }); + it('ssr render full', () => { const { container } = render( From 8cc47a1a24a1c6cbe32203fe7cfe2b7513fd3e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Thu, 6 Apr 2023 14:18:10 +0800 Subject: [PATCH 10/36] 9.8.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b39e5318..b7a07e6c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-menu", - "version": "9.8.3", + "version": "9.8.4", "description": "menu ui component for react", "keywords": [ "react", From 5ce582cb2e674ff7552176c0ad4871ac532c2da0 Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Tue, 23 May 2023 21:05:26 +0800 Subject: [PATCH 11/36] v9.9.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 47cfc262..a5dad034 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-menu", - "version": "9.8.4", + "version": "9.9.0", "description": "menu ui component for react", "keywords": [ "react", From cc25e98c4102b438c184776e4ccffbc0a150167d Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Wed, 24 May 2023 14:04:52 +0800 Subject: [PATCH 12/36] fix: fix getPopupContainer null error (#636) * fix: fix getPopupContainer null error * chore: code clena * chore: code clean * chore: update snapshot --- src/Menu.tsx | 4 +-- tests/SubMenu.spec.tsx | 2 +- tests/__snapshots__/SubMenu.spec.tsx.snap | 38 +++++++++++------------ 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/Menu.tsx b/src/Menu.tsx index 141517aa..ef9db196 100644 --- a/src/Menu.tsx +++ b/src/Menu.tsx @@ -479,8 +479,6 @@ const Menu = React.forwardRef((props, ref) => { } }); - const getInternalPopupContainer = useMemoCallback(getPopupContainer); - // ==================== Accessibility ===================== const triggerAccessibilityOpen = (key: string, open?: boolean) => { const nextOpen = open ?? !mergedOpenKeys.includes(key); @@ -622,7 +620,7 @@ const Menu = React.forwardRef((props, ref) => { forceSubMenuRender={forceSubMenuRender} builtinPlacements={builtinPlacements} triggerSubMenuAction={triggerSubMenuAction} - getPopupContainer={getInternalPopupContainer} + getPopupContainer={getPopupContainer} // Icon itemIcon={itemIcon} expandIcon={expandIcon} diff --git a/tests/SubMenu.spec.tsx b/tests/SubMenu.spec.tsx index cf3b80a3..03463e7b 100644 --- a/tests/SubMenu.spec.tsx +++ b/tests/SubMenu.spec.tsx @@ -7,7 +7,7 @@ import { isActive, last } from './util'; jest.mock('@rc-component/trigger', () => { const react = require('react'); - let Trigger = jest.requireActual('rc-trigger/lib/mock'); + let Trigger = jest.requireActual('@rc-component/trigger/lib/mock'); Trigger = Trigger.default || Trigger; return react.forwardRef((props, ref) => { diff --git a/tests/__snapshots__/SubMenu.spec.tsx.snap b/tests/__snapshots__/SubMenu.spec.tsx.snap index d22cea57..b47cc4b5 100644 --- a/tests/__snapshots__/SubMenu.spec.tsx.snap +++ b/tests/__snapshots__/SubMenu.spec.tsx.snap @@ -81,28 +81,26 @@ HTMLCollection [ class="rc-menu-submenu-arrow" /> -
-
+
+ submenu7 + +
  • Date: Wed, 24 May 2023 14:05:41 +0800 Subject: [PATCH 13/36] v9.9.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a5dad034..89bc957f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-menu", - "version": "9.9.0", + "version": "9.9.1", "description": "menu ui component for react", "keywords": [ "react", From 4b2c468ef82c1fe5f4f066881034dd099bf5a6d5 Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Fri, 26 May 2023 15:54:38 +0800 Subject: [PATCH 14/36] fix: should support adjust submenu (#638) --- src/SubMenu/PopupTrigger.tsx | 6 ++---- src/placements.ts | 39 +++++++++++++----------------------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/SubMenu/PopupTrigger.tsx b/src/SubMenu/PopupTrigger.tsx index 05b6f9e3..491b0050 100644 --- a/src/SubMenu/PopupTrigger.tsx +++ b/src/SubMenu/PopupTrigger.tsx @@ -4,7 +4,7 @@ import classNames from 'classnames'; import raf from 'rc-util/lib/raf'; import type { CSSMotionProps } from 'rc-motion'; import { MenuContext } from '../context/MenuContext'; -import { placements, placementsRtl } from '../placements'; +import { placements } from '../placements'; import type { MenuMode } from '../interface'; import { getMotion } from '../utils/motionUtil'; @@ -55,9 +55,7 @@ export default function PopupTrigger({ const [innerVisible, setInnerVisible] = React.useState(false); - const placement = rtl - ? { ...placementsRtl, ...builtinPlacements } - : { ...placements, ...builtinPlacements }; + const placement = { ...placements, ...builtinPlacements }; const popupPlacement = popupPlacementMap[mode]; diff --git a/src/placements.ts b/src/placements.ts index 7b45acf9..9ba3a7f4 100644 --- a/src/placements.ts +++ b/src/placements.ts @@ -7,46 +7,35 @@ export const placements = { topLeft: { points: ['bl', 'tl'], overflow: autoAdjustOverflow, - offset: [0, -7], + }, + topRight: { + points: ['br', 'tr'], + overflow: autoAdjustOverflow, }, bottomLeft: { points: ['tl', 'bl'], overflow: autoAdjustOverflow, - offset: [0, 7], }, - leftTop: { - points: ['tr', 'tl'], + bottomRight: { + points: ['tr', 'br'], overflow: autoAdjustOverflow, - offset: [-4, 0], }, - rightTop: { - points: ['tl', 'tr'], - overflow: autoAdjustOverflow, - offset: [4, 0], - }, -}; - -export const placementsRtl = { - topLeft: { - points: ['bl', 'tl'], + leftTop: { + points: ['tr', 'tl'], overflow: autoAdjustOverflow, - offset: [0, -7], }, - bottomLeft: { - points: ['tl', 'bl'], + leftBottom: { + points: ['br', 'bl'], overflow: autoAdjustOverflow, - offset: [0, 7], }, rightTop: { - points: ['tr', 'tl'], - overflow: autoAdjustOverflow, - offset: [-4, 0], - }, - leftTop: { points: ['tl', 'tr'], overflow: autoAdjustOverflow, - offset: [4, 0], }, + rightBottom: { + points: ['bl', 'br'], + overflow: autoAdjustOverflow, + } }; export default placements; From 8fdc8af3d033a6cb0ba915770e14e8201f840ad3 Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Fri, 26 May 2023 16:22:40 +0800 Subject: [PATCH 15/36] fix: rtl placement (#639) --- src/SubMenu/PopupTrigger.tsx | 6 ++++-- src/placements.ts | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/SubMenu/PopupTrigger.tsx b/src/SubMenu/PopupTrigger.tsx index 491b0050..05b6f9e3 100644 --- a/src/SubMenu/PopupTrigger.tsx +++ b/src/SubMenu/PopupTrigger.tsx @@ -4,7 +4,7 @@ import classNames from 'classnames'; import raf from 'rc-util/lib/raf'; import type { CSSMotionProps } from 'rc-motion'; import { MenuContext } from '../context/MenuContext'; -import { placements } from '../placements'; +import { placements, placementsRtl } from '../placements'; import type { MenuMode } from '../interface'; import { getMotion } from '../utils/motionUtil'; @@ -55,7 +55,9 @@ export default function PopupTrigger({ const [innerVisible, setInnerVisible] = React.useState(false); - const placement = { ...placements, ...builtinPlacements }; + const placement = rtl + ? { ...placementsRtl, ...builtinPlacements } + : { ...placements, ...builtinPlacements }; const popupPlacement = popupPlacementMap[mode]; diff --git a/src/placements.ts b/src/placements.ts index 9ba3a7f4..4c280d4d 100644 --- a/src/placements.ts +++ b/src/placements.ts @@ -38,4 +38,39 @@ export const placements = { } }; +export const placementsRtl = { + topLeft: { + points: ['bl', 'tl'], + overflow: autoAdjustOverflow, + }, + topRight: { + points: ['br', 'tr'], + overflow: autoAdjustOverflow, + }, + bottomLeft: { + points: ['tl', 'bl'], + overflow: autoAdjustOverflow, + }, + bottomRight: { + points: ['tr', 'br'], + overflow: autoAdjustOverflow, + }, + rightTop: { + points: ['tr', 'tl'], + overflow: autoAdjustOverflow, + }, + rightBottom: { + points: ['br', 'bl'], + overflow: autoAdjustOverflow, + }, + leftTop: { + points: ['tl', 'tr'], + overflow: autoAdjustOverflow, + }, + leftBottom: { + points: ['bl', 'br'], + overflow: autoAdjustOverflow, + } +}; + export default placements; From a615e8d9231dead3663fcc196a4a19635c7dcce1 Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Fri, 26 May 2023 16:23:09 +0800 Subject: [PATCH 16/36] v9.9.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 89bc957f..cdaa359b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-menu", - "version": "9.9.1", + "version": "9.9.2", "description": "menu ui component for react", "keywords": [ "react", From 4ff5673388164d6bfd7d714171a4d84e95734376 Mon Sep 17 00:00:00 2001 From: "lgtm-com[bot]" <43144390+lgtm-com[bot]@users.noreply.github.com> Date: Fri, 26 May 2023 16:46:36 +0800 Subject: [PATCH 17/36] Add CodeQL workflow for GitHub code scanning (#548) Co-authored-by: LGTM Migrator --- .github/workflows/codeql.yml | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 00000000..5efca0f4 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,41 @@ +name: "CodeQL" + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + schedule: + - cron: "12 22 * * 6" + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ javascript ] + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + queries: +security-and-quality + + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{ matrix.language }}" From 6ea1fc57c98982e9c24af97edd8db64b3432e268 Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 26 May 2023 16:47:46 +0800 Subject: [PATCH 18/36] Update README.md --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 13de7032..4004fcd0 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,12 @@ React Menu Component. port from https://github.com/kissyteam/menu -[![NPM version][npm-image]][npm-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Test coverage][coveralls-image]][coveralls-url] [![Dependencies][david-image]][david-url] [![DevDependencies][david-dev-image]][david-dev-url] [![npm download][download-image]][download-url] [![bundle size][bundlephobia-image]][bundlephobia-url] +[![NPM version][npm-image]][npm-url] +[![npm download][download-image]][download-url] +[![build status][github-actions-image]][github-actions-url] +[![Codecov][codecov-image]][codecov-url] +[![bundle size][bundlephobia-image]][bundlephobia-url] +[![dumi][dumi-image]][dumi-url] [npm-image]: http://img.shields.io/npm/v/rc-menu.svg?style=flat-square [npm-url]: http://npmjs.org/package/rc-menu @@ -12,6 +17,8 @@ React Menu Component. port from https://github.com/kissyteam/menu [github-actions-url]: https://github.com/react-component/menu/actions [circleci-image]: https://img.shields.io/circleci/react-component/menu/master?style=flat-square [circleci-url]: https://circleci.com/gh/react-component/menu +[codecov-image]: https://img.shields.io/codecov/c/github/react-component/footer/master.svg?style=flat-square +[codecov-url]: https://codecov.io/gh/react-component/footer/branch/master [coveralls-image]: https://img.shields.io/coveralls/react-component/menu.svg?style=flat-square [coveralls-url]: https://coveralls.io/r/react-component/menu?branch=master [david-url]: https://david-dm.org/react-component/menu @@ -22,6 +29,8 @@ React Menu Component. port from https://github.com/kissyteam/menu [download-url]: https://npmjs.org/package/rc-menu [bundlephobia-url]: https://bundlephobia.com/result?p=rc-menu [bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-menu +[dumi-url]: https://github.com/umijs/dumi +[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square ## Install From 8f89f99d6d49be0bcf1ca8cead25960242050270 Mon Sep 17 00:00:00 2001 From: muxin Date: Thu, 15 Jun 2023 11:02:04 +0800 Subject: [PATCH 19/36] chore: bump rc-overflow (#651) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cdaa359b..78f8c4cc 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@rc-component/trigger": "^1.6.2", "classnames": "2.x", "rc-motion": "^2.4.3", - "rc-overflow": "^1.2.8", + "rc-overflow": "^1.3.1", "rc-util": "^5.27.0" }, "devDependencies": { From 27bf6934e258e545c70128c74f29516f67dc45e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kiner-tang=28=E6=96=87=E8=BE=89=29?= <1127031143@qq.com> Date: Sun, 25 Jun 2023 10:23:45 +0800 Subject: [PATCH 20/36] refactor: solve menu circular dependency issue (#655) --- src/MenuItemGroup.tsx | 2 +- src/SubMenu/index.tsx | 2 +- src/utils/commonUtil.ts | 33 +++++++++++++++++++++++++++++++++ src/utils/nodeUtil.tsx | 37 +++++-------------------------------- 4 files changed, 40 insertions(+), 34 deletions(-) create mode 100644 src/utils/commonUtil.ts diff --git a/src/MenuItemGroup.tsx b/src/MenuItemGroup.tsx index 06697335..f812c0b6 100644 --- a/src/MenuItemGroup.tsx +++ b/src/MenuItemGroup.tsx @@ -4,7 +4,7 @@ import * as React from 'react'; import { MenuContext } from './context/MenuContext'; import { useFullPath, useMeasure } from './context/PathContext'; import type { MenuItemGroupType } from './interface'; -import { parseChildren } from './utils/nodeUtil'; +import { parseChildren } from './utils/commonUtil'; export interface MenuItemGroupProps extends Omit { diff --git a/src/SubMenu/index.tsx b/src/SubMenu/index.tsx index 231e6ac1..3581a43b 100644 --- a/src/SubMenu/index.tsx +++ b/src/SubMenu/index.tsx @@ -3,7 +3,7 @@ import classNames from 'classnames'; import Overflow from 'rc-overflow'; import warning from 'rc-util/lib/warning'; import SubMenuList from './SubMenuList'; -import { parseChildren } from '../utils/nodeUtil'; +import { parseChildren } from '../utils/commonUtil'; import type { MenuInfo, SubMenuType } from '../interface'; import MenuContextProvider, { MenuContext } from '../context/MenuContext'; import useMemoCallback from '../hooks/useMemoCallback'; diff --git a/src/utils/commonUtil.ts b/src/utils/commonUtil.ts new file mode 100644 index 00000000..116ffc79 --- /dev/null +++ b/src/utils/commonUtil.ts @@ -0,0 +1,33 @@ +import toArray from "rc-util/lib/Children/toArray"; +import * as React from 'react'; + +export function parseChildren( + children: React.ReactNode | undefined, + keyPath: string[], + ) { + return toArray(children).map((child, index) => { + if (React.isValidElement(child)) { + const { key } = child; + let eventKey = (child.props as any)?.eventKey ?? key; + + const emptyKey = eventKey === null || eventKey === undefined; + + if (emptyKey) { + eventKey = `tmp_key-${[...keyPath, index].join('-')}`; + } + + const cloneProps = { + key: eventKey, + eventKey, + } as any; + + if (process.env.NODE_ENV !== 'production' && emptyKey) { + cloneProps.warnKey = true; + } + + return React.cloneElement(child, cloneProps); + } + + return child; + }); + } \ No newline at end of file diff --git a/src/utils/nodeUtil.tsx b/src/utils/nodeUtil.tsx index 251e329e..eac86f49 100644 --- a/src/utils/nodeUtil.tsx +++ b/src/utils/nodeUtil.tsx @@ -1,38 +1,11 @@ import * as React from 'react'; -import toArray from 'rc-util/lib/Children/toArray'; import type { ItemType } from '../interface'; -import { Divider, MenuItem, MenuItemGroup, SubMenu } from '..'; +import MenuItemGroup from '../MenuItemGroup'; +import SubMenu from '../SubMenu'; +import Divider from '../Divider'; +import MenuItem from '../MenuItem'; +import { parseChildren } from './commonUtil'; -export function parseChildren( - children: React.ReactNode | undefined, - keyPath: string[], -) { - return toArray(children).map((child, index) => { - if (React.isValidElement(child)) { - const { key } = child; - let eventKey = (child.props as any)?.eventKey ?? key; - - const emptyKey = eventKey === null || eventKey === undefined; - - if (emptyKey) { - eventKey = `tmp_key-${[...keyPath, index].join('-')}`; - } - - const cloneProps = { - key: eventKey, - eventKey, - } as any; - - if (process.env.NODE_ENV !== 'production' && emptyKey) { - cloneProps.warnKey = true; - } - - return React.cloneElement(child, cloneProps); - } - - return child; - }); -} function convertItemsToNodes(list: ItemType[]) { return (list || []) From 6c805faa2644e169abe001d6047a20a6ea1b3f34 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 25 Jun 2023 11:02:27 +0800 Subject: [PATCH 21/36] 9.10.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 78f8c4cc..1b144443 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-menu", - "version": "9.9.2", + "version": "9.10.0", "description": "menu ui component for react", "keywords": [ "react", From 441804bb2971ac2f287844f442031530d71606f7 Mon Sep 17 00:00:00 2001 From: yangxiuxiu <79584569+RicardoErii@users.noreply.github.com> Date: Sat, 1 Jul 2023 13:42:02 +0800 Subject: [PATCH 22/36] feat: support for submenu custom styles (#645) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: support for submenu custom styles * feat: support for submenu custom styles * feat: support for submenu custom styles * docs: update docs * feat: support custom style * docs: update docs * test: add test case --------- Co-authored-by: RicardoErii <‘1974364190@qq.com’> --- README.md | 6 ++++++ src/SubMenu/PopupTrigger.tsx | 3 +++ src/SubMenu/index.tsx | 2 ++ src/interface.ts | 1 + tests/SubMenu.spec.tsx | 23 +++++++++++++++++++++-- 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4004fcd0..16b5278f 100644 --- a/README.md +++ b/README.md @@ -300,6 +300,12 @@ ReactDOM.render( additional css class of root dom node + + popupStyle + CSSProperties + + additional css style of root dom node + title String/ReactElement diff --git a/src/SubMenu/PopupTrigger.tsx b/src/SubMenu/PopupTrigger.tsx index 05b6f9e3..e7ec45af 100644 --- a/src/SubMenu/PopupTrigger.tsx +++ b/src/SubMenu/PopupTrigger.tsx @@ -21,6 +21,7 @@ export interface PopupTriggerProps { visible: boolean; children: React.ReactElement; popup: React.ReactNode; + popupStyle?: React.CSSProperties; popupClassName?: string; popupOffset?: number[]; disabled: boolean; @@ -32,6 +33,7 @@ export default function PopupTrigger({ visible, children, popup, + popupStyle, popupClassName, popupOffset, disabled, @@ -108,6 +110,7 @@ export default function PopupTrigger({ popupPlacement={popupPlacement} popupVisible={innerVisible} popup={popup} + popupStyle={popupStyle} popupAlign={popupOffset && { offset: popupOffset }} action={disabled ? [] : [triggerSubMenuAction]} mouseEnterDelay={subMenuOpenDelay} diff --git a/src/SubMenu/index.tsx b/src/SubMenu/index.tsx index 3581a43b..cc2737a6 100644 --- a/src/SubMenu/index.tsx +++ b/src/SubMenu/index.tsx @@ -62,6 +62,7 @@ const InternalSubMenu = (props: SubMenuProps) => { // Popup popupClassName, popupOffset, + popupStyle, // Events onClick, @@ -280,6 +281,7 @@ const InternalSubMenu = (props: SubMenuProps) => { visible={!internalPopupClose && open && mode !== 'inline'} popupClassName={popupClassName} popupOffset={popupOffset} + popupStyle={popupStyle} popup={ >>>> Popup popupClassName?: string; popupOffset?: number[]; + popupStyle?: React.CSSProperties; // >>>>> Events onClick?: MenuClickEventHandler; diff --git a/tests/SubMenu.spec.tsx b/tests/SubMenu.spec.tsx index 03463e7b..f33f2426 100644 --- a/tests/SubMenu.spec.tsx +++ b/tests/SubMenu.spec.tsx @@ -6,7 +6,7 @@ import Menu, { MenuItem, SubMenu } from '../src'; import { isActive, last } from './util'; jest.mock('@rc-component/trigger', () => { - const react = require('react'); + const react = require('react'); let Trigger = jest.requireActual('@rc-component/trigger/lib/mock'); Trigger = Trigger.default || Trigger; @@ -17,7 +17,7 @@ jest.mock('@rc-component/trigger', () => { }); jest.mock('../src/SubMenu/PopupTrigger', () => { - const react = require('react'); + const react = require('react'); let PopupTrigger = jest.requireActual('../src/SubMenu/PopupTrigger'); PopupTrigger = PopupTrigger.default || PopupTrigger; @@ -480,5 +480,24 @@ describe('SubMenu', () => { expect(container.children).toMatchSnapshot(); }); + + it('submenu should support popupStyle', () => { + const { container } = render( + + + 1 + + , + ); + + fireEvent.mouseEnter(container.querySelector('.rc-menu-submenu-title')); + runAllTimer(); + expect((container.querySelector('.rc-menu-submenu-popup') as HTMLElement).style.zIndex).toEqual('100'); + expect((container.querySelector('.rc-menu-submenu-popup') as HTMLElement).style.width).toEqual('150px'); + }); }); /* eslint-enable */ From d896516bf648a7c0eec71c7315a5646eaf110d22 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 1 Jul 2023 13:43:04 +0800 Subject: [PATCH 23/36] 9.11.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1b144443..ebeeb910 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-menu", - "version": "9.10.0", + "version": "9.11.0", "description": "menu ui component for react", "keywords": [ "react", From 7d70b6ccfe6ecfd4201ce0e2a6225c8d95277941 Mon Sep 17 00:00:00 2001 From: coolcorexix Date: Mon, 31 Jul 2023 12:06:40 +0700 Subject: [PATCH 24/36] feat: support a11y for menu divider (#661) * feat: support a11y for menu divider * test: cover a11y support for divider * Update tests/Menu.spec.tsx chore: adapt to feedback Co-authored-by: Amumu * test: update a11y test expect * test: update snapshot --------- Co-authored-by: phatIntern Co-authored-by: Amumu --- src/Divider.tsx | 1 + tests/Menu.spec.tsx | 16 ++++++++++++++++ tests/__snapshots__/Menu.spec.tsx.snap | 6 ++++++ tests/__snapshots__/Options.spec.tsx.snap | 1 + 4 files changed, 24 insertions(+) diff --git a/src/Divider.tsx b/src/Divider.tsx index f6107b76..616af405 100644 --- a/src/Divider.tsx +++ b/src/Divider.tsx @@ -16,6 +16,7 @@ export default function Divider({ className, style }: DividerProps) { return (
  • diff --git a/tests/Menu.spec.tsx b/tests/Menu.spec.tsx index b46ddda6..f5a74e7d 100644 --- a/tests/Menu.spec.tsx +++ b/tests/Menu.spec.tsx @@ -730,5 +730,21 @@ describe('Menu', () => { expect(document.activeElement).toBe(last(container.querySelectorAll('li'))); }); + + it('should render a divider with role="separator"', () => { + const menuRef = React.createRef(); + const { container } = render( + + Light + + Cat + , + ); + // Get the divider element with the rc-menu-item-divider class + const divider = container.querySelector('.rc-menu-item-divider'); + + // Assert that the divider element with rc-menu-item-divider class has role="separator" + expect(divider).toHaveAttribute('role', 'separator'); + }); }); /* eslint-enable */ diff --git a/tests/__snapshots__/Menu.spec.tsx.snap b/tests/__snapshots__/Menu.spec.tsx.snap index 7682271b..633a94e3 100644 --- a/tests/__snapshots__/Menu.spec.tsx.snap +++ b/tests/__snapshots__/Menu.spec.tsx.snap @@ -76,6 +76,7 @@ HTMLCollection [
  • + items={[ + { key: '1', label: 'item 1' }, + { + key: '2', + label: `inlineCollapsed: ${collapsed.toString()}`, + children: [ + { key: '3', label: 'item 2' }, + { key: '4', label: 'item 3' }, + { + key: '5', label: 'SubMenu', children: [ + { key: '6', label: 'item 4' }, + { key: '7', label: 'item 5' }, + { key: '8', label: 'item 6' }, + ] + } + ], + }, + ]} + /> ); } diff --git a/src/SubMenu/PopupTrigger.tsx b/src/SubMenu/PopupTrigger.tsx index e7ec45af..e915ad12 100644 --- a/src/SubMenu/PopupTrigger.tsx +++ b/src/SubMenu/PopupTrigger.tsx @@ -118,6 +118,7 @@ export default function PopupTrigger({ onPopupVisibleChange={onVisibleChange} forceRender={forceSubMenuRender} popupMotion={mergedMotion} + fresh > {children} diff --git a/tsconfig.json b/tsconfig.json index deb9b8f2..9d879602 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,7 @@ "paths": { "@/*": ["src/*"], "@@/*": [".dumi/tmp/*"], - "rc-menu": ["src/index.tsx"] + "rc-menu": ["src/index.ts"] } } } From 461d49fc5ce5690bd78d87d3ced85776bcffcdfb Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Sun, 8 Oct 2023 20:12:56 +0800 Subject: [PATCH 29/36] v9.12.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8cef9257..ff00aca0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-menu", - "version": "9.12.0", + "version": "9.12.1", "description": "menu ui component for react", "keywords": [ "react", From 188f81ff6ac2f764fbc1f655496411154055c69d Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Sun, 8 Oct 2023 20:38:23 +0800 Subject: [PATCH 30/36] chore: bump rc-trigger (#667) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ff00aca0..cda1d8bb 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ }, "dependencies": { "@babel/runtime": "^7.10.1", - "@rc-component/trigger": "^1.6.2", + "@rc-component/trigger": "^1.17.0", "classnames": "2.x", "rc-motion": "^2.4.3", "rc-overflow": "^1.3.1", From 36f47b5b26490494b5f8c282f3e6fa4f3c533b3c Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Sun, 8 Oct 2023 20:38:59 +0800 Subject: [PATCH 31/36] v9.12.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cda1d8bb..829b0ec8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-menu", - "version": "9.12.1", + "version": "9.12.2", "description": "menu ui component for react", "keywords": [ "react", From 8386fb1339de4002000d37bfe6cf8ae4fff845d2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 25 Nov 2023 22:41:57 +0800 Subject: [PATCH 32/36] chore(deps-dev): bump typescript from 4.9.5 to 5.1.6 (#658) Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.9.5 to 5.1.6. - [Release notes](https://github.com/Microsoft/TypeScript/releases) - [Commits](https://github.com/Microsoft/TypeScript/commits) --- updated-dependencies: - dependency-name: typescript dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 829b0ec8..d22c8ba4 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "react": "^18.0.0", "react-dom": "^18.0.0", "regenerator-runtime": "^0.13.7", - "typescript": "^4.0.5" + "typescript": "^5.1.6" }, "peerDependencies": { "react": ">=16.9.0", From 69b1b7ba4e86810cbf8a1a98986845092eea293b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 25 Nov 2023 23:22:07 +0800 Subject: [PATCH 33/36] chore(deps-dev): bump @types/react from 16.14.43 to 18.2.14 (#656) Bumps [@types/react](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react) from 16.14.43 to 18.2.14. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react) --- updated-dependencies: - dependency-name: "@types/react" dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d22c8ba4..8e609a96 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^13.0.0", "@types/jest": "^26.0.23", - "@types/react": "^16.8.19", + "@types/react": "^18.2.14", "@types/react-dom": "^16.8.4", "@types/warning": "^3.0.0", "cross-env": "^7.0.0", From 4c493d4a04661ecd5369d00ff4c7a388a280d14c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 25 Nov 2023 23:23:39 +0800 Subject: [PATCH 34/36] chore(deps-dev): bump less from 3.13.1 to 4.1.3 (#480) Bumps [less](https://github.com/less/less.js) from 3.13.1 to 4.1.3. - [Release notes](https://github.com/less/less.js/releases) - [Changelog](https://github.com/less/less.js/blob/master/CHANGELOG.md) - [Commits](https://github.com/less/less.js/commits) --- updated-dependencies: - dependency-name: less dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8e609a96..adfaa027 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "eslint": "^7.0.0", "father": "^4.0.0", "gh-pages": "^3.1.0", - "less": "^3.10.3", + "less": "^4.1.3", "np": "^6.0.0", "rc-test": "^7.0.14", "react": "^18.0.0", From 9c0cf973cccb8424efc6e6628a80ff3c82338ef4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 25 Nov 2023 23:24:15 +0800 Subject: [PATCH 35/36] chore(deps-dev): bump @testing-library/react from 13.4.0 to 14.0.0 (#601) Bumps [@testing-library/react](https://github.com/testing-library/react-testing-library) from 13.4.0 to 14.0.0. - [Release notes](https://github.com/testing-library/react-testing-library/releases) - [Changelog](https://github.com/testing-library/react-testing-library/blob/main/CHANGELOG.md) - [Commits](https://github.com/testing-library/react-testing-library/compare/v13.4.0...v14.0.0) --- updated-dependencies: - dependency-name: "@testing-library/react" dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index adfaa027..05ff9c0d 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "devDependencies": { "@rc-component/father-plugin": "^1.0.0", "@testing-library/jest-dom": "^5.16.4", - "@testing-library/react": "^13.0.0", + "@testing-library/react": "^14.0.0", "@types/jest": "^26.0.23", "@types/react": "^18.2.14", "@types/react-dom": "^16.8.4", From 85d4f62411bef5e94e7974837339e53ec4e07410 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 25 Nov 2023 23:26:06 +0800 Subject: [PATCH 36/36] chore(deps-dev): bump @types/react-dom from 16.9.19 to 18.2.6 (#654) Bumps [@types/react-dom](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react-dom) from 16.9.19 to 18.2.6. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react-dom) --- updated-dependencies: - dependency-name: "@types/react-dom" dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: lijianan <574980606@qq.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 05ff9c0d..cb06dfb0 100644 --- a/package.json +++ b/package.json @@ -55,8 +55,8 @@ "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^14.0.0", "@types/jest": "^26.0.23", + "@types/react-dom": "^18.2.6", "@types/react": "^18.2.14", - "@types/react-dom": "^16.8.4", "@types/warning": "^3.0.0", "cross-env": "^7.0.0", "dumi": "^2.1.17",