Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 5 additions & 5 deletions assets/list.less
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
min-height: auto;
}

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

&-menu {
&-holder {
display: flex;
flex-wrap: nowrap;
}

flex: none;
margin: 0;
padding: 0;
Expand Down
5 changes: 5 additions & 0 deletions src/Cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ interface BaseCascaderProps
expandTrigger?: 'hover' | 'click';

dropdownMenuColumnStyle?: React.CSSProperties;
/** @private Internal usage. Do not use in your production. */
dropdownPrefixCls?: string;
loadData?: (selectOptions: DataNode[]) => void;

expandIcon?: React.ReactNode;
Expand Down Expand Up @@ -153,6 +155,7 @@ const Cascader = React.forwardRef((props: CascaderProps, ref: React.Ref<Cascader

loadData,
dropdownMenuColumnStyle,
dropdownPrefixCls,

...restProps
} = props;
Expand Down Expand Up @@ -292,6 +295,7 @@ const Cascader = React.forwardRef((props: CascaderProps, ref: React.Ref<Cascader
loadData,
dropdownMenuColumnStyle,
search: searchConfig,
dropdownPrefixCls,
}),
[
changeOnSelect,
Expand All @@ -302,6 +306,7 @@ const Cascader = React.forwardRef((props: CascaderProps, ref: React.Ref<Cascader
loadData,
dropdownMenuColumnStyle,
searchConfig,
dropdownPrefixCls,
],
);

Expand Down
12 changes: 8 additions & 4 deletions src/OptionList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { isLeaf, restoreCompatibleValue } from '../util';
import CascaderContext from '../context';
import useSearchResult from '../hooks/useSearchResult';

type OptionListProps = SelectOptionListProps<OptionDataNode[]>;
type OptionListProps = SelectOptionListProps<OptionDataNode[]> & { prefixCls: string };
export type FlattenOptions = OptionListProps['flattenOptions'];

const RefOptionList = React.forwardRef<RefOptionListProps, OptionListProps>((props, ref) => {
Expand All @@ -33,9 +33,11 @@ const RefOptionList = React.forwardRef<RefOptionListProps, OptionListProps>((pro
const rtl = direction === 'rtl';

const { checkedKeys, halfCheckedKeys } = React.useContext(SelectContext);
const { changeOnSelect, expandTrigger, fieldNames, loadData, search } =
const { changeOnSelect, expandTrigger, fieldNames, loadData, search, dropdownPrefixCls } =
React.useContext(CascaderContext);

const mergedPrefixCls = dropdownPrefixCls || prefixCls;

// ========================= loadData =========================
const [loadingKeys, setLoadingKeys] = React.useState([]);

Expand Down Expand Up @@ -122,6 +124,7 @@ const RefOptionList = React.forwardRef<RefOptionListProps, OptionListProps>((pro
// ========================== Search ==========================
const searchOptions = useSearchResult({
...props,
prefixCls: mergedPrefixCls,
fieldNames,
changeOnSelect,
searchConfig: search,
Expand Down Expand Up @@ -310,6 +313,7 @@ const RefOptionList = React.forwardRef<RefOptionListProps, OptionListProps>((pro
key={index}
index={index}
{...columnProps}
prefixCls={mergedPrefixCls}
options={col.options}
openKey={openPath[index]}
/>
Expand All @@ -319,8 +323,8 @@ const RefOptionList = React.forwardRef<RefOptionListProps, OptionListProps>((pro
return (
<>
<div
className={classNames(`${prefixCls}-holder`, {
[`${prefixCls}-rtl`]: rtl,
className={classNames(`${mergedPrefixCls}-menu-holder`, {
[`${mergedPrefixCls}-rtl`]: rtl,
})}
>
{columnNodes}
Expand Down
31 changes: 16 additions & 15 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ import * as React from 'react';
import type { CascaderProps } from './Cascader';
import type { ShowSearchType } from './interface';

const CascaderContext = React.createContext<
Required<
Pick<
CascaderProps,
| 'changeOnSelect'
| 'expandTrigger'
| 'fieldNames'
| 'expandIcon'
| 'loadingIcon'
| 'loadData'
| 'dropdownMenuColumnStyle'
> & {
search: ShowSearchType;
}
type ContextProps = Required<
Pick<
CascaderProps,
| 'changeOnSelect'
| 'expandTrigger'
| 'fieldNames'
| 'expandIcon'
| 'loadingIcon'
| 'loadData'
| 'dropdownMenuColumnStyle'
>
>({
> & {
search: ShowSearchType;
dropdownPrefixCls?: string;
};

const CascaderContext = React.createContext<ContextProps>({
changeOnSelect: false,
expandTrigger: 'click',
fieldNames: null,
Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/index.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ exports[`Cascader.Basic should render custom dropdown correctly 1`] = `
class="custom-dropdown"
>
<div
class="rc-cascader-holder"
class="rc-cascader-menu-holder"
>
<ul
class="rc-cascader-menu"
Expand Down
101 changes: 101 additions & 0 deletions tests/__snapshots__/private.spec.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Cascader.Private dropdownPrefixCls 1`] = `
<div
class="bamboo bamboo-single bamboo-show-arrow bamboo-open"
>
<div
class="bamboo-selector"
>
<span
class="bamboo-selection-search"
>
<input
aria-activedescendant="rc_select_TEST_OR_SSR_list_0"
aria-autocomplete="list"
aria-controls="rc_select_TEST_OR_SSR_list"
aria-expanded="true"
aria-haspopup="listbox"
aria-owns="rc_select_TEST_OR_SSR_list"
autocomplete="off"
class="bamboo-selection-search-input"
id="rc_select_TEST_OR_SSR"
readonly=""
role="combobox"
style="opacity: 0;"
type="search"
unselectable="on"
value=""
/>
</span>
<span
class="bamboo-selection-item"
title="Light / Toy"
>
Light / Toy
</span>
</div>
<div>
<div
class="bamboo-dropdown"
style="opacity: 0; pointer-events: none; min-width: auto;"
>
<div>
<div
class="little-menu-holder"
>
<ul
class="little-menu"
role="menu"
>
<li
aria-checked="false"
class="little-menu-item little-menu-item-active"
role="menuitemcheckbox"
title="Light"
>
<div
class="little-menu-item-content"
>
Light
</div>
<div
class="little-menu-item-expand-icon"
>
&gt;
</div>
</li>
</ul>
<ul
class="little-menu"
role="menu"
>
<li
aria-checked="true"
class="little-menu-item little-menu-item-active"
role="menuitemcheckbox"
title="Toy"
>
<div
class="little-menu-item-content"
>
Toy
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
<span
aria-hidden="true"
class="bamboo-arrow"
style="user-select: none;"
unselectable="on"
>
<span
class="bamboo-arrow-icon"
/>
</span>
</div>
`;
32 changes: 32 additions & 0 deletions tests/private.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable @typescript-eslint/consistent-type-imports */

import React from 'react';
import { mount } from './enzyme';
import Cascader from '../src';

describe('Cascader.Private', () => {
it('dropdownPrefixCls', () => {
const wrapper = mount(
<Cascader
defaultValue={['light', 'toy']}
options={[
{
label: 'Light',
value: 'light',
children: [
{
label: 'Toy',
value: 'toy',
},
],
},
]}
open
prefixCls="bamboo"
dropdownPrefixCls="little"
/>,
);

expect(wrapper.render()).toMatchSnapshot();
});
});