From 679af40e84aaea0c9d75607187ae18c505aa6461 Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 26 Jun 2026 14:38:28 +0800 Subject: [PATCH 01/36] chore: standardize repository maintenance --- .dumirc.ts | 18 +- .github/FUNDING.yml | 17 +- .../workflows/cloudflare-pages-preview.yml | 42 ++ .github/workflows/codeql.yml | 22 +- .github/workflows/main.yml | 6 - .github/workflows/react-component-ci.yml | 8 + .github/workflows/react-doctor.yml | 27 + .github/workflows/surge-preview.yml | 39 ++ .gitignore | 5 +- README.md | 594 +++++------------- now.json | 14 - package.json | 10 +- tsconfig.json | 4 +- vercel.json | 6 + 14 files changed, 325 insertions(+), 487 deletions(-) create mode 100644 .github/workflows/cloudflare-pages-preview.yml delete mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/react-component-ci.yml create mode 100644 .github/workflows/react-doctor.yml create mode 100644 .github/workflows/surge-preview.yml delete mode 100644 now.json create mode 100644 vercel.json diff --git a/.dumirc.ts b/.dumirc.ts index ebd40b0d..03f4625b 100644 --- a/.dumirc.ts +++ b/.dumirc.ts @@ -1,17 +1,19 @@ // more config: https://d.umijs.org/config import { defineConfig } from 'dumi'; +const basePath = process.env.GH_PAGES ? '/menu/' : '/'; +const publicPath = process.env.GH_PAGES ? '/menu/' : '/'; + export default defineConfig({ themeConfig: { - name: 'rc-menu', + name: 'Menu', logo: 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4', - nav: [ - { title: 'Demo', link: '/demo/antd'} - ], + nav: [{ title: 'Demo', link: '/demo/antd' }], }, - favicons: - ['https://avatars0.githubusercontent.com/u/9441414?s=200&v=4'], - outputPath: '.doc', + favicons: ['https://avatars0.githubusercontent.com/u/9441414?s=200&v=4'], + outputPath: 'docs-dist', + base: basePath, + publicPath, exportStatic: {}, mfsu: {}, styles: [ @@ -20,5 +22,5 @@ export default defineConfig({ width: auto !important; } `, - ] + ], }); diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 33b1999c..758659af 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,15 +1,2 @@ -# These are supported funding model platforms - -github: ant-design # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] -patreon: # Replace with a single Patreon username -open_collective: ant-design # Replace with a single Open Collective username -ko_fi: # Replace with a single Ko-fi username -tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel -community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry -liberapay: # Replace with a single Liberapay username -issuehunt: # Replace with a single IssueHunt username -lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry -polar: # Replace with a single Polar username -buy_me_a_coffee: # Replace with a single Buy Me a Coffee username -thanks_dev: # Replace with a single thanks.dev username -custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] +github: ant-design +open_collective: ant-design diff --git a/.github/workflows/cloudflare-pages-preview.yml b/.github/workflows/cloudflare-pages-preview.yml new file mode 100644 index 00000000..d925f518 --- /dev/null +++ b/.github/workflows/cloudflare-pages-preview.yml @@ -0,0 +1,42 @@ +name: Cloudflare Pages Preview + +on: + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} + cancel-in-progress: true + +permissions: + contents: read + deployments: write + +jobs: + preview: + runs-on: ubuntu-latest + env: + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_PAGES_PROJECT: ${{ vars.CLOUDFLARE_PAGES_PROJECT }} + PREVIEW: true + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 + with: + persist-credentials: false + - name: Skip Cloudflare Pages preview + if: ${{ env.CLOUDFLARE_API_TOKEN == '' || env.CLOUDFLARE_ACCOUNT_ID == '' || env.CLOUDFLARE_PAGES_PROJECT == '' }} + run: echo "Cloudflare Pages preview is not configured; skip deployment." + - name: Install dependencies + if: ${{ env.CLOUDFLARE_API_TOKEN != '' && env.CLOUDFLARE_ACCOUNT_ID != '' && env.CLOUDFLARE_PAGES_PROJECT != '' }} + run: npm install + - name: Build site + if: ${{ env.CLOUDFLARE_API_TOKEN != '' && env.CLOUDFLARE_ACCOUNT_ID != '' && env.CLOUDFLARE_PAGES_PROJECT != '' }} + run: npm run build + - name: Deploy preview + if: ${{ env.CLOUDFLARE_API_TOKEN != '' && env.CLOUDFLARE_ACCOUNT_ID != '' && env.CLOUDFLARE_PAGES_PROJECT != '' }} + uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 + with: + apiToken: ${{ env.CLOUDFLARE_API_TOKEN }} + accountId: ${{ env.CLOUDFLARE_ACCOUNT_ID }} + command: pages deploy docs-dist --project-name=${{ env.CLOUDFLARE_PAGES_PROJECT }} --branch=${{ github.head_ref }} + gitHubToken: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 5efca0f4..7df7bc4c 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -1,12 +1,12 @@ -name: "CodeQL" +name: 'CodeQL' on: push: - branches: [ "master" ] + branches: ['master'] pull_request: - branches: [ "master" ] + branches: ['master'] schedule: - - cron: "12 22 * * 6" + - cron: '12 22 * * 6' jobs: analyze: @@ -20,22 +20,24 @@ jobs: strategy: fail-fast: false matrix: - language: [ javascript ] + language: [javascript] steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 + with: + persist-credentials: false - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@8aad20d150bbac5944a9f9d289da16a4b0d87c1e with: languages: ${{ matrix.language }} queries: +security-and-quality - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@8aad20d150bbac5944a9f9d289da16a4b0d87c1e - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@8aad20d150bbac5944a9f9d289da16a4b0d87c1e with: - category: "/language:${{ matrix.language }}" + category: '/language:${{ matrix.language }}' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 5735e2d2..00000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: ✅ test -on: [push, pull_request] -jobs: - test: - uses: react-component/rc-test/.github/workflows/test.yml@main - secrets: inherit \ No newline at end of file diff --git a/.github/workflows/react-component-ci.yml b/.github/workflows/react-component-ci.yml new file mode 100644 index 00000000..9503b960 --- /dev/null +++ b/.github/workflows/react-component-ci.yml @@ -0,0 +1,8 @@ +name: ✅ test +on: [push, pull_request] +permissions: + contents: read +jobs: + test: + uses: react-component/rc-test/.github/workflows/test-utoo.yml@main + secrets: inherit diff --git a/.github/workflows/react-doctor.yml b/.github/workflows/react-doctor.yml new file mode 100644 index 00000000..f68281c8 --- /dev/null +++ b/.github/workflows/react-doctor.yml @@ -0,0 +1,27 @@ +name: React Doctor + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + push: + branches: [master] + +permissions: + contents: read + pull-requests: write + issues: write + statuses: write + +concurrency: + group: react-doctor-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + react-doctor: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 + with: + fetch-depth: 0 + persist-credentials: false + - uses: millionco/react-doctor@0b4f4f4bd248a154e64eb508a48347f71154b3f3 diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml new file mode 100644 index 00000000..1b29a17b --- /dev/null +++ b/.github/workflows/surge-preview.yml @@ -0,0 +1,39 @@ +name: Surge Preview + +on: + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} + cancel-in-progress: true + +permissions: + contents: read + pull-requests: write + checks: write + statuses: write + +jobs: + preview: + runs-on: ubuntu-latest + env: + SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} + PREVIEW: true + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 + with: + persist-credentials: false + - uses: afc163/surge-preview@bf90a5a86111f6311ca42f0a5a0f80fb0fb03cec + if: ${{ env.SURGE_TOKEN != '' }} + with: + surge_token: ${{ env.SURGE_TOKEN }} + github_token: ${{ secrets.GITHUB_TOKEN }} + dist: docs-dist + failOnError: true + setCommitStatus: true + build: | + npm install + npm run build + - name: Skip Surge preview + if: ${{ env.SURGE_TOKEN == '' }} + run: echo "SURGE_TOKEN is not configured; skip Surge preview." diff --git a/.gitignore b/.gitignore index 898129e9..267c6ce6 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,8 @@ build lib es coverage +.doc +docs-dist/ yarn.lock package-lock.json pnpm-lock.yaml @@ -38,4 +40,5 @@ pnpm-lock.yaml .dumi/tmp-production .env.local -bun.lockb \ No newline at end of file +bun.lockb +.vercel diff --git a/README.md b/README.md index 22d3dce2..f05e38e5 100644 --- a/README.md +++ b/README.md @@ -1,464 +1,200 @@ -# @rc-component/menu +
+

@rc-component/menu

+

🧭 Accessible React menu primitives for navigation, command surfaces, and nested item trees.

+
---- - -React Menu Component. port from https://github.com/kissyteam/menu +
[![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]: https://img.shields.io/npm/v/@rc-component/menu.svg?style=flat-square -[npm-url]: https://npmjs.org/package/@rc-component/menu -[github-actions-image]: https://github.com/react-component/menu/actions/workflows/main.yml/badge.svg -[github-actions-url]: https://github.com/react-component/menu/actions/workflows/main.yml -[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 -[david-image]: https://david-dm.org/react-component/menu/status.svg?style=flat-square -[david-dev-url]: https://david-dm.org/react-component/menu?type=dev -[david-dev-image]: https://david-dm.org/react-component/menu/dev-status.svg?style=flat-square -[download-image]: https://img.shields.io/npm/dm/@rc-component/menu.svg?style=flat-square -[download-url]: https://npmjs.org/package/@rc-component/menu -[bundlephobia-url]: https://bundlephobia.com/result?p=@rc-component/menu -[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/menu -[dumi-url]: https://github.com/umijs/dumi -[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square +
+ +
+ + Part of the Ant Design ecosystem + Ant Design + +
+ +## Highlights + +- Horizontal, vertical, and inline menu modes. +- Controlled and uncontrolled selection, open keys, and active key state. +- `items` configuration API with legacy children support. +- Sub menus, item groups, dividers, icons, overflow, popup rendering, and keyboard focus helpers. +- TypeScript definitions and semantic `classNames` / `styles` slots. +- Used by Ant Design as the shared menu foundation. ## Install -[![@rc-component/menu](https://nodei.co/npm/@rc-component/menu.png)](https://npmjs.org/package/@rc-component/menu) +```bash +npm install @rc-component/menu +``` ## Usage -```js -import Menu, { SubMenu, MenuItem } from '@rc-component/menu'; +```tsx | pure +import Menu, { type MenuProps } from '@rc-component/menu'; + +const items: MenuProps['items'] = [ + { key: 'home', label: 'Home' }, + { + key: 'docs', + label: 'Docs', + children: [ + { key: 'quick-start', label: 'Quick start' }, + { key: 'api', label: 'API' }, + ], + }, +]; + +export default () => ( + +); +``` -ReactDOM.render( +```tsx | pure +import Menu, { MenuItem, SubMenu } from '@rc-component/menu'; + +export default () => ( - 1 - - 2-1 + Item 1 + + Item 2-1 - , - container, + ); ``` -## Compatibility - -| [IE / Edge](http://godban.github.io/browsers-support-badges/)
IE / Edge | [Firefox](http://godban.github.io/browsers-support-badges/)
Firefox | [Chrome](http://godban.github.io/browsers-support-badges/)
Chrome | [Safari](http://godban.github.io/browsers-support-badges/)
Safari | [Electron](http://godban.github.io/browsers-support-badges/)
Electron | -| --- | --- | --- | --- | --- | -| IE11, Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions | +## Examples -## API - -### Menu props - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
nametypedefaultdescription
refReact.HTMLLIElementget dom node
classNameStringadditional css class of root dom node
modeStringverticalone of ["horizontal","inline","vertical-left","vertical-right"]
activeKeyStringinitial and current active menu item's key.
defaultActiveFirstBooleanfalsewhether active first menu item when show if activeKey is not set or invalid
multipleBooleanfalsewhether allow multiple select
selectableBooleantrueallow selecting menu items
selectedKeysString[][]selected keys of items
defaultSelectedKeysString[][]initial selected keys of items
openKeysString[][]open keys of SubMenuItem
defaultOpenKeysString[][]initial open keys of SubMenuItem
onSelectfunction({key:String, item:ReactComponent, domEvent:Event, selectedKeys:String[],ItemData:ItemData})called when select a menu item
onClickfunction({key:String, item:ReactComponent, domEvent:Event, keyPath: String[], ItemData:ItemData})called when click a menu item
onOpenChange(openKeys:String[]) => voidcalled when open/close sub menu
onDeselectfunction({key:String, item:ReactComponent, domEvent:Event, selectedKeys:String[]})called when deselect a menu item. only called when allow multiple
triggerSubMenuActionEnum { hover, click }hoverwhich action can trigger submenu open/close
openAnimation{enter:function,leave:function}|Stringanimate when sub menu open or close. see @rc-component/motion for object type.
openTransitionStringcss transitionName when sub menu open or close
subMenuOpenDelayNumber0delay time to show popup sub menu. unit: s
subMenuCloseDelayNumber0.1delay time to hide popup sub menu. unit: s
forceSubMenuRenderBooleanfalsewhether to render submenu even if it is not visible
getPopupContainerFunction(menuDOMNode): HTMLElement() => document.bodyWhere to render the DOM node of popup menu when the mode is horizontal or vertical
builtinPlacementsObject of alignConfigs for dom-alignsee placements.tsDescribes how the popup menus should be positioned
itemIconReactNode | (props: MenuItemProps) => ReactNodeSpecify the menu item icon.
expandIconReactNode | (props: SubMenuProps & { isSubMenu: boolean }) => ReactNodeSpecify the menu item icon.
directionStringLayout direction of menu component, it supports RTL direction too.
inlineIndentNumber24Padding level multiplier. Right or left padding depends on param "direction".
- -### Menu.Item props - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
nametypedefaultdescription
classNameStringadditional css class of root dom node
disabledBooleanfalseno effect for click or keydown for this item
extraReact.ReactNodeSpecify menu item extra node.
keyObjectcorresponding to activeKey
onMouseEnterFunction({eventKey, domEvent})
onMouseLeaveFunction({eventKey, domEvent})
itemIconReactNode | (props: MenuItemProps) => ReactNodeSpecify the menu item icon.
- -### Menu.SubMenu props - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
nametypedefaultdescription
refReact.HTMLLIElementget dom node
popupClassNameStringadditional css class of root dom node
popupStyleCSSPropertiesadditional css style of root dom node
titleString/ReactElementsub menu's content
overflowedIndicatorString/ReactElement···overflow indicator when menu overlows in horizontal mode
keyObjectcorresponding to activeKey
disabledBooleanfalseno effect for click or keydown for this item
onMouseEnterFunction({eventKey, domEvent})
onMouseLeaveFunction({eventKey, domEvent})
onTitleMouseEnterFunction({eventKey, domEvent})
onTitleMouseLeaveFunction({eventKey, domEvent})
onTitleClickFunction({eventKey, domEvent})
popupOffsetArrayThe offset of the popup submenu, in an x, y coordinate array. e.g.: `[0,15]`
expandIconReactNode | (props: SubMenuProps) => ReactNodeSpecify the menu item icon.
itemIconReactNode | (props: SubMenuProps & { isSubMenu: boolean }) => ReactNodeSpecify the menu item icon.
- -### Menu.Divider props - -none - -### Menu.ItemGroup props - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
nametypedefaultdescription
refReact.HTMLLIElementget dom node
titleString|React.Elementtitle of item group
childrenReact.Element[]MenuItems belonged to this group
- -## Development +Run the examples locally: -``` +```bash npm install npm start ``` -## Example +Then open the dumi dev server in your browser. -http://localhost:8001/examples/index.md +## API -online example: http://react-component.github.io/menu/examples/ +### Menu + +| Property | Type | Default | Description | +| --- | --- | --- | --- | +| activeKey | `string` | - | Controlled active item key. | +| builtinPlacements | `Record` | - | Popup alignment placements for sub menus. | +| className | `string` | - | Class name for the root menu. | +| classNames | `Partial>` | - | Semantic class names for menu slots. | +| defaultActiveFirst | `boolean` | `false` | Focus the first enabled item when active key is absent. | +| defaultOpenKeys | `string[]` | `[]` | Initial open sub menu keys. | +| defaultSelectedKeys | `string[]` | `[]` | Initial selected item keys. | +| defaultMotions | `Partial>` | - | Motion config by menu mode. | +| direction | `'ltr' \| 'rtl'` | - | Layout direction. | +| disabled | `boolean` | `false` | Disable all menu interactions. | +| disabledOverflow | `boolean` | `false` | Disable overflow measurement. | +| expandIcon | `ReactNode \| (props: RenderIconInfo) => ReactNode` | - | Custom sub menu expand icon. | +| forceSubMenuRender | `boolean` | `false` | Render popup sub menus before they are opened. | +| getPopupContainer | `(node: HTMLElement) => HTMLElement` | - | Container for popup sub menus. | +| inlineCollapsed | `boolean` | - | Collapse inline menu layout. | +| inlineIndent | `number` | `24` | Indent width for inline mode. | +| itemIcon | `ReactNode \| (props: RenderIconInfo) => ReactNode` | - | Custom item icon. | +| items | `ItemType[]` | - | Menu item configuration. | +| mode | `'horizontal' \| 'vertical' \| 'inline'` | `vertical` | Menu display mode. | +| motion | `CSSMotionProps` | - | Motion config for menu transitions. | +| multiple | `boolean` | `false` | Allow multiple selected items. | +| openKeys | `string[]` | - | Controlled open sub menu keys. | +| overflowedIndicator | `ReactNode` | `...` | Indicator rendered for overflowed items. | +| popupRender | `(node, info) => ReactNode` | - | Customize popup menu rendering. | +| prefixCls | `string` | `rc-menu` | Class name prefix. | +| rootClassName | `string` | - | Class name for the root wrapper. | +| selectable | `boolean` | `true` | Allow item selection. | +| selectedKeys | `string[]` | - | Controlled selected item keys. | +| styles | `Partial>` | - | Semantic styles for menu slots. | +| subMenuCloseDelay | `number` | `0.1` | Delay in seconds before closing popup sub menus. | +| subMenuOpenDelay | `number` | `0.1` | Delay in seconds before opening popup sub menus. | +| triggerSubMenuAction | `'click' \| 'hover'` | `hover` | Interaction that opens sub menus. | +| onClick | `(info: MenuInfo) => void` | - | Triggered when an item is clicked. | +| onDeselect | `(info: SelectInfo) => void` | - | Triggered when an item is deselected. | +| onOpenChange | `(openKeys: string[]) => void` | - | Triggered when open keys change. | +| onSelect | `(info: SelectInfo) => void` | - | Triggered when an item is selected. | + +### ItemType + +```ts +type ItemType = + | { + type?: 'item'; + key: React.Key; + label?: React.ReactNode; + disabled?: boolean; + itemIcon?: RenderIconType; + extra?: React.ReactNode; + } + | { + type?: 'submenu'; + key: string; + label?: React.ReactNode; + children: ItemType[]; + disabled?: boolean; + } + | { + type: 'group'; + label?: React.ReactNode; + children?: ItemType[]; + } + | { + type: 'divider'; + }; +``` -## Test Case +### Ref -``` +| Method | Type | Description | +| --- | --- | --- | +| `focus` | `(options?: FocusOptions) => void` | Focus the active item or first enabled item. | +| `findItem` | `({ key: string }) => HTMLElement \| null` | Find the DOM element for an item key. | +| `list` | `HTMLUListElement` | Root menu list element. | + +## Development + +```bash +npm install +npm start npm test -npm run chrome-test +npm run tsc +npm run compile +npm run build ``` -## Coverage +## Release -``` -npm run coverage +The package is published with [`@rc-component/np`](https://github.com/react-component/np): + +```bash +npm run prepublishOnly ``` -open coverage/ dir +This runs the package build before the release helper. The `postpublish` script also syncs `@rc-component/menu` to tnpm after publishing. ## License -@rc-component/menu is released under the MIT license. +`@rc-component/menu` is released under the MIT license. + +[npm-image]: https://img.shields.io/npm/v/@rc-component/menu.svg?style=flat-square +[npm-url]: https://npmjs.org/package/@rc-component/menu +[github-actions-image]: https://github.com/react-component/menu/actions/workflows/react-component-ci.yml/badge.svg +[github-actions-url]: https://github.com/react-component/menu/actions/workflows/react-component-ci.yml +[codecov-image]: https://img.shields.io/codecov/c/github/react-component/menu/master.svg?style=flat-square +[codecov-url]: https://app.codecov.io/gh/react-component/menu +[download-image]: https://img.shields.io/npm/dm/@rc-component/menu.svg?style=flat-square +[download-url]: https://npmjs.org/package/@rc-component/menu +[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/menu +[bundlephobia-image]: https://img.shields.io/bundlephobia/minzip/@rc-component/menu?style=flat-square +[dumi-url]: https://github.com/umijs/dumi +[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square diff --git a/now.json b/now.json deleted file mode 100644 index 2f8b73fd..00000000 --- a/now.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "version": 2, - "name": "rc-menu", - "builds": [ - { - "src": "package.json", - "use": "@now/static-build", - "config": { "distDir": ".doc" } - } - ], - "routes": [ - { "src": "/(.*)", "dest": "/dist/$1" } - ] -} diff --git a/package.json b/package.json index 4d137325..4d877e84 100644 --- a/package.json +++ b/package.json @@ -31,16 +31,20 @@ "assets/*.less" ], "scripts": { + "build": "npm run docs:build", "compile": "father build && lessc assets/index.less assets/index.css", "coverage": "rc-test --coverage", "docs:build": "dumi build", - "docs:deploy": "gh-pages -d .doc", + "docs:deploy": "gh-pages -d docs-dist", + "gh-pages": "GH_PAGES=1 npm run docs:build && npm run docs:deploy", "lint": "eslint src/ --ext .tsx,.ts,.jsx,.js", - "now-build": "npm run build", + "now-build": "npm run docs:build", "prepublishOnly": "npm run compile && rc-np", - "postpublish": "tnpm sync @rc-component/menu", + "postpublish": "npm run gh-pages && tnpm sync @rc-component/menu", + "prettier": "prettier --write --ignore-unknown .", "start": "dumi dev", "test": "rc-test", + "tsc": "tsc --noEmit", "prepare": "husky && dumi setup" }, "dependencies": { diff --git a/tsconfig.json b/tsconfig.json index 0e7a3f4a..2da8b22d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,5 +12,7 @@ "@@/*": [".dumi/tmp/*"], "@rc-component/menu": ["src/index.ts"] } - } + }, + "include": ["src", "docs", ".dumirc.ts", ".fatherrc.js"], + "exclude": ["node_modules", "lib", "es", "dist", "docs-dist", ".dumi"] } diff --git a/vercel.json b/vercel.json new file mode 100644 index 00000000..5f9139ef --- /dev/null +++ b/vercel.json @@ -0,0 +1,6 @@ +{ + "framework": "umijs", + "installCommand": "npm install", + "buildCommand": "npm run build", + "outputDirectory": "docs-dist" +} From 09bd2ac549d0861964d5a077e589a76182b4a898 Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 26 Jun 2026 14:44:39 +0800 Subject: [PATCH 02/36] chore: address review feedback --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4d877e84..c29ee1f7 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "lint": "eslint src/ --ext .tsx,.ts,.jsx,.js", "now-build": "npm run docs:build", "prepublishOnly": "npm run compile && rc-np", - "postpublish": "npm run gh-pages && tnpm sync @rc-component/menu", + "postpublish": "tnpm sync @rc-component/menu", "prettier": "prettier --write --ignore-unknown .", "start": "dumi dev", "test": "rc-test", From c021089c5d18365d3090f0efc94c40ac5c267628 Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 26 Jun 2026 14:45:56 +0800 Subject: [PATCH 03/36] docs: clarify menu README details --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f05e38e5..613e98d3 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ Then open the dumi dev server in your browser. | motion | `CSSMotionProps` | - | Motion config for menu transitions. | | multiple | `boolean` | `false` | Allow multiple selected items. | | openKeys | `string[]` | - | Controlled open sub menu keys. | -| overflowedIndicator | `ReactNode` | `...` | Indicator rendered for overflowed items. | +| overflowedIndicator | `ReactNode` | `"..."` | Indicator rendered for overflowed items. | | popupRender | `(node, info) => ReactNode` | - | Customize popup menu rendering. | | prefixCls | `string` | `rc-menu` | Class name prefix. | | rootClassName | `string` | - | Class name for the root wrapper. | @@ -130,6 +130,7 @@ Then open the dumi dev server in your browser. type ItemType = | { type?: 'item'; + // Item keys accept React.Key and are normalized to strings in event info. key: React.Key; label?: React.ReactNode; disabled?: boolean; @@ -138,6 +139,7 @@ type ItemType = } | { type?: 'submenu'; + // Sub menu keys are strings to match openKeys/defaultOpenKeys. key: string; label?: React.ReactNode; children: ItemType[]; From 37170c7b42b4b404b21b00851e0172fca4a38952 Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 26 Jun 2026 15:04:18 +0800 Subject: [PATCH 04/36] chore: remove cloudflare preview and now-build --- .../workflows/cloudflare-pages-preview.yml | 42 ------------------- package.json | 1 - 2 files changed, 43 deletions(-) delete mode 100644 .github/workflows/cloudflare-pages-preview.yml diff --git a/.github/workflows/cloudflare-pages-preview.yml b/.github/workflows/cloudflare-pages-preview.yml deleted file mode 100644 index d925f518..00000000 --- a/.github/workflows/cloudflare-pages-preview.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Cloudflare Pages Preview - -on: - pull_request: - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number }} - cancel-in-progress: true - -permissions: - contents: read - deployments: write - -jobs: - preview: - runs-on: ubuntu-latest - env: - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - CLOUDFLARE_PAGES_PROJECT: ${{ vars.CLOUDFLARE_PAGES_PROJECT }} - PREVIEW: true - steps: - - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 - with: - persist-credentials: false - - name: Skip Cloudflare Pages preview - if: ${{ env.CLOUDFLARE_API_TOKEN == '' || env.CLOUDFLARE_ACCOUNT_ID == '' || env.CLOUDFLARE_PAGES_PROJECT == '' }} - run: echo "Cloudflare Pages preview is not configured; skip deployment." - - name: Install dependencies - if: ${{ env.CLOUDFLARE_API_TOKEN != '' && env.CLOUDFLARE_ACCOUNT_ID != '' && env.CLOUDFLARE_PAGES_PROJECT != '' }} - run: npm install - - name: Build site - if: ${{ env.CLOUDFLARE_API_TOKEN != '' && env.CLOUDFLARE_ACCOUNT_ID != '' && env.CLOUDFLARE_PAGES_PROJECT != '' }} - run: npm run build - - name: Deploy preview - if: ${{ env.CLOUDFLARE_API_TOKEN != '' && env.CLOUDFLARE_ACCOUNT_ID != '' && env.CLOUDFLARE_PAGES_PROJECT != '' }} - uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 - with: - apiToken: ${{ env.CLOUDFLARE_API_TOKEN }} - accountId: ${{ env.CLOUDFLARE_ACCOUNT_ID }} - command: pages deploy docs-dist --project-name=${{ env.CLOUDFLARE_PAGES_PROJECT }} --branch=${{ github.head_ref }} - gitHubToken: ${{ secrets.GITHUB_TOKEN }} diff --git a/package.json b/package.json index c29ee1f7..f5f6265a 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ "docs:deploy": "gh-pages -d docs-dist", "gh-pages": "GH_PAGES=1 npm run docs:build && npm run docs:deploy", "lint": "eslint src/ --ext .tsx,.ts,.jsx,.js", - "now-build": "npm run docs:build", "prepublishOnly": "npm run compile && rc-np", "postpublish": "tnpm sync @rc-component/menu", "prettier": "prettier --write --ignore-unknown .", From 3cb2f76ee4753f3a9d5ddcad7125a53f6d4e905e Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 00:42:10 +0800 Subject: [PATCH 05/36] docs: add Ant Design logo to README header --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 613e98d3..fcdc62cd 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@

@rc-component/menu

+ Ant Design

🧭 Accessible React menu primitives for navigation, command surfaces, and nested item trees.

From eec212b1b02cd3e0636b4916302de21e4a916a67 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 01:27:55 +0800 Subject: [PATCH 06/36] chore: address AI review feedback --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index f5f6265a..eda50144 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "coverage": "rc-test --coverage", "docs:build": "dumi build", "docs:deploy": "gh-pages -d docs-dist", - "gh-pages": "GH_PAGES=1 npm run docs:build && npm run docs:deploy", + "gh-pages": "cross-env GH_PAGES=1 npm run docs:build && npm run docs:deploy", "lint": "eslint src/ --ext .tsx,.ts,.jsx,.js", "prepublishOnly": "npm run compile && rc-np", "postpublish": "tnpm sync @rc-component/menu", @@ -64,6 +64,7 @@ "@types/react-dom": "^18.3.7", "@types/warning": "^3.0.0", "@umijs/fabric": "^4.0.1", + "cross-env": "^7.0.0", "dumi": "^2.1.17", "eslint": "^8.55.0", "father": "^4.0.0", From 2f0c77edaf050978c340ee92a90af2012c2ed2d1 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 01:56:48 +0800 Subject: [PATCH 07/36] docs: standardize README release details --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fcdc62cd..4ef69cf8 100644 --- a/README.md +++ b/README.md @@ -177,17 +177,15 @@ npm run build ## Release -The package is published with [`@rc-component/np`](https://github.com/react-component/np): - ```bash npm run prepublishOnly ``` -This runs the package build before the release helper. The `postpublish` script also syncs `@rc-component/menu` to tnpm after publishing. +The release flow is handled by `@rc-component/np` through the `rc-np` command after the package build. ## License -`@rc-component/menu` is released under the MIT license. +@rc-component/menu is released under the [MIT](./LICENSE.md) license. [npm-image]: https://img.shields.io/npm/v/@rc-component/menu.svg?style=flat-square [npm-url]: https://npmjs.org/package/@rc-component/menu From 86a600280c0e877df47c440bba1a9a5aa1450207 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 02:13:57 +0800 Subject: [PATCH 08/36] ci: make surge preview non-blocking --- .github/workflows/surge-preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml index 1b29a17b..ad8683da 100644 --- a/.github/workflows/surge-preview.yml +++ b/.github/workflows/surge-preview.yml @@ -29,7 +29,7 @@ jobs: surge_token: ${{ env.SURGE_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }} dist: docs-dist - failOnError: true + failOnError: false setCommitStatus: true build: | npm install From f8613d085b8bd2fc9912e6aa03819c0d17f37ed1 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 02:17:44 +0800 Subject: [PATCH 09/36] docs: clarify Ant Design ecosystem note --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 4ef69cf8..decdf541 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,15 @@

🧭 Accessible React menu primitives for navigation, command surfaces, and nested item trees.

+

+ + + Ant Design + + Part of the Ant Design ecosystem. + +

+
[![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] From 970f8c61528cd82cf58bb72e8182d042d97b5608 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 02:25:41 +0800 Subject: [PATCH 10/36] ci: keep surge preview as fallback --- .github/workflows/surge-preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml index ad8683da..70768bf2 100644 --- a/.github/workflows/surge-preview.yml +++ b/.github/workflows/surge-preview.yml @@ -30,7 +30,7 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} dist: docs-dist failOnError: false - setCommitStatus: true + setCommitStatus: false build: | npm install npm run build From 498ca8ea071ce84ef1097b0d39d11e97cd1178f8 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 13:04:00 +0800 Subject: [PATCH 11/36] docs: refine README usage and ecosystem note --- README.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/README.md b/README.md index decdf541..eb827a69 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,10 @@

@rc-component/menu

+

Part of the Ant Design ecosystem.

Ant Design

🧭 Accessible React menu primitives for navigation, command surfaces, and nested item trees.

-

- - - Ant Design - - Part of the Ant Design ecosystem. - -

From 431bf788498183a111a484de4cdf1b83e77ff939 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 13:22:15 +0800 Subject: [PATCH 12/36] ci: isolate surge preview token --- .github/workflows/surge-preview.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml index 70768bf2..faf6b8bd 100644 --- a/.github/workflows/surge-preview.yml +++ b/.github/workflows/surge-preview.yml @@ -17,23 +17,26 @@ jobs: preview: runs-on: ubuntu-latest env: - SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} PREVIEW: true steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 with: persist-credentials: false + - name: Build preview + if: ${{ secrets.SURGE_TOKEN != '' }} + run: | + npm install + npm run build - uses: afc163/surge-preview@bf90a5a86111f6311ca42f0a5a0f80fb0fb03cec - if: ${{ env.SURGE_TOKEN != '' }} + if: ${{ secrets.SURGE_TOKEN != '' }} + env: + SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} with: surge_token: ${{ env.SURGE_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }} dist: docs-dist failOnError: false setCommitStatus: false - build: | - npm install - npm run build - name: Skip Surge preview - if: ${{ env.SURGE_TOKEN == '' }} + if: ${{ secrets.SURGE_TOKEN == '' }} run: echo "SURGE_TOKEN is not configured; skip Surge preview." From 5b1d27e1a00c9dba6f73057d4d3bfb8efdd9cf44 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 13:50:52 +0800 Subject: [PATCH 13/36] chore: address review comments --- README.md | 10 ---------- package.json | 1 - tsconfig.json | 2 +- 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/README.md b/README.md index eb827a69..f6bd4ce5 100644 --- a/README.md +++ b/README.md @@ -12,16 +12,6 @@
-
- - Part of the Ant Design ecosystem - Ant Design - -
## Highlights diff --git a/package.json b/package.json index eda50144..aa396c73 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ "gh-pages": "cross-env GH_PAGES=1 npm run docs:build && npm run docs:deploy", "lint": "eslint src/ --ext .tsx,.ts,.jsx,.js", "prepublishOnly": "npm run compile && rc-np", - "postpublish": "tnpm sync @rc-component/menu", "prettier": "prettier --write --ignore-unknown .", "start": "dumi dev", "test": "rc-test", diff --git a/tsconfig.json b/tsconfig.json index 2da8b22d..18a8d24a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,6 +13,6 @@ "@rc-component/menu": ["src/index.ts"] } }, - "include": ["src", "docs", ".dumirc.ts", ".fatherrc.js"], + "include": ["src", "docs", ".dumirc.ts"], "exclude": ["node_modules", "lib", "es", "dist", "docs-dist", ".dumi"] } From 05f4d204466021a56e5e8eea67e8bbdf6f8c17dc Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 22:00:50 +0800 Subject: [PATCH 14/36] docs: update Ant Design logo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f6bd4ce5..1fb9c2ea 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

@rc-component/menu

Part of the Ant Design ecosystem.

- Ant Design + Ant Design

🧭 Accessible React menu primitives for navigation, command surfaces, and nested item trees.

From 97abc94ca34ffd8a191ad2a01d0a2c34cfb3ef4c Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 22:19:39 +0800 Subject: [PATCH 15/36] docs: add Chinese README --- README.md | 2 + README.zh-CN.md | 195 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 197 insertions(+) create mode 100644 README.zh-CN.md diff --git a/README.md b/README.md index 1fb9c2ea..4a26f19a 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@

🧭 Accessible React menu primitives for navigation, command surfaces, and nested item trees.

+

English | 简体中文

+
diff --git a/README.zh-CN.md b/README.zh-CN.md new file mode 100644 index 00000000..57a17c27 --- /dev/null +++ b/README.zh-CN.md @@ -0,0 +1,195 @@ +
+

@rc-component/menu

+

Ant Design 生态的一部分。

+ Ant Design +

🧭 React 菜单组件,支持水平、垂直、内联、分组和子菜单。

+
+ +

English | 简体中文

+ + +
+ +[![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] + +
+ + +## 特性 + +- Horizontal, vertical, and inline menu modes. +- Controlled and uncontrolled selection, open keys, and active key state. +- `items` configuration API with legacy children support. +- Sub menus, item groups, dividers, icons, overflow, popup rendering, and keyboard focus helpers. +- 提供 TypeScript 类型定义和语义化 `classNames` / `styles` 插槽。 +- 被 Ant Design 用作共享的 menu 基础能力。 + +## 安装 + +```bash +npm install @rc-component/menu +``` + +## 使用 + +```tsx | pure +import Menu, { type MenuProps } from '@rc-component/menu'; + +const items: MenuProps['items'] = [ + { key: 'home', label: 'Home' }, + { + key: 'docs', + label: 'Docs', + children: [ + { key: 'quick-start', label: 'Quick start' }, + { key: 'api', label: 'API' }, + ], + }, +]; + +export default () => ( + +); +``` + +```tsx | pure +import Menu, { MenuItem, SubMenu } from '@rc-component/menu'; + +export default () => ( + + Item 1 + + Item 2-1 + + +); +``` + +## 示例 + +本地运行示例: + +```bash +npm install +npm start +``` + +然后在浏览器中打开 dumi 开发服务地址。 + +## API + +### Menu + +| 参数 | 类型 | 默认值 | 说明 | +| --- | --- | --- | --- | +| activeKey | `string` | - | Controlled active item key. | +| builtinPlacements | `Record` | - | Popup alignment placements for sub menus. | +| className | `string` | - | Class name for the root menu. | +| classNames | `Partial>` | - | Semantic class names for menu slots. | +| defaultActiveFirst | `boolean` | `false` | Focus the first enabled item when active key is absent. | +| defaultOpenKeys | `string[]` | `[]` | Initial open sub menu keys. | +| defaultSelectedKeys | `string[]` | `[]` | Initial selected item keys. | +| defaultMotions | `Partial>` | - | Motion config by menu mode. | +| direction | `'ltr' \| 'rtl'` | - | Layout direction. | +| disabled | `boolean` | `false` | Disable all menu interactions. | +| disabledOverflow | `boolean` | `false` | Disable overflow measurement. | +| expandIcon | `ReactNode \| (props: RenderIconInfo) => ReactNode` | - | Custom sub menu expand icon. | +| forceSubMenuRender | `boolean` | `false` | Render popup sub menus before they are opened. | +| getPopupContainer | `(node: HTMLElement) => HTMLElement` | - | Container for popup sub menus. | +| inlineCollapsed | `boolean` | - | Collapse inline menu layout. | +| inlineIndent | `number` | `24` | Indent width for inline mode. | +| itemIcon | `ReactNode \| (props: RenderIconInfo) => ReactNode` | - | Custom item icon. | +| items | `ItemType[]` | - | Menu item configuration. | +| mode | `'horizontal' \| 'vertical' \| 'inline'` | `vertical` | Menu display mode. | +| motion | `CSSMotionProps` | - | Motion config for menu transitions. | +| multiple | `boolean` | `false` | Allow multiple selected items. | +| openKeys | `string[]` | - | Controlled open sub menu keys. | +| overflowedIndicator | `ReactNode` | `"..."` | Indicator rendered for overflowed items. | +| popupRender | `(node, info) => ReactNode` | - | Customize popup menu rendering. | +| prefixCls | `string` | `rc-menu` | Class name prefix. | +| rootClassName | `string` | - | Class name for the root wrapper. | +| selectable | `boolean` | `true` | Allow item selection. | +| selectedKeys | `string[]` | - | Controlled selected item keys. | +| styles | `Partial>` | - | Semantic styles for menu slots. | +| subMenuCloseDelay | `number` | `0.1` | Delay in seconds before closing popup sub menus. | +| subMenuOpenDelay | `number` | `0.1` | Delay in seconds before opening popup sub menus. | +| triggerSubMenuAction | `'click' \| 'hover'` | `hover` | Interaction that opens sub menus. | +| onClick | `(info: MenuInfo) => void` | - | Triggered when an item is clicked. | +| onDeselect | `(info: SelectInfo) => void` | - | Triggered when an item is deselected. | +| onOpenChange | `(openKeys: string[]) => void` | - | Triggered when open keys change. | +| onSelect | `(info: SelectInfo) => void` | - | Triggered when an item is selected. | + +### ItemType + +```ts +type ItemType = + | { + type?: 'item'; + // Item keys accept React.Key and are normalized to strings in event info. + key: React.Key; + label?: React.ReactNode; + disabled?: boolean; + itemIcon?: RenderIconType; + extra?: React.ReactNode; + } + | { + type?: 'submenu'; + // Sub menu keys are strings to match openKeys/defaultOpenKeys. + key: string; + label?: React.ReactNode; + children: ItemType[]; + disabled?: boolean; + } + | { + type: 'group'; + label?: React.ReactNode; + children?: ItemType[]; + } + | { + type: 'divider'; + }; +``` + +### Ref + +| Method | 类型 | 说明 | +| --- | --- | --- | +| `focus` | `(options?: FocusOptions) => void` | Focus the active item or first enabled item. | +| `findItem` | `({ key: string }) => HTMLElement \| null` | Find the DOM element for an item key. | +| `list` | `HTMLUListElement` | Root menu list element. | + +## 本地开发 + +```bash +npm install +npm start +npm test +npm run tsc +npm run compile +npm run build +``` + +## 发布 + +```bash +npm run prepublishOnly +``` + +The release flow is handled by `@rc-component/np` through the `rc-np` command after the package build. + +## 许可证 + +@rc-component/menu is released under the [MIT](./LICENSE.md) license. + +[npm-image]: https://img.shields.io/npm/v/@rc-component/menu.svg?style=flat-square +[npm-url]: https://npmjs.org/package/@rc-component/menu +[github-actions-image]: https://github.com/react-component/menu/actions/workflows/react-component-ci.yml/badge.svg +[github-actions-url]: https://github.com/react-component/menu/actions/workflows/react-component-ci.yml +[codecov-image]: https://img.shields.io/codecov/c/github/react-component/menu/master.svg?style=flat-square +[codecov-url]: https://app.codecov.io/gh/react-component/menu +[download-image]: https://img.shields.io/npm/dm/@rc-component/menu.svg?style=flat-square +[download-url]: https://npmjs.org/package/@rc-component/menu +[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/menu +[bundlephobia-image]: https://img.shields.io/bundlephobia/minzip/@rc-component/menu?style=flat-square +[dumi-url]: https://github.com/umijs/dumi +[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square From 32a66337dec13f0aa662875b3e7c86c46c67f981 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 23:03:15 +0800 Subject: [PATCH 16/36] docs: refine bilingual README branding --- README.md | 3 +- README.zh-CN.md | 89 ++++++++++++++++++++++++------------------------- 2 files changed, 45 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 4a26f19a..67f9ae72 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@

@rc-component/menu

-

Part of the Ant Design ecosystem.

- Ant Design +

Ant Design Part of the Ant Design ecosystem.

🧭 Accessible React menu primitives for navigation, command surfaces, and nested item trees.

diff --git a/README.zh-CN.md b/README.zh-CN.md index 57a17c27..1216c8f0 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -1,7 +1,6 @@

@rc-component/menu

-

Ant Design 生态的一部分。

- Ant Design +

Ant Design Ant Design 生态的一部分。

🧭 React 菜单组件,支持水平、垂直、内联、分组和子菜单。

@@ -17,10 +16,10 @@ ## 特性 -- Horizontal, vertical, and inline menu modes. -- Controlled and uncontrolled selection, open keys, and active key state. -- `items` configuration API with legacy children support. -- Sub menus, item groups, dividers, icons, overflow, popup rendering, and keyboard focus helpers. +- 水平、垂直和内联菜单模式。 +- 受控和非受控选择、打开键和活动键状态。 +- `items` 配置 API 具有旧子支持。 +- 子菜单、项目组、分隔线、图标、溢出、弹层渲染和键盘焦点助手。 - 提供 TypeScript 类型定义和语义化 `classNames` / `styles` 插槽。 - 被 Ant Design 用作共享的 menu 基础能力。 @@ -82,42 +81,42 @@ npm start | 参数 | 类型 | 默认值 | 说明 | | --- | --- | --- | --- | -| activeKey | `string` | - | Controlled active item key. | -| builtinPlacements | `Record` | - | Popup alignment placements for sub menus. | -| className | `string` | - | Class name for the root menu. | -| classNames | `Partial>` | - | Semantic class names for menu slots. | -| defaultActiveFirst | `boolean` | `false` | Focus the first enabled item when active key is absent. | -| defaultOpenKeys | `string[]` | `[]` | Initial open sub menu keys. | -| defaultSelectedKeys | `string[]` | `[]` | Initial selected item keys. | -| defaultMotions | `Partial>` | - | Motion config by menu mode. | +| activeKey | `string` | - | 受控活动项目键。 | +| builtinPlacements | `Record` | - | 子菜单的弹层对齐位置。 | +| className | `string` | - | 根菜单的className。 | +| classNames | `Partial>` | - | 菜单槽的语义className称。 | +| defaultActiveFirst | `boolean` | `false` | 当活动键不存在时,聚焦第一个启用的项目。 | +| defaultOpenKeys | `string[]` | `[]` | 初始打开子菜单键。 | +| defaultSelectedKeys | `string[]` | `[]` | 初始选定项目键。 | +| defaultMotions | `Partial>` | - | 通过菜单模式进行运动配置。 | | direction | `'ltr' \| 'rtl'` | - | Layout direction. | -| disabled | `boolean` | `false` | Disable all menu interactions. | -| disabledOverflow | `boolean` | `false` | Disable overflow measurement. | -| expandIcon | `ReactNode \| (props: RenderIconInfo) => ReactNode` | - | Custom sub menu expand icon. | -| forceSubMenuRender | `boolean` | `false` | Render popup sub menus before they are opened. | -| getPopupContainer | `(node: HTMLElement) => HTMLElement` | - | Container for popup sub menus. | -| inlineCollapsed | `boolean` | - | Collapse inline menu layout. | -| inlineIndent | `number` | `24` | Indent width for inline mode. | -| itemIcon | `ReactNode \| (props: RenderIconInfo) => ReactNode` | - | Custom item icon. | -| items | `ItemType[]` | - | Menu item configuration. | +| disabled | `boolean` | `false` | 禁用所有菜单交互。 | +| disabledOverflow | `boolean` | `false` | 禁用溢出测量。 | +| expandIcon | `ReactNode \| (props: RenderIconInfo) => ReactNode` | - | 自定义子菜单展开图标。 | +| forceSubMenuRender | `boolean` | `false` | 在打开弹层子菜单之前渲染它们。 | +| getPopupContainer | `(node: HTMLElement) => HTMLElement` | - | 弹层子菜单的容器。 | +| inlineCollapsed | `boolean` | - | 折叠内联菜单布局。 | +| inlineIndent | `number` | `24` | 内联模式的缩进宽度。 | +| itemIcon | `ReactNode \| (props: RenderIconInfo) => ReactNode` | - | 自定义项目图标。 | +| 项目 | `ItemType[]` | - | 菜单项配置。 | | mode | `'horizontal' \| 'vertical' \| 'inline'` | `vertical` | Menu display mode. | -| motion | `CSSMotionProps` | - | Motion config for menu transitions. | -| multiple | `boolean` | `false` | Allow multiple selected items. | -| openKeys | `string[]` | - | Controlled open sub menu keys. | -| overflowedIndicator | `ReactNode` | `"..."` | Indicator rendered for overflowed items. | -| popupRender | `(node, info) => ReactNode` | - | Customize popup menu rendering. | -| prefixCls | `string` | `rc-menu` | Class name prefix. | -| rootClassName | `string` | - | Class name for the root wrapper. | -| selectable | `boolean` | `true` | Allow item selection. | -| selectedKeys | `string[]` | - | Controlled selected item keys. | -| styles | `Partial>` | - | Semantic styles for menu slots. | -| subMenuCloseDelay | `number` | `0.1` | Delay in seconds before closing popup sub menus. | -| subMenuOpenDelay | `number` | `0.1` | Delay in seconds before opening popup sub menus. | -| triggerSubMenuAction | `'click' \| 'hover'` | `hover` | Interaction that opens sub menus. | -| onClick | `(info: MenuInfo) => void` | - | Triggered when an item is clicked. | -| onDeselect | `(info: SelectInfo) => void` | - | Triggered when an item is deselected. | -| onOpenChange | `(openKeys: string[]) => void` | - | Triggered when open keys change. | -| onSelect | `(info: SelectInfo) => void` | - | Triggered when an item is selected. | +| 运动 | `CSSMotionProps` | - | 菜单转换的运动配置。 | +| multiple | `boolean` | `false` | 允许选择多个项目。 | +| openKeys | `string[]` | - | 受控打开子菜单键。 | +| overflowedIndicator | `ReactNode` | `"..."` | 为溢出项目呈现的指示器。 | +| popupRender | `(node, info) => ReactNode` | - | 自定义弹层菜单渲染。 | +| prefixCls | `string` | `rc-menu` | className前缀。 | +| rootClassName | `string` | - | 根包装器的className。 | +| selectable | `boolean` | `true` | 允许选择项目。 | +| selectedKeys | `string[]` | - | 控制选定的项目键。 | +| styles | `Partial>` | - | 菜单槽的语义样式。 | +| subMenuCloseDelay | `number` | `0.1` | 关闭弹层子菜单之前延迟几秒。 | +| subMenuOpenDelay | `number` | `0.1` | 打开弹层子菜单之前延迟几秒。 | +| triggerSubMenuAction | `'click' \| 'hover'` | `hover` | 打开子菜单的交互。 | +| onClick | `(info: MenuInfo) => void` | - | 单击某个项目时触发。 | +| onDeselect | `(info: SelectInfo) => void` | - | 取消选择某个项目时触发。 | +| onOpenChange | `(openKeys: string[]) => void` | - | 当打开键更改时触发。 | +| onSelect | `(info: SelectInfo) => void` | - | 选择项目时触发。 | ### ItemType @@ -154,9 +153,9 @@ type ItemType = | Method | 类型 | 说明 | | --- | --- | --- | -| `focus` | `(options?: FocusOptions) => void` | Focus the active item or first enabled item. | -| `findItem` | `({ key: string }) => HTMLElement \| null` | Find the DOM element for an item key. | -| `list` | `HTMLUListElement` | Root menu list element. | +| `focus` | `(options?: FocusOptions) => void` | 聚焦活动项目或第一个启用的项目。 | +| `findItem` | `({ key: string }) => HTMLElement \| null` | 查找项目键的 DOM 元素。 | +| `list` | `HTMLUListElement` | 根菜单列表元素。 | ## 本地开发 @@ -175,11 +174,11 @@ npm run build npm run prepublishOnly ``` -The release flow is handled by `@rc-component/np` through the `rc-np` command after the package build. +包构建完成后,发布流程由 `@rc-component/np` 通过 `rc-np` 命令处理。 ## 许可证 -@rc-component/menu is released under the [MIT](./LICENSE.md) license. +@rc-component/menu 基于 [MIT](./LICENSE.md) 许可证发布。 [npm-image]: https://img.shields.io/npm/v/@rc-component/menu.svg?style=flat-square [npm-url]: https://npmjs.org/package/@rc-component/menu From cd9ae5c19bb538d44851bb99cff42883dcc3bdcd Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 01:28:40 +0800 Subject: [PATCH 17/36] chore: standardize rc tooling and docs --- .dumirc.ts | 2 +- README.md | 4 ++-- README.zh-CN.md | 4 ++-- package.json | 38 +++++++++++++++++++------------------- tsconfig.json | 30 ++++++++++++++++++++++++------ 5 files changed, 48 insertions(+), 30 deletions(-) diff --git a/.dumirc.ts b/.dumirc.ts index 03f4625b..50c681a4 100644 --- a/.dumirc.ts +++ b/.dumirc.ts @@ -2,7 +2,7 @@ import { defineConfig } from 'dumi'; const basePath = process.env.GH_PAGES ? '/menu/' : '/'; -const publicPath = process.env.GH_PAGES ? '/menu/' : '/'; +const publicPath = basePath; export default defineConfig({ themeConfig: { diff --git a/README.md b/README.md index 67f9ae72..b66315b4 100644 --- a/README.md +++ b/README.md @@ -66,14 +66,14 @@ export default () => ( ## Examples -Run the examples locally: +Run the local dumi site: ```bash npm install npm start ``` -Then open the dumi dev server in your browser. +Then open `http://localhost:8000`. ## API diff --git a/README.zh-CN.md b/README.zh-CN.md index 1216c8f0..c2c8d212 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -66,14 +66,14 @@ export default () => ( ## 示例 -本地运行示例: +运行本地 dumi 站点: ```bash npm install npm start ``` -然后在浏览器中打开 dumi 开发服务地址。 +然后打开 `http://localhost:8000`。 ## API diff --git a/package.json b/package.json index aa396c73..f83a8254 100644 --- a/package.json +++ b/package.json @@ -53,29 +53,29 @@ "clsx": "^2.1.1" }, "devDependencies": { - "@rc-component/father-plugin": "^2.0.2", - "@rc-component/np": "^1.0.3", - "@testing-library/jest-dom": "^6.1.5", - "@testing-library/react": "^16.0.0", - "@types/jest": "^30.0.0", - "@types/node": "^24.7.1", - "@types/react": "^18.2.14", + "@rc-component/father-plugin": "^2.2.0", + "@rc-component/np": "^1.0.4", + "@testing-library/jest-dom": "^6.9.1", + "@testing-library/react": "^15.0.7", + "@types/jest": "^29.5.14", + "@types/node": "^26.0.1", + "@types/react": "^18.3.31", "@types/react-dom": "^18.3.7", - "@types/warning": "^3.0.0", + "@types/warning": "^3.0.4", "@umijs/fabric": "^4.0.1", - "cross-env": "^7.0.0", - "dumi": "^2.1.17", - "eslint": "^8.55.0", - "father": "^4.0.0", - "gh-pages": "^6.1.0", - "husky": "^9.1.6", - "less": "^4.1.3", - "lint-staged": "^16.2.4", - "prettier": "^3.3.3", - "rc-test": "^7.0.14", + "cross-env": "^10.1.0", + "dumi": "^2.4.35", + "eslint": "^8.57.1", + "father": "^4.6.23", + "gh-pages": "^6.3.0", + "husky": "^9.1.7", + "less": "^4.6.7", + "lint-staged": "^16.4.0", + "prettier": "^3.9.0", + "rc-test": "^7.1.3", "react": "^18.3.1", "react-dom": "^18.3.1", - "typescript": "^5.1.6" + "typescript": "^5.9.3" }, "peerDependencies": { "react": ">=16.9.0", diff --git a/tsconfig.json b/tsconfig.json index 18a8d24a..42638649 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,11 +8,29 @@ "skipLibCheck": true, "esModuleInterop": true, "paths": { - "@/*": ["src/*"], - "@@/*": [".dumi/tmp/*"], - "@rc-component/menu": ["src/index.ts"] - } + "@/*": [ + "src/*" + ], + "@@/*": [ + ".dumi/tmp/*" + ], + "@rc-component/menu": [ + "src/index.ts" + ] + }, + "ignoreDeprecations": "5.0" }, - "include": ["src", "docs", ".dumirc.ts"], - "exclude": ["node_modules", "lib", "es", "dist", "docs-dist", ".dumi"] + "include": [ + "src", + "docs", + ".dumirc.ts" + ], + "exclude": [ + "node_modules", + "lib", + "es", + "dist", + "docs-dist", + ".dumi" + ] } From 18c43a54cb8f7597c8ca26d4df7dfe7e7ccf64d6 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 02:01:05 +0800 Subject: [PATCH 18/36] chore: address standardization review comments --- .github/workflows/surge-preview.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml index faf6b8bd..cb6c8c4a 100644 --- a/.github/workflows/surge-preview.yml +++ b/.github/workflows/surge-preview.yml @@ -22,13 +22,23 @@ jobs: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 with: persist-credentials: false + - name: Check Surge token + id: surge-token + env: + SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} + run: | + if [ -n "$SURGE_TOKEN" ]; then + echo "enabled=true" >> "$GITHUB_OUTPUT" + else + echo "enabled=false" >> "$GITHUB_OUTPUT" + fi - name: Build preview - if: ${{ secrets.SURGE_TOKEN != '' }} + if: ${{ steps.surge-token.outputs.enabled == 'true' }} run: | npm install npm run build - uses: afc163/surge-preview@bf90a5a86111f6311ca42f0a5a0f80fb0fb03cec - if: ${{ secrets.SURGE_TOKEN != '' }} + if: ${{ steps.surge-token.outputs.enabled == 'true' }} env: SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} with: @@ -38,5 +48,5 @@ jobs: failOnError: false setCommitStatus: false - name: Skip Surge preview - if: ${{ secrets.SURGE_TOKEN == '' }} + if: ${{ steps.surge-token.outputs.enabled != 'true' }} run: echo "SURGE_TOKEN is not configured; skip Surge preview." From 75a41ad2b64f17cf99d65d78befb73dbe902c392 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 12:23:59 +0800 Subject: [PATCH 19/36] ci: update GitHub Actions versions --- .github/workflows/codeql.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 7df7bc4c..5d5b3c8d 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -29,15 +29,15 @@ jobs: persist-credentials: false - name: Initialize CodeQL - uses: github/codeql-action/init@8aad20d150bbac5944a9f9d289da16a4b0d87c1e + uses: github/codeql-action/init@a0853c24544627f65ddf259abe73b1d18a591444 with: languages: ${{ matrix.language }} queries: +security-and-quality - name: Autobuild - uses: github/codeql-action/autobuild@8aad20d150bbac5944a9f9d289da16a4b0d87c1e + uses: github/codeql-action/autobuild@a0853c24544627f65ddf259abe73b1d18a591444 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@8aad20d150bbac5944a9f9d289da16a4b0d87c1e + uses: github/codeql-action/analyze@a0853c24544627f65ddf259abe73b1d18a591444 with: category: '/language:${{ matrix.language }}' From cdec0255e652475bac9fbf23e98def8979e523a5 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 12:29:10 +0800 Subject: [PATCH 20/36] ci: use resolvable CodeQL action ref --- .github/workflows/codeql.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 5d5b3c8d..7df7bc4c 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -29,15 +29,15 @@ jobs: persist-credentials: false - name: Initialize CodeQL - uses: github/codeql-action/init@a0853c24544627f65ddf259abe73b1d18a591444 + uses: github/codeql-action/init@8aad20d150bbac5944a9f9d289da16a4b0d87c1e with: languages: ${{ matrix.language }} queries: +security-and-quality - name: Autobuild - uses: github/codeql-action/autobuild@a0853c24544627f65ddf259abe73b1d18a591444 + uses: github/codeql-action/autobuild@8aad20d150bbac5944a9f9d289da16a4b0d87c1e - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@a0853c24544627f65ddf259abe73b1d18a591444 + uses: github/codeql-action/analyze@8aad20d150bbac5944a9f9d289da16a4b0d87c1e with: category: '/language:${{ matrix.language }}' From 087137f8e40783cf7d6a1b90f1a646d2e26aafac Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 13:27:26 +0800 Subject: [PATCH 21/36] docs: add license file --- LICENSE | 21 +++++++++++++++++++++ README.md | 2 +- README.zh-CN.md | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..bd0a1f72 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019-present react-component + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index b66315b4..9443c8fa 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,7 @@ The release flow is handled by `@rc-component/np` through the `rc-np` command af ## License -@rc-component/menu is released under the [MIT](./LICENSE.md) license. +@rc-component/menu is released under the [MIT](./LICENSE) license. [npm-image]: https://img.shields.io/npm/v/@rc-component/menu.svg?style=flat-square [npm-url]: https://npmjs.org/package/@rc-component/menu diff --git a/README.zh-CN.md b/README.zh-CN.md index c2c8d212..b71b347a 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -178,7 +178,7 @@ npm run prepublishOnly ## 许可证 -@rc-component/menu 基于 [MIT](./LICENSE.md) 许可证发布。 +@rc-component/menu 基于 [MIT](./LICENSE) 许可证发布。 [npm-image]: https://img.shields.io/npm/v/@rc-component/menu.svg?style=flat-square [npm-url]: https://npmjs.org/package/@rc-component/menu From 7f3835a2d9ac0b287e68449f8a0565e3d9861976 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 14:00:24 +0800 Subject: [PATCH 22/36] ci: use actions checkout v7 --- .github/workflows/codeql.yml | 2 +- .github/workflows/react-doctor.yml | 2 +- .github/workflows/surge-preview.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 7df7bc4c..984e4786 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -24,7 +24,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 + uses: actions/checkout@v7 with: persist-credentials: false diff --git a/.github/workflows/react-doctor.yml b/.github/workflows/react-doctor.yml index f68281c8..097eb883 100644 --- a/.github/workflows/react-doctor.yml +++ b/.github/workflows/react-doctor.yml @@ -20,7 +20,7 @@ jobs: react-doctor: runs-on: ubuntu-latest steps: - - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 + - uses: actions/checkout@v7 with: fetch-depth: 0 persist-credentials: false diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml index cb6c8c4a..ebfecd53 100644 --- a/.github/workflows/surge-preview.yml +++ b/.github/workflows/surge-preview.yml @@ -19,7 +19,7 @@ jobs: env: PREVIEW: true steps: - - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 + - uses: actions/checkout@v7 with: persist-credentials: false - name: Check Surge token From a84c96c0533db12736ca51ff521ebbeb30c40a5c Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 14:31:05 +0800 Subject: [PATCH 23/36] chore: standardize package metadata --- package.json | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f83a8254..833d2b79 100644 --- a/package.json +++ b/package.json @@ -9,13 +9,13 @@ "ui", "react-menu" ], - "homepage": "http://github.com/react-component/menu", + "homepage": "https://react-component.github.io/menu", "bugs": { - "url": "http://github.com/react-component/menu/issues" + "url": "https://github.com/react-component/menu/issues" }, "repository": { "type": "git", - "url": "git@github.com:react-component/menu.git" + "url": "https://github.com/react-component/menu.git" }, "license": "MIT", "maintainers": [ @@ -83,5 +83,8 @@ }, "lint-staged": { "*": "prettier --write --ignore-unknown" + }, + "publishConfig": { + "access": "public" } } From 1121e47f3b4707e5d598f31c795b9573a7ee7328 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 14:37:24 +0800 Subject: [PATCH 24/36] ci: standardize dependabot updates --- .github/dependabot.yml | 43 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 6745ced9..3b730ef9 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,28 +1,19 @@ version: 2 updates: -- package-ecosystem: npm - directory: "/" - schedule: - interval: daily - time: "21:00" - open-pull-requests-limit: 10 - ignore: - - dependency-name: "@types/react-dom" - versions: - - 17.0.0 - - 17.0.1 - - 17.0.2 - - dependency-name: "@types/react" - versions: - - 17.0.0 - - 17.0.1 - - 17.0.2 - - 17.0.3 - - dependency-name: np - versions: - - 7.2.0 - - 7.3.0 - - 7.4.0 - - dependency-name: less - versions: - - 4.1.0 + - package-ecosystem: npm + directory: '/' + schedule: + interval: weekly + day: monday + time: '21:00' + timezone: Asia/Shanghai + open-pull-requests-limit: 10 + + - package-ecosystem: github-actions + directory: '/' + schedule: + interval: weekly + day: monday + time: '21:00' + timezone: Asia/Shanghai + open-pull-requests-limit: 10 From 2bc2983c2d53e0894a396e94cbbc94cb03e5f9e3 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 16:26:55 +0800 Subject: [PATCH 25/36] docs: fix Chinese README API names --- README.zh-CN.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/README.zh-CN.md b/README.zh-CN.md index b71b347a..1f0d7db1 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -6,14 +6,12 @@

English | 简体中文

-
[![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]
- ## 特性 - 水平、垂直和内联菜单模式。 @@ -98,9 +96,9 @@ npm start | inlineCollapsed | `boolean` | - | 折叠内联菜单布局。 | | inlineIndent | `number` | `24` | 内联模式的缩进宽度。 | | itemIcon | `ReactNode \| (props: RenderIconInfo) => ReactNode` | - | 自定义项目图标。 | -| 项目 | `ItemType[]` | - | 菜单项配置。 | +| items | `ItemType[]` | - | 菜单项配置。 | | mode | `'horizontal' \| 'vertical' \| 'inline'` | `vertical` | Menu display mode. | -| 运动 | `CSSMotionProps` | - | 菜单转换的运动配置。 | +| motion | `CSSMotionProps` | - | 菜单转换的运动配置。 | | multiple | `boolean` | `false` | 允许选择多个项目。 | | openKeys | `string[]` | - | 受控打开子菜单键。 | | overflowedIndicator | `ReactNode` | `"..."` | 为溢出项目呈现的指示器。 | @@ -151,11 +149,11 @@ type ItemType = ### Ref -| Method | 类型 | 说明 | -| --- | --- | --- | -| `focus` | `(options?: FocusOptions) => void` | 聚焦活动项目或第一个启用的项目。 | -| `findItem` | `({ key: string }) => HTMLElement \| null` | 查找项目键的 DOM 元素。 | -| `list` | `HTMLUListElement` | 根菜单列表元素。 | +| Method | 类型 | 说明 | +| ---------- | ------------------------------------------ | -------------------------------- | +| `focus` | `(options?: FocusOptions) => void` | 聚焦活动项目或第一个启用的项目。 | +| `findItem` | `({ key: string }) => HTMLElement \| null` | 查找项目键的 DOM 元素。 | +| `list` | `HTMLUListElement` | 根菜单列表元素。 | ## 本地开发 From 37e28796842b35556e1f7d1fcb6373e88c1934ad Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 16:51:59 +0800 Subject: [PATCH 26/36] docs: localize Chinese README descriptions --- README.zh-CN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.zh-CN.md b/README.zh-CN.md index 1f0d7db1..c07eac11 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -97,7 +97,7 @@ npm start | inlineIndent | `number` | `24` | 内联模式的缩进宽度。 | | itemIcon | `ReactNode \| (props: RenderIconInfo) => ReactNode` | - | 自定义项目图标。 | | items | `ItemType[]` | - | 菜单项配置。 | -| mode | `'horizontal' \| 'vertical' \| 'inline'` | `vertical` | Menu display mode. | +| mode | `'horizontal' \| 'vertical' \| 'inline'` | `vertical` | 菜单展示模式。 | | motion | `CSSMotionProps` | - | 菜单转换的运动配置。 | | multiple | `boolean` | `false` | 允许选择多个项目。 | | openKeys | `string[]` | - | 受控打开子菜单键。 | From 89716f5ca7e427620e89f7b914c2a5c065c80fca Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 17:15:08 +0800 Subject: [PATCH 27/36] chore: refine preview workflow ignores --- .github/workflows/surge-preview.yml | 3 +++ .prettierignore | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 .prettierignore diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml index ebfecd53..eaff160a 100644 --- a/.github/workflows/surge-preview.yml +++ b/.github/workflows/surge-preview.yml @@ -16,6 +16,9 @@ permissions: jobs: preview: runs-on: ubuntu-latest + concurrency: + group: surge-preview-${{ github.event.pull_request.number }} + cancel-in-progress: true env: PREVIEW: true steps: diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..c466d872 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,14 @@ +node_modules +coverage +docs-dist +dist +es +lib +.dumi/tmp +.dumi/tmp-production +.vercel +package-lock.json +pnpm-lock.yaml +yarn.lock +bun.lockb +*.log From 272d935d69f4d4553018a2036ac274148b530928 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 17:36:12 +0800 Subject: [PATCH 28/36] docs: polish Chinese README wording --- README.zh-CN.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.zh-CN.md b/README.zh-CN.md index c07eac11..56e497e8 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -81,8 +81,8 @@ npm start | --- | --- | --- | --- | | activeKey | `string` | - | 受控活动项目键。 | | builtinPlacements | `Record` | - | 子菜单的弹层对齐位置。 | -| className | `string` | - | 根菜单的className。 | -| classNames | `Partial>` | - | 菜单槽的语义className称。 | +| className | `string` | - | 根菜单的 className。 | +| classNames | `Partial>` | - | 菜单槽的语义 className。 | | defaultActiveFirst | `boolean` | `false` | 当活动键不存在时,聚焦第一个启用的项目。 | | defaultOpenKeys | `string[]` | `[]` | 初始打开子菜单键。 | | defaultSelectedKeys | `string[]` | `[]` | 初始选定项目键。 | @@ -103,8 +103,8 @@ npm start | openKeys | `string[]` | - | 受控打开子菜单键。 | | overflowedIndicator | `ReactNode` | `"..."` | 为溢出项目呈现的指示器。 | | popupRender | `(node, info) => ReactNode` | - | 自定义弹层菜单渲染。 | -| prefixCls | `string` | `rc-menu` | className前缀。 | -| rootClassName | `string` | - | 根包装器的className。 | +| prefixCls | `string` | `rc-menu` | className 前缀。 | +| rootClassName | `string` | - | 根包装器的 className。 | | selectable | `boolean` | `true` | 允许选择项目。 | | selectedKeys | `string[]` | - | 控制选定的项目键。 | | styles | `Partial>` | - | 菜单槽的语义样式。 | From 5a3fb913c51516e5e0251f1e7a38a4c9b49a99aa Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 19:13:35 +0800 Subject: [PATCH 29/36] chore: align father config and Chinese README --- .fatherrc.ts | 5 +++++ README.zh-CN.md | 2 +- tsconfig.json | 27 +++++---------------------- 3 files changed, 11 insertions(+), 23 deletions(-) create mode 100644 .fatherrc.ts diff --git a/.fatherrc.ts b/.fatherrc.ts new file mode 100644 index 00000000..96268ae1 --- /dev/null +++ b/.fatherrc.ts @@ -0,0 +1,5 @@ +import { defineConfig } from 'father'; + +export default defineConfig({ + plugins: ['@rc-component/father-plugin'], +}); diff --git a/README.zh-CN.md b/README.zh-CN.md index 56e497e8..49de117c 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -87,7 +87,7 @@ npm start | defaultOpenKeys | `string[]` | `[]` | 初始打开子菜单键。 | | defaultSelectedKeys | `string[]` | `[]` | 初始选定项目键。 | | defaultMotions | `Partial>` | - | 通过菜单模式进行运动配置。 | -| direction | `'ltr' \| 'rtl'` | - | Layout direction. | +| direction | `'ltr' \| 'rtl'` | - | 布局方向。 | | disabled | `boolean` | `false` | 禁用所有菜单交互。 | | disabledOverflow | `boolean` | `false` | 禁用溢出测量。 | | expandIcon | `ReactNode \| (props: RenderIconInfo) => ReactNode` | - | 自定义子菜单展开图标。 | diff --git a/tsconfig.json b/tsconfig.json index 42638649..0f80b4f2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,29 +8,12 @@ "skipLibCheck": true, "esModuleInterop": true, "paths": { - "@/*": [ - "src/*" - ], - "@@/*": [ - ".dumi/tmp/*" - ], - "@rc-component/menu": [ - "src/index.ts" - ] + "@/*": ["src/*"], + "@@/*": [".dumi/tmp/*"], + "@rc-component/menu": ["src/index.ts"] }, "ignoreDeprecations": "5.0" }, - "include": [ - "src", - "docs", - ".dumirc.ts" - ], - "exclude": [ - "node_modules", - "lib", - "es", - "dist", - "docs-dist", - ".dumi" - ] + "include": ["src", "docs", ".dumirc.ts", ".fatherrc.ts"], + "exclude": ["node_modules", "lib", "es", "dist", "docs-dist", ".dumi"] } From a97adc133a64929e05b56f5dab172843cb3f5f00 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 19:38:32 +0800 Subject: [PATCH 30/36] docs: document dumi dev server port --- README.md | 4 ++-- README.zh-CN.md | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9443c8fa..675bf454 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,12 @@

English | 简体中文

-
[![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]
- ## Highlights - Horizontal, vertical, and inline menu modes. @@ -168,6 +166,8 @@ npm run compile npm run build ``` +The dumi site runs at `http://localhost:8000` by default. + ## Release ```bash diff --git a/README.zh-CN.md b/README.zh-CN.md index 49de117c..a33b323e 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -166,6 +166,8 @@ npm run compile npm run build ``` +dumi 站点默认运行在 `http://localhost:8000`。 + ## 发布 ```bash From b558b0e56726a375ee445c63aaa72521472f315a Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 19:57:49 +0800 Subject: [PATCH 31/36] chore: standardize husky configuration --- .husky/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index c27d8893..2312dc58 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1 +1 @@ -lint-staged +npx lint-staged From 006bea4a3d1d07d6bcfaab3cf1156be1423e2c05 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 20:06:17 +0800 Subject: [PATCH 32/36] docs: align readme badge layout --- README.md | 28 +++++++++------------------- README.zh-CN.md | 28 +++++++++------------------- 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 675bf454..ac8052cc 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,19 @@

@rc-component/menu

Ant Design Part of the Ant Design ecosystem.

🧭 Accessible React menu primitives for navigation, command surfaces, and nested item trees.

+ +

+ NPM version + npm downloads + build status + Codecov + bundle size + dumi +

English | 简体中文

-
- -[![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] - -
- ## Highlights - Horizontal, vertical, and inline menu modes. @@ -179,16 +182,3 @@ The release flow is handled by `@rc-component/np` through the `rc-np` command af ## License @rc-component/menu is released under the [MIT](./LICENSE) license. - -[npm-image]: https://img.shields.io/npm/v/@rc-component/menu.svg?style=flat-square -[npm-url]: https://npmjs.org/package/@rc-component/menu -[github-actions-image]: https://github.com/react-component/menu/actions/workflows/react-component-ci.yml/badge.svg -[github-actions-url]: https://github.com/react-component/menu/actions/workflows/react-component-ci.yml -[codecov-image]: https://img.shields.io/codecov/c/github/react-component/menu/master.svg?style=flat-square -[codecov-url]: https://app.codecov.io/gh/react-component/menu -[download-image]: https://img.shields.io/npm/dm/@rc-component/menu.svg?style=flat-square -[download-url]: https://npmjs.org/package/@rc-component/menu -[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/menu -[bundlephobia-image]: https://img.shields.io/bundlephobia/minzip/@rc-component/menu?style=flat-square -[dumi-url]: https://github.com/umijs/dumi -[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square diff --git a/README.zh-CN.md b/README.zh-CN.md index a33b323e..cfb19eb7 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -2,16 +2,19 @@

@rc-component/menu

Ant Design Ant Design 生态的一部分。

🧭 React 菜单组件,支持水平、垂直、内联、分组和子菜单。

+ +

+ NPM version + npm downloads + build status + Codecov + bundle size + dumi +

English | 简体中文

-
- -[![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] - -
- ## 特性 - 水平、垂直和内联菜单模式。 @@ -179,16 +182,3 @@ npm run prepublishOnly ## 许可证 @rc-component/menu 基于 [MIT](./LICENSE) 许可证发布。 - -[npm-image]: https://img.shields.io/npm/v/@rc-component/menu.svg?style=flat-square -[npm-url]: https://npmjs.org/package/@rc-component/menu -[github-actions-image]: https://github.com/react-component/menu/actions/workflows/react-component-ci.yml/badge.svg -[github-actions-url]: https://github.com/react-component/menu/actions/workflows/react-component-ci.yml -[codecov-image]: https://img.shields.io/codecov/c/github/react-component/menu/master.svg?style=flat-square -[codecov-url]: https://app.codecov.io/gh/react-component/menu -[download-image]: https://img.shields.io/npm/dm/@rc-component/menu.svg?style=flat-square -[download-url]: https://npmjs.org/package/@rc-component/menu -[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/menu -[bundlephobia-image]: https://img.shields.io/bundlephobia/minzip/@rc-component/menu?style=flat-square -[dumi-url]: https://github.com/umijs/dumi -[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square From 10cd0bd0f488dbaa3c990bf645c9b1818fcbd9bb Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 20:32:26 +0800 Subject: [PATCH 33/36] chore: standardize package type entry --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 833d2b79..3fe3f9d4 100644 --- a/package.json +++ b/package.json @@ -86,5 +86,6 @@ }, "publishConfig": { "access": "public" - } + }, + "types": "./es/index.d.ts" } From bdf60e05961cebaa2f97b8e8c62a69b0af2515f2 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 21:20:12 +0800 Subject: [PATCH 34/36] ci: limit reusable workflow secrets --- .github/workflows/react-component-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/react-component-ci.yml b/.github/workflows/react-component-ci.yml index 9503b960..36dacae4 100644 --- a/.github/workflows/react-component-ci.yml +++ b/.github/workflows/react-component-ci.yml @@ -5,4 +5,5 @@ permissions: jobs: test: uses: react-component/rc-test/.github/workflows/test-utoo.yml@main - secrets: inherit + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} From 5679ad69d3f8e9637963ae14a37037dc7de44edd Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 21:33:03 +0800 Subject: [PATCH 35/36] ci: restore reusable workflow compatibility --- .github/workflows/react-component-ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/react-component-ci.yml b/.github/workflows/react-component-ci.yml index 36dacae4..9503b960 100644 --- a/.github/workflows/react-component-ci.yml +++ b/.github/workflows/react-component-ci.yml @@ -5,5 +5,4 @@ permissions: jobs: test: uses: react-component/rc-test/.github/workflows/test-utoo.yml@main - secrets: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + secrets: inherit From 08147e4577ba63faa108520e76324cd0eddc87ef Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 29 Jun 2026 00:47:18 +0800 Subject: [PATCH 36/36] ci: narrow surge preview permissions --- .github/workflows/surge-preview.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml index eaff160a..4c2f17ed 100644 --- a/.github/workflows/surge-preview.yml +++ b/.github/workflows/surge-preview.yml @@ -11,7 +11,6 @@ permissions: contents: read pull-requests: write checks: write - statuses: write jobs: preview: