Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
fcf5499
start up
zombieJ Apr 6, 2021
4361e5f
more classNames
zombieJ Apr 6, 2021
da68ec5
add openKeys
zombieJ Apr 7, 2021
97fe682
chore: Back of onClick
zombieJ Apr 8, 2021
2331624
feat: Motion back
zombieJ Apr 8, 2021
34ff4a9
active key support
zombieJ Apr 15, 2021
7798422
pass active keys
zombieJ Apr 15, 2021
4fc428a
fix: mode pass logic
zombieJ Apr 16, 2021
8dd3f5c
support menu group
zombieJ Apr 16, 2021
a5036a1
docs: Fix definition
zombieJ Apr 16, 2021
4b26d84
disabled should not click
zombieJ Apr 16, 2021
1e1cd0d
chore: Add loop check of path
zombieJ Apr 16, 2021
f50eb2b
chore: Back of nest selection
zombieJ Apr 16, 2021
8ee63cb
wrap item prop as warning
zombieJ Apr 16, 2021
52c4aec
feat: support onSelect & onDeselect event
zombieJ Apr 16, 2021
3626171
revert useless onSelect & support itemIcon
zombieJ Apr 16, 2021
29f9102
all rtl inlineIndent
zombieJ Apr 16, 2021
8ded9ae
hover event
zombieJ Apr 16, 2021
8f16966
popup data
zombieJ Apr 16, 2021
8dde0ab
back of defaultMotions
zombieJ Apr 19, 2021
cbbd6d7
fix: Not lose active when hover disabled region
zombieJ Apr 19, 2021
72987e7
feat: use rc-overflow
zombieJ Apr 19, 2021
ab60701
fix: disabled should not trigger children active
zombieJ Apr 19, 2021
c920c06
chore: Cache inline open keys
zombieJ Apr 19, 2021
d7eef77
fix cache logic
zombieJ Apr 19, 2021
6b0f526
inline mode no need pass active on subMenu
zombieJ Apr 19, 2021
2ecb763
chore: inline handle motion logic
zombieJ Apr 20, 2021
f550aae
fix: inline open logic
zombieJ Apr 20, 2021
85a0c1d
chore: Update comment
zombieJ Apr 20, 2021
7e9422c
fix open logic
zombieJ Apr 21, 2021
7d0a45f
fix icon
zombieJ Apr 21, 2021
2db29b7
update test
zombieJ Apr 21, 2021
ceca551
test: first test case
zombieJ Apr 21, 2021
67805d2
fix: clean up timer logic
zombieJ Apr 22, 2021
8bc6c0c
test: More test case
zombieJ Apr 22, 2021
cdabf94
Divider
zombieJ Apr 23, 2021
a0fc736
test: update snapshot
zombieJ Apr 23, 2021
8b7eb06
test: Back of snapshot
zombieJ Apr 23, 2021
a6a2cdf
test: clean up
zombieJ Apr 23, 2021
e257f9e
test: fix dir
zombieJ Apr 23, 2021
f36de4f
test: Update snapshot
zombieJ Apr 26, 2021
c44dcf2
test: Update snapshot
zombieJ Apr 26, 2021
cf7f344
test: back of fragment test
zombieJ Apr 26, 2021
628665c
test: role
zombieJ Apr 26, 2021
dfd2403
test: selection & active
zombieJ Apr 26, 2021
02bae1e
fix: open keys
zombieJ Apr 26, 2021
4be6dd4
test: More test case
zombieJ Apr 26, 2021
b3177a1
feat: Native focus logic
zombieJ Apr 27, 2021
b0eff80
move to correct key
zombieJ Apr 27, 2021
f3792fb
fix aria link
zombieJ Apr 27, 2021
94f42e4
menu item select
zombieJ Apr 27, 2021
86da675
fix: no active for invisible content
zombieJ Apr 27, 2021
81cf0c7
trigger open
zombieJ Apr 27, 2021
846263b
feat: Go to sub list
zombieJ Apr 28, 2021
24e6259
support nest level
zombieJ Apr 28, 2021
826c703
feat: Auto focus link
zombieJ Apr 28, 2021
3350a63
inline use special operation
zombieJ Apr 28, 2021
0214f83
test: Update snapshot
zombieJ Apr 28, 2021
2b8428f
test: back of key code
zombieJ Apr 28, 2021
74f2907
fix: Not focus if activeKey not changed
zombieJ Apr 28, 2021
d2aab10
fix: active logic
zombieJ Apr 28, 2021
bc664fe
chore: Use activeKey as start element instead
zombieJ Apr 28, 2021
39ed351
comment
zombieJ Apr 29, 2021
3b001ad
test: keyboard test
zombieJ Apr 29, 2021
03c523c
test: defaultActiveFirst
zombieJ Apr 29, 2021
7b8772a
test: more MenuItem test
zombieJ Apr 29, 2021
3a2ed7a
test: fix rest props
zombieJ Apr 29, 2021
a221b2e
test: menuItem test
zombieJ Apr 29, 2021
911d8e9
test: Sub menu part test
zombieJ Apr 29, 2021
a828e5c
test: ltr & rtl
zombieJ Apr 29, 2021
e1fd1ea
test: Back of all test case
zombieJ Apr 29, 2021
d951434
docs: Update docs
zombieJ Apr 30, 2021
4c49c51
test: warning test
zombieJ Apr 30, 2021
73304ee
test: keycode coverage
zombieJ May 1, 2021
d426d00
test: click disabled coverage
zombieJ May 1, 2021
1b38f10
test: selectable coverage
zombieJ May 1, 2021
531c9b8
test: full coverage
zombieJ May 1, 2021
f912e78
chore: add data-*
zombieJ May 1, 2021
7df66b3
chore: clean up
zombieJ May 1, 2021
3544810
chore: Split context
zombieJ May 1, 2021
f99a99f
chore: Use record context
zombieJ May 1, 2021
b0ef325
render use another contexr
zombieJ May 1, 2021
2effa5e
rm usePathData
zombieJ May 1, 2021
0c623fd
fix arrow logic
zombieJ May 1, 2021
e705cb7
patch match support overflow
zombieJ May 1, 2021
98accf0
update snapshot
zombieJ May 1, 2021
7414ca0
test: Fix test case
zombieJ May 1, 2021
69f0b83
test: Fix key test
zombieJ May 1, 2021
d23345a
test: Final test case
zombieJ May 1, 2021
142300b
test: Coverage
zombieJ May 1, 2021
43a64af
fix: open logci
zombieJ May 2, 2021
3774eaa
fix: accessibility for focus
zombieJ May 2, 2021
8135a29
chore: clean up
zombieJ May 2, 2021
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
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all"
"trailingComma": "all",
"arrowParens": "avoid"
}
22 changes: 22 additions & 0 deletions assets/menu.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@menuPrefixCls: ~'rc-menu';

.@{menuPrefixCls} {
&:focus-visible {
box-shadow: 0 0 5px green;
}

&-horizontal {
display: flex;
flex-wrap: nowrap;
}

&-submenu {
&-hidden {
display: none;
}
}

&-overflow-item {
flex: none;
}
}
3 changes: 3 additions & 0 deletions docs/demo/debug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## debug

<code src="../examples/debug.tsx">
1 change: 0 additions & 1 deletion docs/examples/antd-switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const Demo = () => {
<CommonMenu
mode="inline"
openKeys={openKeys}
collapsedWidth={80}
onOpenChange={keys => {
console.error('Open Keys Changed:', keys);
setOpenKey(keys);
Expand Down
59 changes: 50 additions & 9 deletions docs/examples/antd.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
/* eslint-disable no-console, react/require-default-props, no-param-reassign */

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

function handleClick(info) {
console.log(`clicked ${info.key}`);
console.log(info);
}

const collapseNode = () => ({ height: 0 });
const expandNode = node => ({ height: node.scrollHeight });
const collapseNode = () => {
return { height: 0 };
};
const expandNode = node => {
return { height: node.scrollHeight };
};

const horizontalMotion: CSSMotionProps = {
motionName: 'rc-menu-open-slide-up',
motionAppear: true,
motionEnter: true,
motionLeave: true,
};

export const inlineMotion = {
const verticalMotion: CSSMotionProps = {
motionName: 'rc-menu-open-zoom',
motionAppear: true,
motionEnter: true,
motionLeave: true,
};

const inlineMotion: CSSMotionProps = {
motionName: 'rc-menu-collapse',
motionAppear: true,
onAppearStart: collapseNode,
onAppearActive: expandNode,
onEnterStart: collapseNode,
Expand All @@ -22,6 +42,12 @@ export const inlineMotion = {
onLeaveActive: collapseNode,
};

const motionMap: Record<MenuProps['mode'], CSSMotionProps> = {
horizontal: horizontalMotion,
inline: inlineMotion,
vertical: verticalMotion,
};

const nestSubMenu = (
<SubMenu
title={<span className="submenu-title-wrapper">offset sub menu 2</span>}
Expand Down Expand Up @@ -95,8 +121,21 @@ const children2 = [

const customizeIndicator = <span>Add More Items</span>;

export class CommonMenu extends React.Component {
state = {
interface CommonMenuProps extends MenuProps {
triggerSubMenuAction?: MenuProps['triggerSubMenuAction'];
updateChildrenAndOverflowedIndicator?: boolean;
}

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

export class CommonMenu extends React.Component<
CommonMenuProps,
CommonMenuState
> {
state: CommonMenuState = {
children: children1,
overflowedIndicator: undefined,
};
Expand Down Expand Up @@ -149,21 +188,23 @@ function Demo() {
<CommonMenu
mode="horizontal"
// use openTransition for antd
openAnimation="slide-up"
defaultMotions={motionMap}
/>
);

const horizontalMenu2 = (
<CommonMenu
mode="horizontal"
// use openTransition for antd
openAnimation="slide-up"
defaultMotions={motionMap}
triggerSubMenuAction="click"
updateChildrenAndOverflowedIndicator
/>
);

const verticalMenu = <CommonMenu mode="vertical" openAnimation="zoom" />;
const verticalMenu = (
<CommonMenu mode="vertical" defaultMotions={motionMap} />
);

const inlineMenu = (
<CommonMenu mode="inline" defaultOpenKeys={['1']} motion={inlineMotion} />
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/custom-icon.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable no-console, no-param-reassign */
import * as React from 'react';
import Menu, { SubMenu, Item as MenuItem, Divider } from 'rc-menu';
import Menu, { SubMenu, Item as MenuItem, Divider } from '../../src';
import '../../assets/index.less';

const getSvgIcon = (style = {}, text) => {
const getSvgIcon = (style = {}, text?: React.ReactNode) => {
if (text) {
return <i style={style}>{text}</i>;
}
Expand Down
158 changes: 158 additions & 0 deletions docs/examples/debug.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/* eslint no-console:0 */

import React from 'react';
import type { CSSMotionProps } from 'rc-motion';
import Menu, { ItemGroup as MenuItemGroup } from '../../src';
import type { MenuProps } from '../../src';
import '../../assets/index.less';
import '../../assets/menu.less';
import type { MenuInfo } from '@/interface';

const collapseNode = () => {
return { height: 0 };
};
const expandNode = node => {
return { height: node.scrollHeight };
};

const horizontalMotion: CSSMotionProps = {
motionName: 'rc-menu-open-slide-up',
motionAppear: true,
motionEnter: true,
motionLeave: true,
};

const verticalMotion: CSSMotionProps = {
motionName: 'rc-menu-open-zoom',
motionAppear: true,
motionEnter: true,
motionLeave: true,
};

const inlineMotion: CSSMotionProps = {
motionName: 'rc-menu-collapse',
motionAppear: true,
onAppearStart: collapseNode,
onAppearActive: expandNode,
onEnterStart: collapseNode,
onEnterActive: expandNode,
onLeaveStart: expandNode,
onLeaveActive: collapseNode,
};

const motionMap: Record<MenuProps['mode'], CSSMotionProps> = {
horizontal: horizontalMotion,
inline: inlineMotion,
vertical: verticalMotion,
};

export default () => {
const [mode, setMode] = React.useState<MenuProps['mode']>('horizontal');
const [narrow, setNarrow] = React.useState(false);
const [inlineCollapsed, setInlineCollapsed] = React.useState(false);
const [forceRender, setForceRender] = React.useState(false);
const [openKeys, setOpenKeys] = React.useState<string[]>([]);

const onRootClick = (info: MenuInfo) => {
console.log('Root Menu Item Click:', info);
};

const onSubMenuClick = (info: MenuInfo) => {
console.log('Sub Menu Item Click:', info);
};

const onClick = (info: MenuInfo) => {
console.log('Menu Item Click:', info);
};

return (
<>
<div>
<select value={mode} onChange={e => setMode(e.target.value as any)}>
<option value="inline">Inline</option>
<option value="vertical">Vertical</option>
<option value="horizontal">Horizontal</option>
</select>

{/* Narrow */}
<button
onClick={() => {
setNarrow(!narrow);
}}
>
Narrow: {String(narrow)}
</button>

{/* InlineCollapsed */}
<button
onClick={() => {
setInlineCollapsed(!inlineCollapsed);
}}
>
Inline Collapsed: {String(inlineCollapsed)}
</button>

{/* forceRender */}
<button
onClick={() => {
setForceRender(!forceRender);
}}
>
Force Render: {String(forceRender)}
</button>
</div>

<div style={{ width: narrow ? 350 : undefined }}>
<Menu
// direction="rtl"
forceSubMenuRender={forceRender}
mode={mode}
style={{ width: mode === 'horizontal' ? undefined : 256 }}
onClick={onRootClick}
defaultMotions={motionMap}
inlineCollapsed={inlineCollapsed}
// openKeys={openKeys}
onOpenChange={newOpenKeys => setOpenKeys(newOpenKeys)}
>
<Menu.Item key="mail">
<a href="http://www.taobao.com">Navigation One</a>
</Menu.Item>
<Menu.Item key="next" onClick={onClick}>
Next Item
</Menu.Item>
<Menu.SubMenu title="Sub Menu" key="sub" onClick={onSubMenuClick}>
<Menu.Item key="sub1" onClick={onClick}>
Sub Item 1
</Menu.Item>
<Menu.Item key="sub2">Sub Item 2</Menu.Item>

<Menu.SubMenu title="Nest Menu" key="nest">
<MenuItemGroup title="group 1" key="grp1">
<Menu.Item key="21">2</Menu.Item>
<Menu.Item key="22">3</Menu.Item>
</MenuItemGroup>
<MenuItemGroup title="group 2" key="grp2">
<Menu.Item key="31">4</Menu.Item>
<Menu.Item key="32">5</Menu.Item>
</MenuItemGroup>
</Menu.SubMenu>
</Menu.SubMenu>
<Menu.Item key="disabled" disabled>
Disabled Item
</Menu.Item>

<Menu.SubMenu
title="Disabled Sub Menu"
key="disabled-sub"
onClick={onSubMenuClick}
disabled
>
<Menu.Item key="dis-sub1" onClick={onClick}>
Disabled Sub Item 1
</Menu.Item>
</Menu.SubMenu>
</Menu>
</div>
</>
);
};
Loading