Skip to content

Commit

Permalink
feat: Cascader component value support number type (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
Loogeek authored May 17, 2020
1 parent 03c9b9b commit 557aecb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 10 additions & 8 deletions src/Cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import Menus from './Menus';
import BUILT_IN_PLACEMENTS from './placements';

export interface CascaderFieldNames {
value?: string;
value?: string | number;
label?: string;
children?: string;
}

export type CascaderValueType = (string | number)[];

export interface CascaderOption {
value?: string;
value?: string | number;
label?: React.ReactNode;
disabled?: boolean;
isLeaf?: boolean;
Expand All @@ -24,10 +26,10 @@ export interface CascaderOption {
}

export interface CascaderProps extends Pick<TriggerProps, 'getPopupContainer'> {
value?: string[];
defaultValue?: string[];
value?: CascaderValueType;
defaultValue?: CascaderValueType;
options?: CascaderOption[];
onChange?: (value: string[], selectOptions: CascaderOption[]) => void;
onChange?: (value: CascaderValueType, selectOptions: CascaderOption[]) => void;
onPopupVisibleChange?: (popupVisible: boolean) => void;
popupVisible?: boolean;
disabled?: boolean;
Expand All @@ -50,8 +52,8 @@ export interface CascaderProps extends Pick<TriggerProps, 'getPopupContainer'> {

interface CascaderState {
popupVisible?: boolean;
activeValue?: string[];
value?: string[];
activeValue?: CascaderValueType;
value?: CascaderValueType;
prevProps?: CascaderProps;
}

Expand Down Expand Up @@ -158,7 +160,7 @@ class Cascader extends React.Component<CascaderProps, CascaderState> {
return [...options].filter(o => !o.disabled);
}

getActiveOptions(activeValue: string[]): CascaderOption[] {
getActiveOptions(activeValue: CascaderValueType): CascaderOption[] {
return arrayTreeFilter(
this.props.options || [],
(o, level) => o[this.getFieldName('value')] === activeValue[level],
Expand Down
4 changes: 2 additions & 2 deletions src/Menus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import arrayTreeFilter from 'array-tree-filter';
import { CascaderOption, CascaderFieldNames } from './Cascader';

interface MenusProps {
value?: string[];
activeValue?: string[];
value?: (string | number)[];
activeValue?: (string | number)[];
options?: CascaderOption[];
prefixCls?: string;
expandTrigger?: string;
Expand Down

0 comments on commit 557aecb

Please sign in to comment.