├── .dumirc.ts
├── .editorconfig
├── .eslintrc.js
├── .fatherrc.js
├── .github
├── FUNDING.yml
├── dependabot.yml
└── workflows
│ ├── codeql.yml
│ └── main.yml
├── .gitignore
├── .prettierrc
├── CHANGELOG.md
├── LICENSE.md
├── README.md
├── assets
├── index.less
├── list.less
├── panel.less
└── select.less
├── bunfig.toml
├── docs
├── CHANGELOG.md
├── demo
│ ├── adjust-overflow.md
│ ├── animation.md
│ ├── change-on-select.md
│ ├── custom-arrow-icon.md
│ ├── custom-field-name.md
│ ├── debug.md
│ ├── default-expand-single-option.md
│ ├── defaultValue.md
│ ├── disabled.md
│ ├── dynamic-options.md
│ ├── hover.md
│ ├── multiple-search.md
│ ├── multiple.md
│ ├── option-render.md
│ ├── panel.md
│ ├── popup-render.md
│ ├── rc-form.md
│ ├── search.md
│ ├── simple.md
│ ├── text-trigger.md
│ ├── value.md
│ └── visible.md
└── index.md
├── examples
├── adjust-overflow.tsx
├── animation.tsx
├── change-on-select.tsx
├── custom-arrow-icon.tsx
├── custom-field-name.tsx
├── debug.tsx
├── default-expand-single-option.tsx
├── defaultValue.tsx
├── disabled.tsx
├── dynamic-options.tsx
├── hover.tsx
├── multiple-search.tsx
├── multiple.tsx
├── option-render.tsx
├── panel.tsx
├── popup-render.tsx
├── rc-form.tsx
├── search.tsx
├── simple.tsx
├── text-trigger.tsx
├── utils.tsx
├── value.tsx
└── visible.tsx
├── index.js
├── jest.config.js
├── package.json
├── src
├── Cascader.tsx
├── OptionList
│ ├── CacheContent.tsx
│ ├── Checkbox.tsx
│ ├── Column.tsx
│ ├── List.tsx
│ ├── index.tsx
│ ├── useActive.ts
│ └── useKeyboard.ts
├── Panel.tsx
├── context.ts
├── hooks
│ ├── useDisplayValues.ts
│ ├── useEntities.ts
│ ├── useMissingValues.ts
│ ├── useOptions.ts
│ ├── useSearchConfig.ts
│ ├── useSearchOptions.ts
│ ├── useSelect.ts
│ └── useValues.ts
├── index.tsx
└── utils
│ ├── commonUtil.ts
│ ├── treeUtil.ts
│ └── warningPropsUtil.ts
├── tests
├── Panel.spec.tsx
├── __mocks__
│ └── @rc-component
│ │ └── trigger.js
├── __snapshots__
│ ├── index.spec.tsx.snap
│ └── search.spec.tsx.snap
├── checkable.spec.tsx
├── demoOptions.ts
├── enzyme.ts
├── fieldNames.spec.tsx
├── index.spec.tsx
├── keyboard.spec.tsx
├── loadData.spec.tsx
├── private.spec.tsx
├── search.limit.spec.tsx
├── search.spec.tsx
├── selector.spec.tsx
├── semantic.spec.tsx
└── setup.js
├── tsconfig.json
└── update-example.js
/.dumirc.ts:
--------------------------------------------------------------------------------
1 | import { defineConfig } from 'dumi';
2 | import path from 'path';
3 |
4 | export default defineConfig({
5 | alias: {
6 | 'rc-cascader$': path.resolve('src'),
7 | 'rc-cascader/es': path.resolve('src'),
8 | },
9 | favicons: ['https://avatars0.githubusercontent.com/u/9441414?s=200&v=4'],
10 | themeConfig: {
11 | name: 'Cascader',
12 | logo: 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4',
13 | },
14 | });
15 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # top-most EditorConfig file
2 | root = true
3 |
4 | # Unix-style newlines with a newline ending every file
5 | [*.{js,css}]
6 | end_of_line = lf
7 | insert_final_newline = true
8 | indent_style = space
9 | indent_size = 2
10 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | const base = require('@umijs/fabric/dist/eslint');
2 |
3 | module.exports = {
4 | ...base,
5 | rules: {
6 | ...base.rules,
7 | 'no-template-curly-in-string': 0,
8 | 'prefer-promise-reject-errors': 0,
9 | 'react/no-array-index-key': 0,
10 | 'react/sort-comp': 0,
11 | '@typescript-eslint/no-explicit-any': 0,
12 | 'jsx-a11y/label-has-associated-control': 0,
13 | 'jsx-a11y/label-has-for': 0,
14 | 'import/no-extraneous-dependencies': 0,
15 | 'no-shadow': 0
16 | },
17 | };
18 |
--------------------------------------------------------------------------------
/.fatherrc.js:
--------------------------------------------------------------------------------
1 | import { defineConfig } from 'father';
2 |
3 | export default defineConfig({
4 | plugins: ['@rc-component/father-plugin'],
5 | });
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: ant-design # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: ant-design # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
12 | polar: # Replace with a single Polar username
13 | buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
14 | thanks_dev: # Replace with a single thanks.dev username
15 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
16 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: npm
4 | directory: "/"
5 | schedule:
6 | interval: daily
7 | time: "21:00"
8 | open-pull-requests-limit: 10
9 | ignore:
10 | - dependency-name: np
11 | versions:
12 | - 7.2.0
13 | - 7.3.0
14 | - 7.4.0
15 | - dependency-name: "@types/react"
16 | versions:
17 | - 17.0.0
18 | - 17.0.1
19 | - 17.0.2
20 | - 17.0.3
21 | - dependency-name: "@types/jest"
22 | versions:
23 | - 26.0.20
24 | - 26.0.21
25 | - 26.0.22
26 | - dependency-name: "@types/react-dom"
27 | versions:
28 | - 17.0.0
29 | - 17.0.1
30 | - 17.0.2
31 | - dependency-name: typescript
32 | versions:
33 | - 4.1.3
34 | - 4.1.4
35 | - 4.1.5
36 | - 4.2.2
37 | - 4.2.3
38 |
--------------------------------------------------------------------------------
/.github/workflows/codeql.yml:
--------------------------------------------------------------------------------
1 | name: "CodeQL"
2 |
3 | on:
4 | push:
5 | branches: [ "master" ]
6 | pull_request:
7 | branches: [ "master" ]
8 | schedule:
9 | - cron: "2 15 * * 3"
10 |
11 | jobs:
12 | analyze:
13 | name: Analyze
14 | runs-on: ubuntu-latest
15 | permissions:
16 | actions: read
17 | contents: read
18 | security-events: write
19 |
20 | strategy:
21 | fail-fast: false
22 | matrix:
23 | language: [ javascript ]
24 |
25 | steps:
26 | - name: Checkout
27 | uses: actions/checkout@v3
28 |
29 | - name: Initialize CodeQL
30 | uses: github/codeql-action/init@v2
31 | with:
32 | languages: ${{ matrix.language }}
33 | queries: +security-and-quality
34 |
35 | - name: Autobuild
36 | uses: github/codeql-action/autobuild@v2
37 |
38 | - name: Perform CodeQL Analysis
39 | uses: github/codeql-action/analyze@v2
40 | with:
41 | category: "/language:${{ matrix.language }}"
42 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: ✅ test
2 | on: [push, pull_request]
3 | jobs:
4 | test:
5 | uses: react-component/rc-test/.github/workflows/test-npm.yml@main
6 | secrets: inherit
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .storybook
2 | *.iml
3 | *.log
4 | .idea
5 | .ipr
6 | .iws
7 | *~
8 | ~*
9 | *.diff
10 | *.patch
11 | *.bak
12 | .DS_Store
13 | Thumbs.db
14 | .project
15 | .*proj
16 | .svn
17 | *.swp
18 | *.swo
19 | *.pyc
20 | *.pyo
21 | node_modules
22 | .cache
23 | *.css
24 | build
25 | lib
26 | es
27 | yarn.lock
28 | package-lock.json
29 | coverage
30 | # umi
31 | .umi
32 | .umi-production
33 | .umi-test
34 | .env.local
35 | .doc
36 |
37 | # dumi
38 | .dumi/tmp
39 | .dumi/tmp-production
40 | dist
41 | .vscode
42 |
43 | bun.lockb
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "endOfLine": "lf",
3 | "semi": true,
4 | "singleQuote": true,
5 | "tabWidth": 2,
6 | "trailingComma": "all",
7 | "printWidth": 100,
8 | "arrowParens": "avoid"
9 | }
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # History
2 |
3 | ## 0.17.0 / 2018/12/14
4 |
5 | - should close popup on double click when changeOnSelect is set
6 |
7 | ## 0.16.0 / 2018/08/23
8 |
9 | - Add loadingIcon.
10 |
11 | ## 0.15.0 / 2018/08/10
12 |
13 | - Add expandIcon.
14 |
15 | ## 0.14.0 / 2018/07/03
16 |
17 | - Fix typo `filedNames` to `fieldNames`. [ant-design/ant-design#10896](https://github.com/ant-design/ant-design/issues/10896)
18 |
19 | ## 0.13.0 / 2018/04/27
20 |
21 | - Allow to custom the field name of options. [#23](https://github.com/react-component/cascader/pull/23)
22 |
23 | ## 0.12.0
24 |
25 | - Add es build
26 | - support React 16
27 |
28 | ## 0.11.0 / 2017-01-17
29 |
30 | - Add Keyboard support
31 |
32 | ## 0.10.0 / 2016-08-20
33 |
34 | - Add `dropdownMenuColumnStyle`
35 | - Fix `changeOnSelect` when load data dynamicly
36 |
37 | ## 0.9.0 / 2016-02-19
38 |
39 | - support `popupPlacement`
40 |
41 | ## 0.8.0 / 2016-01-26
42 |
43 | - Add prop `changeOnSelect`
44 |
45 | ## 0.7.0 / 2016-01-25
46 |
47 | - Support disabled item
48 |
49 | ## 0.6.1 / 2016-01-18
50 |
51 | - Hide popup menu when there is no options, fix #4
52 |
53 | ## 0.6.0 / 2016-01-05
54 |
55 | - Add prop `disabled`.
56 |
57 | ## 0.5.1 / 2015-12-31
58 |
59 | - Always scroll to show active menu item
60 |
61 | ## 0.5.0 / 2015-12-30
62 |
63 | - Remove `onSelect`
64 | - Add `loadData` for dynamicly changing options
65 |
66 | ## 0.4.0 / 2015-12-29
67 |
68 | - Add prop `popupVisible`.
69 | - `onVisibleChange` => `onPopupVisibleChange`.
70 |
71 | ## 0.3.0 / 2015-12-28
72 |
73 | - Fix value and defaultValue.
74 | - Add Test Cases.
75 |
76 | ## 0.2.0 / 2015-12-25
77 |
78 | - Add prop `expandTrigger`.
79 |
80 | ## 0.1.0 / 2015-12-25
81 |
82 | First release.
83 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014-present alipay.com
4 |
5 | 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:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | 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.
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # rc-cascader
2 |
3 | React Cascader Component.
4 |
5 | [![NPM version][npm-image]][npm-url]
6 | [![npm download][download-image]][download-url]
7 | [![build status][github-actions-image]][github-actions-url]
8 | [![Codecov][codecov-image]][codecov-url]
9 | [![bundle size][bundlephobia-image]][bundlephobia-url]
10 | [![dumi][dumi-image]][dumi-url]
11 |
12 | [npm-image]: http://img.shields.io/npm/v/rc-cascader.svg?style=flat-square
13 | [npm-url]: http://npmjs.org/package/rc-cascader
14 | [travis-image]: https://img.shields.io/travis/react-component/cascader/master?style=flat-square
15 | [travis-url]: https://travis-ci.com/react-component/cascader
16 | [github-actions-image]: https://github.com/react-component/cascader/workflows/CI/badge.svg
17 | [github-actions-url]: https://github.com/react-component/cascader/actions
18 | [codecov-image]: https://img.shields.io/codecov/c/github/react-component/cascader/master.svg?style=flat-square
19 | [codecov-url]: https://app.codecov.io/gh/react-component/cascader
20 | [david-url]: https://david-dm.org/react-component/cascader
21 | [david-image]: https://david-dm.org/react-component/cascader/status.svg?style=flat-square
22 | [david-dev-url]: https://david-dm.org/react-component/cascader?type=dev
23 | [david-dev-image]: https://david-dm.org/react-component/cascader/dev-status.svg?style=flat-square
24 | [download-image]: https://img.shields.io/npm/dm/rc-cascader.svg?style=flat-square
25 | [download-url]: https://npmjs.org/package/rc-cascader
26 | [bundlephobia-url]: https://bundlephobia.com/package/rc-cascader
27 | [bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-cascader
28 | [dumi-url]: https://github.com/umijs/dumi
29 | [dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square
30 |
31 | ## Browser Support
32 |
33 | | [
](http://godban.github.io/browsers-support-badges/)
IE / Edge | [
](http://godban.github.io/browsers-support-badges/)
Firefox | [
](http://godban.github.io/browsers-support-badges/)
Chrome | [
](http://godban.github.io/browsers-support-badges/)
Safari | [
](http://godban.github.io/browsers-support-badges/)
Electron |
34 | | --- | --- | --- | --- | --- |
35 | | IE11, Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
36 |
37 | ## Screenshots
38 |
39 |
40 |
41 | ## Example
42 |
43 | https://cascader-react-component.vercel.app
44 |
45 | ## Install
46 |
47 | [](https://npmjs.org/package/rc-cascader)
48 |
49 | ```bash
50 | $ npm install rc-cascader --save
51 | ```
52 |
53 | ## Usage
54 |
55 | ```js
56 | import React from 'react';
57 | import Cascader from '@rc-component/cascader';
58 |
59 | const options = [{
60 | 'label': '福建',
61 | 'value': 'fj',
62 | 'children': [{
63 | 'label': '福州',
64 | 'value': 'fuzhou',
65 | 'children': [{
66 | 'label': '马尾',
67 | 'value': 'mawei',
68 | }],
69 | }, {
70 | 'label': '泉州',
71 | 'value': 'quanzhou',
72 | }],
73 | }, {
74 | 'label': '浙江',
75 | 'value': 'zj',
76 | 'children': [{
77 | 'label': '杭州',
78 | 'value': 'hangzhou',
79 | 'children': [{
80 | 'label': '余杭',
81 | 'value': 'yuhang',
82 | }],
83 | }],
84 | }, {
85 | 'label': '北京',
86 | 'value': 'bj',
87 | 'children': [{
88 | 'label': '朝阳区',
89 | 'value': 'chaoyang',
90 | }, {
91 | 'label': '海淀区',
92 | 'value': 'haidian',
93 | }],
94 | }];
95 |
96 | React.render(
97 |
98 | ...
99 |
100 | , container);
101 | ```
102 |
103 | ## API
104 |
105 | ### props
106 |
107 |
108 |
109 |
110 | name |
111 | type |
112 | default |
113 | description |
114 |
115 |
116 |
117 |
118 | autoClearSearchValue |
119 | boolean |
120 | true |
121 | Whether the current search will be cleared on selecting an item. Only applies when checkable |
122 |
123 |
124 | options |
125 | Object |
126 | |
127 | The data options of cascade |
128 |
129 |
130 | value |
131 | Array |
132 | |
133 | selected value |
134 |
135 |
136 | defaultValue |
137 | Array |
138 | |
139 | initial selected value |
140 |
141 |
142 | onChange |
143 | Function(value, selectedOptions) |
144 | |
145 | callback when finishing cascader select |
146 |
147 |
148 | changeOnSelect |
149 | Boolean |
150 | false |
151 | change value on each selection |
152 |
153 |
154 | loadData |
155 | Function(selectedOptions) |
156 | |
157 | callback when click any option, use for loading more options |
158 |
159 |
160 | expandTrigger |
161 | String |
162 | 'click' |
163 | expand current item when click or hover |
164 |
165 |
166 | open |
167 | Boolean |
168 | |
169 | visibility of popup overlay |
170 |
171 |
172 | onPopupVisibleChange |
173 | Function(visible) |
174 | |
175 | callback when popup overlay's visibility changed |
176 |
177 |
178 | transitionName |
179 | String |
180 | |
181 | transition className like "slide-up" |
182 |
183 |
184 | prefixCls |
185 | String |
186 | rc-cascader |
187 | prefix className of popup overlay |
188 |
189 |
190 | popupClassName |
191 | String |
192 | |
193 | additional className of popup overlay |
194 |
195 |
196 | popupPlacement |
197 | String |
198 | bottomLeft |
199 | use preset popup align config from builtinPlacements:bottomRight topRight bottomLeft topLeft |
200 |
201 |
202 | getPopupContainer |
203 | function(trigger:Node):Node |
204 | () => document.body |
205 | container which popup select menu rendered into |
206 |
207 |
208 | dropdownMenuColumnStyle |
209 | Object |
210 | |
211 | style object for each cascader pop menu |
212 |
213 |
214 | fieldNames |
215 | Object |
216 | { label: 'label', value: 'value', children: 'children' } |
217 | custom field name for label and value and children |
218 |
219 |
220 | expandIcon |
221 | ReactNode |
222 | > |
223 | specific the default expand icon |
224 |
225 |
226 | loadingIcon |
227 | ReactNode |
228 | > |
229 | specific the default loading icon |
230 |
231 |
232 | hidePopupOnSelect |
233 | Boolean |
234 | >true |
235 | hide popup on select |
236 |
237 |
238 |
239 |
240 | ### option
241 |
242 |
243 |
244 |
245 | name |
246 | type |
247 | default |
248 | description |
249 |
250 |
251 |
252 |
253 | label |
254 | String |
255 | |
256 | option text to display |
257 |
258 |
259 | value |
260 | String |
261 | |
262 | option value as react key |
263 |
264 |
265 | disabled |
266 | Boolean |
267 | |
268 | disabled option |
269 |
270 |
271 | children |
272 | Array |
273 | |
274 | children options |
275 |
276 |
277 |
278 |
279 | ## Development
280 |
281 | ```bash
282 | $ npm install
283 | $ npm start
284 | ```
285 |
286 | ## Test Case
287 |
288 | ```bash
289 | $ npm test
290 | ```
291 |
292 | ## Coverage
293 |
294 | ```bash
295 | $ npm run coverage
296 | ```
297 |
298 | ## License
299 |
300 | rc-cascader is released under the MIT license.
301 |
302 | ## 🤝 Contributing
303 |
304 |
305 |
306 |
--------------------------------------------------------------------------------
/assets/index.less:
--------------------------------------------------------------------------------
1 | @import "./select.less";
2 | @import "./list.less";
3 | @import "./panel.less";
--------------------------------------------------------------------------------
/assets/list.less:
--------------------------------------------------------------------------------
1 | @select-prefix: ~'rc-cascader';
2 |
3 | .@{select-prefix} {
4 | &-dropdown {
5 | min-height: auto;
6 | }
7 |
8 | &-menus {
9 | display: flex;
10 | flex-wrap: nowrap;
11 | }
12 |
13 | &-menu {
14 | flex: none;
15 | margin: 0;
16 | padding: 0;
17 | list-style: none;
18 | border-left: 1px solid blue;
19 | height: 180px;
20 | min-width: 100px;
21 | overflow: auto;
22 |
23 | &:first-child {
24 | border-left: 0;
25 | }
26 |
27 | &-item {
28 | display: flex;
29 | flex-wrap: nowrap;
30 | padding-right: 20px;
31 | position: relative;
32 |
33 | &:hover {
34 | background: rgba(0, 0, 255, 0.1);
35 | }
36 |
37 | &-selected {
38 | background: rgba(0, 0, 255, 0.05);
39 | }
40 |
41 | &-active {
42 | background: rgba(0, 255, 0, 0.1);
43 | }
44 |
45 | &-disabled {
46 | opacity: 0.5;
47 | }
48 |
49 |
50 |
51 | &-content {
52 | flex: auto;
53 | }
54 |
55 | &-expand-icon {
56 | position: absolute;
57 | right: 4px;
58 | top: 50%;
59 | transform: translateY(-50%);
60 | }
61 | }
62 | }
63 |
64 | &-checkbox {
65 | position: relative;
66 | display: block;
67 | flex: none;
68 | width: 20px;
69 | height: 20px;
70 | border: 1px solid blue;
71 |
72 | &::after {
73 | position: absolute;
74 | top: 50%;
75 | left: 50%;
76 | transform: translate(-50%, -50%);
77 | content: '';
78 | }
79 |
80 | &-checked::after {
81 | content: '✔️';
82 | }
83 |
84 | &-indeterminate::after {
85 | content: '➖';
86 | }
87 | }
88 |
89 | // ====================== RTL ======================
90 | &-rtl {
91 | direction: rtl;
92 |
93 | .@{select-prefix}-menu {
94 | flex: none;
95 | margin: 0;
96 | padding: 0;
97 | list-style: none;
98 | border-left: none;
99 | border-right: 1px solid blue;
100 |
101 | &:first-child {
102 | border-right: 0;
103 | }
104 | }
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/assets/panel.less:
--------------------------------------------------------------------------------
1 | @import (reference) './index.less';
2 |
3 | .@{select-prefix} {
4 | &-panel {
5 | border: 1px solid green;
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/assets/select.less:
--------------------------------------------------------------------------------
1 | @import '~@rc-component/select/assets/index';
2 |
3 | @select-prefix: ~'rc-cascader';
--------------------------------------------------------------------------------
/bunfig.toml:
--------------------------------------------------------------------------------
1 | [install]
2 | peer = false
--------------------------------------------------------------------------------
/docs/CHANGELOG.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docs/demo/adjust-overflow.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: adjust-overflow
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/animation.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: animation
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/change-on-select.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: change-on-select
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/custom-arrow-icon.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: custom-arrow-icon
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/custom-field-name.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: custom-field-name
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/debug.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: debug
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/default-expand-single-option.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: default-expand-single-option
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/defaultValue.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: defaultValue
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/disabled.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: disabled
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/dynamic-options.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: dynamic-options
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/hover.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: hover
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/multiple-search.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: multiple-search
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/multiple.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: multiple
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/option-render.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: option-render
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/panel.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Panel
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/popup-render.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: popup-render
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/rc-form.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: rc-form
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/search.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: search
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/simple.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: animated
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/text-trigger.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: text-trigger
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/value.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: value
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/demo/visible.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: visible
3 | nav:
4 | title: Demo
5 | path: /demo
6 | ---
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | hero:
3 | title: rc-cascader
4 | description: React cascader Component
5 | ---
6 |
7 |
8 |
--------------------------------------------------------------------------------
/examples/adjust-overflow.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import type { BuildInPlacements } from '@rc-component/trigger/lib/interface';
3 | import '../assets/index.less';
4 | import type { CascaderProps } from '../src';
5 | import Cascader from '../src';
6 | import type { Option2 } from './utils';
7 |
8 | const addressOptions = [
9 | {
10 | label: '福建',
11 | value: 'fj',
12 | children: [
13 | {
14 | label: '福州',
15 | value: 'fuzhou',
16 | children: [
17 | {
18 | label: '马尾',
19 | value: 'mawei',
20 | },
21 | ],
22 | },
23 | {
24 | label: '泉州',
25 | value: 'quanzhou',
26 | },
27 | ],
28 | },
29 | {
30 | label: '浙江',
31 | value: 'zj',
32 | children: [
33 | {
34 | label: '杭州',
35 | value: 'hangzhou',
36 | children: [
37 | {
38 | label: '余杭',
39 | value: 'yuhang',
40 | },
41 | ],
42 | },
43 | ],
44 | },
45 | {
46 | label: '北京',
47 | value: 'bj',
48 | children: [
49 | {
50 | label: '朝阳区',
51 | value: 'chaoyang',
52 | },
53 | {
54 | label: '海淀区',
55 | value: 'haidian',
56 | disabled: true,
57 | },
58 | ],
59 | },
60 | ];
61 |
62 | const MyCascader = ({ builtinPlacements }: { builtinPlacements?: BuildInPlacements }) => {
63 | const [inputValue, setInputValue] = useState('');
64 |
65 | const onChange: CascaderProps['onChange'] = (value, selectedOptions) => {
66 | console.log(value, selectedOptions);
67 | setInputValue(selectedOptions.map(o => o.label).join(', '));
68 | };
69 |
70 | return (
71 |
72 |
77 |
78 | );
79 | };
80 |
81 | const placements = {
82 | bottomLeft: {
83 | points: ['tl', 'bl'],
84 | offset: [0, 4],
85 | overflow: {
86 | adjustY: 1,
87 | },
88 | },
89 | topLeft: {
90 | points: ['bl', 'tl'],
91 | offset: [0, -4],
92 | overflow: {
93 | adjustY: 1,
94 | },
95 | },
96 | bottomRight: {
97 | points: ['tr', 'br'],
98 | offset: [0, 4],
99 | overflow: {
100 | adjustY: 1,
101 | },
102 | },
103 | topRight: {
104 | points: ['br', 'tr'],
105 | offset: [0, -4],
106 | overflow: {
107 | adjustY: 1,
108 | },
109 | },
110 | };
111 |
112 | function Demo() {
113 | return (
114 |
115 |
116 |
117 |
118 |
119 |
120 | );
121 | }
122 |
123 | export default Demo;
124 |
--------------------------------------------------------------------------------
/examples/animation.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import '../assets/index.less';
3 | import type { CascaderProps } from '../src';
4 | import Cascader from '../src';
5 | import type { Option2 } from './utils';
6 |
7 | const addressOptions = [
8 | {
9 | label: '福建',
10 | value: 'fj',
11 | children: [
12 | {
13 | label: '福州',
14 | value: 'fuzhou',
15 | children: [
16 | {
17 | label: '马尾',
18 | value: 'mawei',
19 | },
20 | ],
21 | },
22 | {
23 | label: '泉州',
24 | value: 'quanzhou',
25 | },
26 | ],
27 | },
28 | {
29 | label: '浙江',
30 | value: 'zj',
31 | children: [
32 | {
33 | label: '杭州',
34 | value: 'hangzhou',
35 | children: [
36 | {
37 | label: '余杭',
38 | value: 'yuhang',
39 | },
40 | ],
41 | },
42 | ],
43 | },
44 | {
45 | label: '北京',
46 | value: 'bj',
47 | children: [
48 | {
49 | label: '朝阳区',
50 | value: 'chaoyang',
51 | },
52 | {
53 | label: '海淀区',
54 | value: 'haidian',
55 | },
56 | ],
57 | },
58 | ];
59 |
60 | const Demo = () => {
61 | const [inputValue, setInputValue] = useState('');
62 |
63 | const onChange: CascaderProps['onChange'] = (value, selectedOptions) => {
64 | console.log(value, selectedOptions);
65 | setInputValue(selectedOptions.map(o => o.label).join(', '));
66 | };
67 |
68 | return (
69 |
70 |
71 |
72 | );
73 | };
74 |
75 | export default Demo;
76 |
--------------------------------------------------------------------------------
/examples/change-on-select.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import '../assets/index.less';
3 | import type { CascaderProps } from '../src';
4 | import Cascader from '../src';
5 | import type { Option2 } from './utils';
6 |
7 | const options = [
8 | {
9 | label: 'Women Clothing',
10 | value: 'Women Clothing',
11 | children: [
12 | {
13 | label: 'Women Tops, Blouses & Tee',
14 | value: 'Women Tops, Blouses & Tee',
15 | children: [
16 | {
17 | label: 'Women T-Shirts',
18 | value: 'Women T-Shirts',
19 | },
20 | {
21 | label: 'Women Tops',
22 | value: 'Women Tops',
23 | },
24 | {
25 | label: 'Women Tank Tops & Camis',
26 | value: 'Women Tank Tops & Camis',
27 | },
28 | {
29 | label: 'Women Blouses',
30 | value: 'Women Blouses',
31 | },
32 | ],
33 | },
34 | {
35 | label: 'Women Suits',
36 | value: 'Women Suits',
37 | children: [
38 | {
39 | label: 'Women Suit Pants',
40 | value: 'Women Suit Pants',
41 | },
42 | {
43 | label: 'Women Suit Sets',
44 | value: 'Women Suit Sets',
45 | },
46 | {
47 | label: 'Women Blazers',
48 | value: 'Women Blazers',
49 | },
50 | ],
51 | },
52 | {
53 | label: 'Women Co-ords',
54 | value: 'Women Co-ords',
55 | children: [
56 | {
57 | label: 'Two-piece Outfits',
58 | value: 'Two-piece Outfits',
59 | },
60 | ],
61 | },
62 | ],
63 | },
64 | ];
65 |
66 | const onChange: CascaderProps['onChange'] = (value, selectedOptions) => {
67 | console.log(value, selectedOptions);
68 | };
69 |
70 | const Demo = () => (
71 | console.log('loadData')}
78 | />
79 | );
80 |
81 | export default Demo;
82 |
--------------------------------------------------------------------------------
/examples/custom-arrow-icon.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import '../assets/index.less';
3 | import type { CascaderProps } from '../src';
4 | import Cascader from '../src';
5 | import type { Option2 } from './utils';
6 |
7 | const addressOptions: CascaderProps['options'] = [
8 | {
9 | label: '福建',
10 | value: 'fj',
11 | children: [
12 | {
13 | label: '福州',
14 | value: 'fuzhou',
15 | children: [
16 | {
17 | label: '马尾',
18 | value: 'mawei',
19 | },
20 | ],
21 | },
22 | {
23 | label: '泉州',
24 | value: 'quanzhou',
25 | },
26 | ],
27 | },
28 | {
29 | label: '浙江',
30 | value: 'zj',
31 | children: [
32 | {
33 | label: '杭州',
34 | value: 'hangzhou',
35 | children: [
36 | {
37 | label: '余杭',
38 | value: 'yuhang',
39 | },
40 | ],
41 | },
42 | ],
43 | },
44 | {
45 | label: '北京',
46 | value: 'bj',
47 | children: [
48 | {
49 | label: '朝阳区',
50 | value: 'chaoyang',
51 | },
52 | {
53 | label: '海淀区',
54 | value: 'haidian',
55 | disabled: true,
56 | },
57 | ],
58 | },
59 | ];
60 |
61 | const svgPath =
62 | 'M869 487.8L491.2 159.9c-2.9-2.5-6.6-' +
63 | '3.9-10.5-3.9h-88.5c-7.4 0-10.8 9.2-5.2 14l350.2' +
64 | ' 304H152c-4.4 0-8 3.6-8 8v60c0 4.4 ' +
65 | '3.6 8 8 8h585.1L386.9 854c-5.6 4.9-2.2 14 5.2' +
66 | ' 14h91.5c1.9 0 3.8-0.7 5.2-2L869 536.2c14.7-12.8' +
67 | ' 14.7-35.6 0-48.4z';
68 |
69 | const loadingPath =
70 | 'M511.4 124C290.5 124.3 112 303 112' +
71 | ' 523.9c0 128 60.2 242 153.8 315.2l-37.5 48c-4.1 5.3-' +
72 | '0.3 13 6.3 12.9l167-0.8c5.2 0 9-4.9 7.7-9.9L369.8 72' +
73 | '7c-1.6-6.5-10-8.3-14.1-3L315 776.1c-10.2-8-20-16.7-2' +
74 | '9.3-26-29.4-29.4-52.5-63.6-68.6-101.7C200.4 609 192 ' +
75 | '567.1 192 523.9s8.4-85.1 25.1-124.5c16.1-38.1 39.2-7' +
76 | '2.3 68.6-101.7 29.4-29.4 63.6-52.5 101.7-68.6C426.9 ' +
77 | '212.4 468.8 204 512 204s85.1 8.4 124.5 25.1c38.1 16.' +
78 | '1 72.3 39.2 101.7 68.6 29.4 29.4 52.5 63.6 68.6 101.' +
79 | '7 16.7 39.4 25.1 81.3 25.1 124.5s-8.4 85.1-25.1 124.' +
80 | '5c-16.1 38.1-39.2 72.3-68.6 101.7-7.5 7.5-15.3 14.5-' +
81 | '23.4 21.2-3.4 2.8-3.9 7.7-1.2 11.1l39.4 50.5c2.8 3.5' +
82 | ' 7.9 4.1 11.4 1.3C854.5 760.8 912 649.1 912 523.9c0-' +
83 | '221.1-179.4-400.2-400.6-399.9z';
84 |
85 | const Demo = () => {
86 | const [inputValue, setInputValue] = useState('');
87 | const [dynamicInputValue, setDynamicInputValue] = useState('');
88 | const [options, setOptions] = useState([
89 | {
90 | label: '福建',
91 | isLeaf: false,
92 | value: 'fj',
93 | },
94 | {
95 | label: '浙江',
96 | isLeaf: false,
97 | value: 'zj',
98 | },
99 | ]);
100 |
101 | const onChange: CascaderProps['onChange'] = (value, selectedOptions) => {
102 | console.log(value, selectedOptions);
103 | setInputValue(selectedOptions.map(o => o.label).join(', '));
104 | };
105 |
106 | const onChangeDynamic: CascaderProps['onChange'] = (value, selectedOptions) => {
107 | console.log(value, selectedOptions);
108 | setDynamicInputValue(selectedOptions.map(o => o.label).join(', '));
109 | };
110 |
111 | const expandIcon = (
112 |
113 |
125 |
126 | );
127 |
128 | const loadingIcon = (
129 |
136 |
148 |
149 | );
150 |
151 | const loadData: CascaderProps['loadData'] = selectedOptions => {
152 | const targetOption = selectedOptions[selectedOptions.length - 1];
153 | targetOption.loading = true;
154 | // 动态加载下级数据
155 | setTimeout(() => {
156 | targetOption.loading = false;
157 | targetOption.children = [
158 | {
159 | label: `${targetOption.label}动态加载1`,
160 | value: 'dynamic1',
161 | },
162 | {
163 | label: `${targetOption.label}动态加载2`,
164 | value: 'dynamic2',
165 | },
166 | ];
167 | setOptions([...options]);
168 | }, 1500);
169 | };
170 |
171 | return (
172 |
173 |
179 |
180 |
181 |
189 |
190 |
191 |
192 | );
193 | };
194 |
195 | export default Demo;
196 |
--------------------------------------------------------------------------------
/examples/custom-field-name.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import '../assets/index.less';
3 | import type { CascaderProps } from '../src';
4 | import Cascader from '../src';
5 | import type { Option } from './utils';
6 |
7 | const addressOptions: Option[] = [
8 | {
9 | name: '福建',
10 | code: 'fj',
11 | nodes: [
12 | {
13 | name: '福州',
14 | code: 'fuzhou',
15 | nodes: [
16 | {
17 | name: '马尾',
18 | code: 'mawei',
19 | },
20 | ],
21 | },
22 | {
23 | name: '泉州',
24 | code: 'quanzhou',
25 | },
26 | ],
27 | },
28 | {
29 | name: '浙江',
30 | code: 'zj',
31 | nodes: [
32 | {
33 | name: '杭州',
34 | code: 'hangzhou',
35 | nodes: [
36 | {
37 | name: '余杭',
38 | code: 'yuhang',
39 | },
40 | ],
41 | },
42 | ],
43 | },
44 | {
45 | name: '北京',
46 | code: 'bj',
47 | nodes: [
48 | {
49 | name: '朝阳区',
50 | code: 'chaoyang',
51 | },
52 | {
53 | name: '海淀区',
54 | code: 'haidian',
55 | disabled: true,
56 | },
57 | ],
58 | },
59 | ];
60 |
61 | const Demo = () => {
62 | const [inputValue, setInputValue] = useState('');
63 |
64 | const onChange: CascaderProps