Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 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
10 changes: 10 additions & 0 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 [defaultActiveValueCells, setDefaultActiveValueCells] = React.useState<string[]>([]);

return (
<>
<h1>Panel</h1>
Expand All @@ -80,6 +82,13 @@ export default () => {
}}
/>

<button
onClick={() => {
setDefaultActiveValueCells(['bj', 'haidian']);
}}
>
Set defaultActiveValueCells
</button>
<Cascader.Panel
checkable
value={value2}
Expand All @@ -88,6 +97,7 @@ export default () => {
console.log('Change:', nextValue);
setValue2(nextValue);
}}
defaultActiveValueCells={defaultActiveValueCells}
/>

<Cascader.Panel options={addressOptions} direction="rtl" />
Expand Down
2 changes: 2 additions & 0 deletions 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;
defaultActiveValueCells?: React.Key[];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

这个名字改一下?active value cells 是内部命名。如果是要默认展开的话最好是 defaultActiveKey: 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;
defaultActiveValueCells?: React.Key[];
};

export type CascaderRef = Omit<BaseSelectRef, 'scrollTo'>;
Expand Down
10 changes: 8 additions & 2 deletions src/OptionList/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import useKeyboard from './useKeyboard';
export type RawOptionListProps = Pick<
ReturnType<typeof useBaseProps>,
'prefixCls' | 'multiple' | 'searchValue' | 'toggleOpen' | 'notFoundContent' | 'direction' | 'open'
>;
> & { defaultActiveValueCells?: React.Key[]; };

const RawOptionList = React.forwardRef<RefOptionListProps, RawOptionListProps>((props, ref) => {
const { prefixCls, multiple, searchValue, toggleOpen, notFoundContent, direction, open } = props;
const { prefixCls, multiple, searchValue, toggleOpen, notFoundContent, direction, open, defaultActiveValueCells } = props;

const containerRef = React.useRef<HTMLDivElement>(null);
const rtl = direction === 'rtl';
Expand Down Expand Up @@ -99,6 +99,12 @@ const RawOptionList = React.forwardRef<RefOptionListProps, RawOptionListProps>((
internalLoadData(nextValueCells);
};

React.useEffect(() => {
if (defaultActiveValueCells && defaultActiveValueCells?.length > 0) {
setActiveValueCells(defaultActiveValueCells)
}
}, [defaultActiveValueCells]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

不能用 effect,default 就是默认的意思。你如果是 effect 的话,我动态改 defaultActiveKey 这里就会动态的去展开了。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

不能用 effect,default 就是默认的意思。你如果是 effect 的话,我动态改 defaultActiveKey 这里就会动态的去展开了。

已改 0b2c795


const isSelectable = (option: DefaultOptionType) => {
const { disabled } = option;

Expand Down
5 changes: 4 additions & 1 deletion src/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export type PickType =
| 'className'
| 'style'
| 'direction'
| 'notFoundContent';
| 'notFoundContent'
| 'defaultActiveValueCells';

export type PanelProps<
OptionType extends DefaultOptionType = DefaultOptionType,
Expand Down Expand Up @@ -68,6 +69,7 @@ export default function Panel<
loadingIcon,
direction,
notFoundContent = 'Not Found',
defaultActiveValueCells
} = props as Pick<InternalCascaderProps, PickType>;

// ======================== Multiple ========================
Expand Down Expand Up @@ -200,6 +202,7 @@ export default function Panel<
toggleOpen={noop}
open
direction={direction}
defaultActiveValueCells={defaultActiveValueCells}
/>
)}
</div>
Expand Down
13 changes: 13 additions & 0 deletions tests/Panel.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ describe('Cascader.Panel', () => {
expect(onChange).toHaveBeenCalledWith([['bamboo', 'little']], expect.anything());
});

it('multiple with defaultActiveValueCells', () => {
const onChange = jest.fn();
const { container } = render(
<Cascader.Panel
checkable
options={options}
onChange={onChange}
defaultActiveValueCells={['bamboo', 'little']}
/>,
);
expect(container.querySelectorAll('.rc-cascader-menu')).toHaveLength(2);
});

it('rtl', () => {
const { container } = render(<Cascader.Panel options={options} direction="rtl" />);

Expand Down