Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ ReactDOM.render(
## Compatibility

| [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="IE / Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br>IE / Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br>Safari | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/electron/electron_48x48.png" alt="Electron" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br>Electron |
| --- | --- | --- | --- | --- |
| IE11, Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| IE11, Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |

## API

Expand Down Expand Up @@ -172,7 +172,7 @@ ReactDOM.render(
<td>openAnimation</td>
<td>{enter:function,leave:function}|String</td>
<th></th>
<td>animate when sub menu open or close. see rc-motion for object type.</td>
<td>animate when sub menu open or close. see @rc-component/motion for object type.</td>
</tr>
<tr>
<td>openTransition</td>
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/antd.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console, react/require-default-props, no-param-reassign */

import React from 'react';
import type { CSSMotionProps } from 'rc-motion';
import type { CSSMotionProps } from '@rc-component/motion';
import Menu, { SubMenu, Item as MenuItem, Divider, MenuProps } from '../../src';
import '../../assets/index.less';

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/debug.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint no-console:0 */

import React, { useRef } from 'react';
import type { CSSMotionProps } from 'rc-motion';
import type { CSSMotionProps } from '@rc-component/motion';
import Menu, { ItemGroup as MenuItemGroup, MenuItem } from '../../src';
import type { MenuProps } from '../../src';
import '../../assets/index.less';
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/rtl-antd.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console, react/require-default-props, no-param-reassign */

import React from 'react';
import type { CSSMotionProps } from 'rc-motion';
import type { CSSMotionProps } from '@rc-component/motion';
import Menu, { SubMenu, Item as MenuItem, Divider, MenuProps } from 'rc-menu';
import '../../assets/index.less';

Expand Down Expand Up @@ -122,8 +122,8 @@ const children2 = [
const customizeIndicator = <span>Add More Items</span>;

interface CommonMenuState {
children: React.ReactNode;
overflowedIndicator?: React.ReactNode;
children: React.ReactNode;
overflowedIndicator?: React.ReactNode;
}

class CommonMenu extends React.Component<any, CommonMenuState> {
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@
"docs:deploy": "gh-pages -d .doc",
"lint": "eslint src/ --ext .tsx,.ts,.jsx,.js",
"now-build": "npm run build",
"prepublishOnly": "npm run compile && np --yolo --no-publish",
"prepublishOnly": "npm run compile && rc-np",
"postpublish": "tnpm sync rc-menu",
"start": "dumi dev",
"test": "rc-test",
"prepare": "husky && dumi setup"
},
"dependencies": {
"@babel/runtime": "^7.10.1",
"@rc-component/trigger": "^2.0.0",
"@rc-component/motion": "^1.1.4",
"@rc-component/trigger": "^3.0.0",
"@rc-component/util": "^1.0.0",
"classnames": "2.x",
"rc-motion": "^2.4.3",
"rc-overflow": "^1.3.1",
"rc-util": "^5.27.0"
"rc-overflow": "^1.3.1"
},
"devDependencies": {
"@rc-component/father-plugin": "^1.0.0",
"@rc-component/np": "^1.0.3",
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/react": "^16.0.0",
"@types/jest": "^29.5.2",
Expand All @@ -70,7 +70,6 @@
"husky": "^9.1.6",
"less": "^4.1.3",
"lint-staged": "^15.2.10",
"np": "^10.0.5",
"prettier": "^3.3.3",
"rc-test": "^7.0.14",
"react": "^18.3.1",
Expand Down
8 changes: 4 additions & 4 deletions src/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import classNames from 'classnames';
import type { CSSMotionProps } from 'rc-motion';
import type { CSSMotionProps } from '@rc-component/motion';
import Overflow from 'rc-overflow';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import isEqual from 'rc-util/lib/isEqual';
import warning from 'rc-util/lib/warning';
import useMergedState from '@rc-component/util/lib/hooks/useMergedState';
import isEqual from '@rc-component/util/lib/isEqual';
import warning from '@rc-component/util/lib/warning';
import * as React from 'react';
import { useImperativeHandle } from 'react';
import { flushSync } from 'react-dom';
Expand Down
8 changes: 4 additions & 4 deletions src/MenuItem.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import classNames from 'classnames';
import Overflow from 'rc-overflow';
import KeyCode from 'rc-util/lib/KeyCode';
import omit from 'rc-util/lib/omit';
import { useComposeRef } from 'rc-util/lib/ref';
import warning from 'rc-util/lib/warning';
import KeyCode from '@rc-component/util/lib/KeyCode';
import omit from '@rc-component/util/lib/omit';
import { useComposeRef } from '@rc-component/util/lib/ref';
import warning from '@rc-component/util/lib/warning';
import * as React from 'react';
import { useMenuId } from './context/IdContext';
import { MenuContext } from './context/MenuContext';
Expand Down
2 changes: 1 addition & 1 deletion src/MenuItemGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from 'classnames';
import omit from 'rc-util/lib/omit';
import omit from '@rc-component/util/lib/omit';
import * as React from 'react';
import { MenuContext } from './context/MenuContext';
import { useFullPath, useMeasure } from './context/PathContext';
Expand Down
11 changes: 3 additions & 8 deletions src/SubMenu/InlineSubMenuList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import CSSMotion from 'rc-motion';
import CSSMotion from '@rc-component/motion';
import { getMotion } from '../utils/motionUtil';
import MenuContextProvider, { MenuContext } from '../context/MenuContext';
import SubMenuList from './SubMenuList';
Expand All @@ -20,13 +20,8 @@ export default function InlineSubMenuList({
}: InlineSubMenuListProps) {
const fixedMode: MenuMode = 'inline';

const {
prefixCls,
forceSubMenuRender,
motion,
defaultMotions,
mode,
} = React.useContext(MenuContext);
const { prefixCls, forceSubMenuRender, motion, defaultMotions, mode } =
React.useContext(MenuContext);

// Always use latest mode check
const sameModeRef = React.useRef(false);
Expand Down
4 changes: 2 additions & 2 deletions src/SubMenu/PopupTrigger.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import Trigger from '@rc-component/trigger';
import classNames from 'classnames';
import raf from 'rc-util/lib/raf';
import type { CSSMotionProps } from 'rc-motion';
import raf from '@rc-component/util/lib/raf';
import type { CSSMotionProps } from '@rc-component/motion';
import { MenuContext } from '../context/MenuContext';
import { placements, placementsRtl } from '../placements';
import type { MenuMode } from '../interface';
Expand Down
2 changes: 1 addition & 1 deletion src/SubMenu/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import classNames from 'classnames';
import Overflow from 'rc-overflow';
import warning from 'rc-util/lib/warning';
import warning from '@rc-component/util/lib/warning';
import SubMenuList from './SubMenuList';
import { parseChildren } from '../utils/commonUtil';
import type { MenuInfo, SubMenuType } from '../interface';
Expand Down
6 changes: 3 additions & 3 deletions src/context/MenuContext.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import type { CSSMotionProps } from 'rc-motion';
import useMemo from 'rc-util/lib/hooks/useMemo';
import isEqual from 'rc-util/lib/isEqual';
import type { CSSMotionProps } from '@rc-component/motion';
import useMemo from '@rc-component/util/lib/hooks/useMemo';
import isEqual from '@rc-component/util/lib/isEqual';
import type {
BuiltinPlacements,
MenuClickEventHandler,
Expand Down
41 changes: 10 additions & 31 deletions src/hooks/useAccessibility.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getFocusNodeList } from 'rc-util/lib/Dom/focus';
import KeyCode from 'rc-util/lib/KeyCode';
import raf from 'rc-util/lib/raf';
import { getFocusNodeList } from '@rc-component/util/lib/Dom/focus';
import KeyCode from '@rc-component/util/lib/KeyCode';
import raf from '@rc-component/util/lib/raf';
import * as React from 'react';
import { getMenuId } from '../context/IdContext';
import type { MenuMode } from '../interface';
Expand All @@ -15,28 +15,19 @@ function getOffset(
isRootLevel: boolean,
isRtl: boolean,
which: number,
): {
offset?: number;
sibling?: boolean;
inlineTrigger?: boolean;
} {
): { offset?: number; sibling?: boolean; inlineTrigger?: boolean } {
const prev = 'prev' as const;
const next = 'next' as const;
const children = 'children' as const;
const parent = 'parent' as const;

// Inline enter is special that we use unique operation
if (mode === 'inline' && which === ENTER) {
return {
inlineTrigger: true,
};
return { inlineTrigger: true };
}

type OffsetMap = Record<number, 'prev' | 'next' | 'children' | 'parent'>;
const inline: OffsetMap = {
[UP]: prev,
[DOWN]: next,
};
const inline: OffsetMap = { [UP]: prev, [DOWN]: next };
const horizontal: OffsetMap = {
[LEFT]: isRtl ? next : prev,
[RIGHT]: isRtl ? prev : next,
Expand Down Expand Up @@ -68,28 +59,16 @@ function getOffset(

switch (type) {
case prev:
return {
offset: -1,
sibling: true,
};
return { offset: -1, sibling: true };

case next:
return {
offset: 1,
sibling: true,
};
return { offset: 1, sibling: true };

case parent:
return {
offset: -1,
sibling: false,
};
return { offset: -1, sibling: false };

case children:
return {
offset: 1,
sibling: false,
};
return { offset: 1, sibling: false };

default:
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useKeyRecords.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { useRef, useCallback } from 'react';
import warning from 'rc-util/lib/warning';
import warning from '@rc-component/util/lib/warning';
import { nextSlice } from '../utils/timeUtil';

const PATH_SPLIT = '__RC_UTIL_PATH_SPLIT__';
Expand Down
6 changes: 2 additions & 4 deletions src/hooks/useUUID.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import * as React from 'react';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import useMergedState from '@rc-component/util/lib/hooks/useMergedState';

const uniquePrefix = Math.random().toFixed(5).toString().slice(2);

let internalId = 0;

export default function useUUID(id?: string) {
const [uuid, setUUID] = useMergedState(id, {
value: id,
});
const [uuid, setUUID] = useMergedState(id, { value: id });

React.useEffect(() => {
internalId += 1;
Expand Down
55 changes: 26 additions & 29 deletions src/utils/commonUtil.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
import toArray from "rc-util/lib/Children/toArray";
import toArray from '@rc-component/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);
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('-')}`;
}

return child;
});
}

const cloneProps = { key: eventKey, eventKey } as any;

if (process.env.NODE_ENV !== 'production' && emptyKey) {
cloneProps.warnKey = true;
}

return React.cloneElement(child, cloneProps);
}

return child;
});
}
2 changes: 1 addition & 1 deletion src/utils/motionUtil.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CSSMotionProps } from 'rc-motion';
import type { CSSMotionProps } from '@rc-component/motion';

export function getMotion(
mode: string,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/warnUtil.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import warning from 'rc-util/lib/warning';
import warning from '@rc-component/util/lib/warning';

/**
* `onClick` event return `info.item` which point to react node directly.
Expand Down
2 changes: 1 addition & 1 deletion tests/Focus.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-undef */
import { act, fireEvent, render } from '@testing-library/react';
import { spyElementPrototypes } from 'rc-util/lib/test/domHook';
import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
import React from 'react';
import Menu, { MenuItem, MenuItemGroup, MenuRef, SubMenu } from '../src';

Expand Down
4 changes: 2 additions & 2 deletions tests/Keyboard.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* 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 { spyElementPrototypes } from 'rc-util/lib/test/domHook';
import KeyCode from '@rc-component/util/lib/KeyCode';
import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
import React from 'react';
import { act } from 'react-dom/test-utils';
import Menu, { MenuItem, SubMenu } from '../src';
Expand Down
Loading