Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Cascader.Panel support default expand cells #515

Closed
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
bf253d7
feat: Cascader.Panel support default expand cells
lihongxiangfrontend Jul 10, 2024
f18f6f3
fix: 修复Panel 单测报错
lihongxiangfrontend Jul 10, 2024
99e1125
refactor: panel demo support defaultActiveValueCells
lihongxiangfrontend Jul 11, 2024
fdcadbb
fix: remove redundance dependency
lihongxiangfrontend Jul 11, 2024
fc2bc36
test: 补齐 Panel multiple with defaultActiveValueCells test suites
lihongxiangfrontend Jul 11, 2024
5966e56
refactor: panel demo add a button for setDefaultActiveValueCells
lihongxiangfrontend Jul 11, 2024
cecd044
test: use codecov/codecov-action (#524)
Layouwen Aug 15, 2024
b854548
test: use unified github action yml (#528)
Layouwen Aug 24, 2024
6765c25
feat: optimize search (#530)
crazyair Sep 2, 2024
a438e92
feat: test (#531)
crazyair Sep 2, 2024
a75df6f
3.27.1
zombieJ Sep 2, 2024
7ed02d2
chore: bump tree (#534)
zombieJ Sep 3, 2024
7dc164c
3.28.0
zombieJ Sep 3, 2024
ce2e86e
fix: search no scroll (#532)
crazyair Sep 3, 2024
273f613
3.28.1
afc163 Sep 3, 2024
2ad949e
Create FUNDING.yml
afc163 Sep 20, 2024
e1a0426
fix: antd-issue-51248 (#541)
dongbanban Oct 16, 2024
0d4290e
3.28.2
zombieJ Oct 16, 2024
67cef8a
chore: upgrade deps (#542)
afc163 Oct 16, 2024
07f5596
3.29.0
afc163 Oct 16, 2024
6c5c1c5
update README
afc163 Oct 22, 2024
3f03912
chore: move array-tree-filter to devDeps (#544)
afc163 Oct 22, 2024
f0c9f4c
3.29.1
afc163 Oct 22, 2024
0b2c795
refactor: Panel 默认展开属性重命名 & 移除在effect中使用 defaultActiveKey
lihongxiangfrontend Oct 25, 2024
e83b662
feat: add disabled api for panel (#543)
aojunhao123 Oct 29, 2024
be8679f
3.30.0
zombieJ Oct 29, 2024
bee7389
feat: Cascader.Panel support default expand cells
lihongxiangfrontend Jul 10, 2024
fa3d22e
refactor: panel demo support defaultActiveValueCells
lihongxiangfrontend Jul 11, 2024
7c7f117
refactor: Panel 默认展开属性重命名 & 移除在effect中使用 defaultActiveKey
lihongxiangfrontend Oct 25, 2024
5e15a6c
fix: 删除defaultActiveKey多余声明
lihongxiangfrontend Nov 19, 2024
19823ee
fix: 删除重复声明
lihongxiangfrontend Nov 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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']
117 changes: 5 additions & 112 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,113 +1,6 @@
name: CI

on:
push:
branches: [master]
pull_request:

name: ✅ test
on: [push, pull_request]
jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master

- uses: actions/setup-node@v1
with:
node-version: '16'

- name: cache package-lock.json
uses: actions/cache@v2
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: create package-lock.json
run: npm i --package-lock-only

- name: hack for singe file
run: |
if [ ! -d "package-temp-dir" ]; then
mkdir package-temp-dir
fi
cp package-lock.json package-temp-dir
- name: cache node_modules
id: node_modules_cache_id
uses: actions/cache@v2
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}

- name: install
if: steps.node_modules_cache_id.outputs.cache-hit != 'true'
run: npm ci

lint:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master

- name: restore cache from package-lock.json
uses: actions/cache@v2
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: restore cache from node_modules
uses: actions/cache@v2
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}

- name: lint
run: npm run lint

needs: setup

compile:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master

- name: restore cache from package-lock.json
uses: actions/cache@v2
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: restore cache from node_modules
uses: actions/cache@v2
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}

- name: compile
run: npm run compile

needs: setup

coverage:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master

- name: restore cache from package-lock.json
uses: actions/cache@v2
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: restore cache from node_modules
uses: actions/cache@v2
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
- name: tsc
run: npm run lint:tsc
- name: coverage
run: npm test -- --coverage && bash <(curl -s https://codecov.io/bash)

needs: setup
test:
uses: react-component/rc-test/.github/workflows/test.yml@main
secrets: inherit
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ coverage
.dumi/tmp
.dumi/tmp-production
dist
.vscode
.vscode

bun.lockb
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# rc-cascader

React Cascader Component
React Cascader Component.

[![NPM version][npm-image]][npm-url]
[![npm download][download-image]][download-url]
Expand Down
2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[install]
peer = false
8 changes: 8 additions & 0 deletions docs/demo/multiple-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: multiple-search
nav:
title: Demo
path: /demo
---

<code src="../../examples/multiple-search.tsx"></code>
48 changes: 48 additions & 0 deletions examples/multiple-search.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';
import '../assets/index.less';
import Cascader from '../src';
Comment on lines +1 to +3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

建议使用路径别名优化导入语句

当前的相对路径导入方式可能会在项目结构变化时造成维护困难。建议配置 TypeScript 的 path aliases,使用 @ 或类似的别名来简化导入路径。

例如:

-import '../assets/index.less';
-import Cascader from '../src';
+import '@/assets/index.less';
+import Cascader from '@/src';

Committable suggestion was skipped due to low confidence.


const options = [
{
value: 'zhejiang',
label: 'Zhejiang',
children: [
{
value: 'hangzhou',
label: 'Hangzhou',
children: [
{
value: 'xihu',
label: 'West Lake',
},
{
value: 'xiasha',
label: 'Xia Sha',
},
],
},
],
},
{
value: 'jiangsu',
label: 'Jiangsu',
children: [
{
value: 'nanjing',
label: 'Nanjing',
children: [
{
value: 'zhonghuamen',
label: 'Zhong Hua men',
},
],
},
],
},
];
Comment on lines +5 to +42
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

建议添加类型定义并分离数据

  1. 建议为选项数据添加 TypeScript 接口定义,提高代码的类型安全性:
interface CascaderOption {
  value: string;
  label: string;
  children?: CascaderOption[];
}
  1. 建议将模拟数据移至单独的文件(如 mock/cascaderData.ts),以提高代码的可维护性和复用性。


const Demo = () => {
return <Cascader checkable showSearch options={options} />;
};

export default Demo;
20 changes: 17 additions & 3 deletions examples/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export default () => {

const [value2, setValue2] = React.useState<string[][]>([]);

const [disabled, setDisabled] = React.useState(false);

return (
<>
<h1>Panel</h1>
Expand All @@ -71,26 +73,38 @@ export default () => {
>
Set Value
</button>
<button
onClick={() => {
setDisabled(prev => !prev);
}}
>
{disabled ? 'enable panel' : 'disable panel'}
</button>
<Cascader.Panel
value={value}
options={addressOptions}
onChange={nextValue => {
console.log('Change:', nextValue);
setValue(nextValue);
}}
disabled={disabled}
/>

<div>defaultActiveKey=[bj, haidian]</div>
<Cascader.Panel
checkable
value={value2}
options={addressOptions}
onChange={nextValue => {
console.log('Change:', nextValue);
setValue2(nextValue);
console.log('Change:', nextValue);
setValue2(nextValue);
}}
defaultActiveKey={['bj', 'haidian']}
disabled={disabled}
defaultActiveKey={['bj', 'haidian']}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

发现重复的属性设置

defaultActiveKey 属性在组件中被重复定义了两次,这可能会导致意外的行为。

建议移除重复的属性:

  <Cascader.Panel
    checkable
    value={value2}
    options={addressOptions}
    onChange={nextValue => {
      console.log('Change:', nextValue);
      setValue2(nextValue);
    }}
    defaultActiveKey={['bj', 'haidian']}
    disabled={disabled}
-   defaultActiveKey={['bj', 'haidian']}
  />

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 Biome

[error] 103-104: This JSX property is assigned multiple times.

This attribute is assigned again here.

(lint/suspicious/noDuplicateJsxProps)

🪛 eslint

[error] 104-104: No duplicate props allowed

(react/jsx-no-duplicate-props)

/>

<Cascader.Panel options={addressOptions} direction="rtl" />
<Cascader.Panel options={addressOptions} disabled={disabled} direction="rtl" />

<Cascader.Panel notFoundContent="Empty!!!" />
</>
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-cascader",
"version": "3.27.0",
"version": "3.30.0",
"description": "cascade select ui component for react",
"keywords": [
"react",
Expand Down Expand Up @@ -42,12 +42,11 @@
"test": "rc-test"
},
"dependencies": {
"@babel/runtime": "^7.12.5",
"array-tree-filter": "^2.1.0",
"@babel/runtime": "^7.25.7",
"classnames": "^2.3.1",
"rc-select": "~14.15.0",
"rc-tree": "~5.8.1",
"rc-util": "^5.37.0"
"rc-select": "~14.16.2",
"rc-tree": "~5.10.1",
"rc-util": "^5.43.0"
},
"devDependencies": {
"@rc-component/father-plugin": "^1.0.0",
Expand All @@ -60,6 +59,8 @@
"@types/react-dom": "^18.0.11",
"@types/warning": "^3.0.0",
"@umijs/fabric": "^4.0.0",
"array-tree-filter": "^3.0.2",
"cheerio": "1.0.0-rc.12",
"cross-env": "^7.0.0",
"dumi": "^2.1.10",
"enzyme": "^3.3.0",
Expand Down
4 changes: 3 additions & 1 deletion src/Cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export interface CascaderProps<
value: GetValueType<OptionType, ValueField, Multiple>,
selectOptions: OptionType[],
) => void;
defaultActiveKey?: React.Key[];
}

export type SingleValueType = (string | number)[];
Expand All @@ -175,6 +176,7 @@ export type InternalCascaderProps = Omit<CascaderProps, 'onChange' | 'value' | '
value: InternalValueType,
selectOptions: BaseOptionType[] | BaseOptionType[][],
) => void;
defaultActiveKey?: React.Key[];
};

export type CascaderRef = Omit<BaseSelectRef, 'scrollTo'>;
Expand Down Expand Up @@ -280,7 +282,7 @@ const Cascader = React.forwardRef<CascaderRef, InternalCascaderProps>((props, re
mergedFieldNames,
dropdownPrefixCls || prefixCls,
searchConfig,
changeOnSelect,
changeOnSelect || multiple,
);

// =========================== Values ===========================
Expand Down
14 changes: 8 additions & 6 deletions src/OptionList/Column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface ColumnProps<OptionType extends DefaultOptionType = DefaultOptio
halfCheckedSet: Set<React.Key>;
loadingKeys: React.Key[];
isSelectable: (option: DefaultOptionType) => boolean;
searchValue?: string;
disabled?: boolean;
}

export default function Column<OptionType extends DefaultOptionType = DefaultOptionType>({
Expand All @@ -39,7 +39,7 @@ export default function Column<OptionType extends DefaultOptionType = DefaultOpt
halfCheckedSet,
loadingKeys,
isSelectable,
searchValue,
disabled: propsDisabled,
}: ColumnProps<OptionType>) {
const menuPrefixCls = `${prefixCls}-menu`;
const menuItemPrefixCls = `${prefixCls}-menu-item`;
Expand All @@ -56,6 +56,8 @@ export default function Column<OptionType extends DefaultOptionType = DefaultOpt

const hoverOpen = expandTrigger === 'hover';

const isOptionDisabled = (disabled?: boolean) => propsDisabled || disabled;

// ============================ Option ============================
const optionInfoList = React.useMemo(
() =>
Expand Down Expand Up @@ -117,7 +119,7 @@ export default function Column<OptionType extends DefaultOptionType = DefaultOpt
}) => {
// >>>>> Open
const triggerOpenPath = () => {
if (disabled || searchValue) {
if (isOptionDisabled(disabled)) {
return;
}
const nextValueCells = [...fullPath];
Expand All @@ -129,7 +131,7 @@ export default function Column<OptionType extends DefaultOptionType = DefaultOpt

// >>>>> Selection
const triggerSelect = () => {
if (isSelectable(option)) {
if (isSelectable(option) && !isOptionDisabled(disabled)) {
onSelect(fullPath, isMergedLeaf);
}
};
Expand All @@ -150,7 +152,7 @@ export default function Column<OptionType extends DefaultOptionType = DefaultOpt
[`${menuItemPrefixCls}-expand`]: !isMergedLeaf,
[`${menuItemPrefixCls}-active`]:
activeValue === value || activeValue === fullPathKey,
[`${menuItemPrefixCls}-disabled`]: disabled,
[`${menuItemPrefixCls}-disabled`]: isOptionDisabled(disabled),
[`${menuItemPrefixCls}-loading`]: isLoading,
})}
style={dropdownMenuColumnStyle}
Expand Down Expand Up @@ -187,7 +189,7 @@ export default function Column<OptionType extends DefaultOptionType = DefaultOpt
prefixCls={`${prefixCls}-checkbox`}
checked={checked}
halfChecked={halfChecked}
disabled={disabled || disableCheckbox}
disabled={isOptionDisabled(disabled) || disableCheckbox}
disableCheckbox={disableCheckbox}
onClick={(e: React.MouseEvent<HTMLSpanElement>) => {
if (disableCheckbox) {
Expand Down
Loading