Skip to content

Commit

Permalink
chore(SelectCascader): majorization SelectCascader
Browse files Browse the repository at this point in the history
  • Loading branch information
cuilanxin committed Oct 11, 2021
1 parent b5ed8db commit f7d3bf0
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions packages/core/src/SelectCascader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export interface SelectCascaderProps {

export interface Istate {
value: SelectCascaderValue;
modalVisible: boolean;
controlVisible: 'state' | 'props';
}

export default class SelectCascader extends Component<SelectCascaderProps, Istate> {
Expand All @@ -46,14 +48,26 @@ export default class SelectCascader extends Component<SelectCascaderProps, Istat
cols: 3,
maskClosable: true,
};
state = {
state: Istate = {
value: new Array<SelectCascaderOneValue>(),
modalVisible: this.props.visible,
controlVisible: 'props',
};

static getDerivedStateFromProps(props: SelectCascaderProps, state: Istate) {
if (JSON.stringify(props.value) === JSON.stringify(state.value)) {
if (
JSON.stringify(props.value) === JSON.stringify(state.value) &&
state.controlVisible === 'props' &&
state.modalVisible === props.visible
) {
return null;
}
if (JSON.stringify(props.value) === JSON.stringify(state.value)) {
return {
modalVisible: state.controlVisible === 'props' ? props.visible : state.modalVisible,
controlVisible: 'props',
};
}
const getValue = (d: ICascaderDataItem[], val: SelectCascaderValue | undefined) => {
let data = d || props.data;
let value = val || props.value || props.defaultValue;
Expand All @@ -70,8 +84,19 @@ export default class SelectCascader extends Component<SelectCascaderProps, Istat
}
return value;
};
if (
JSON.stringify(props.value) !== JSON.stringify(state.value) &&
state.controlVisible === 'props' &&
state.modalVisible === props.visible
) {
return {
value: getValue(props.data, props.value),
};
}
return {
value: getValue(props.data, props.value),
modalVisible: state.controlVisible === 'props' ? props.visible : state.modalVisible,
controlVisible: 'props',
};
}

Expand Down Expand Up @@ -157,9 +182,9 @@ export default class SelectCascader extends Component<SelectCascaderProps, Istat
const cols = this.getCols();
return (
<Modal
visible={visible}
visible={this.state.modalVisible}
onClosed={() => {
maskClosable && this.props.onDismiss?.();
maskClosable && this.setState({ modalVisible: false, controlVisible: 'state' });
}}
>
<>
Expand Down

0 comments on commit f7d3bf0

Please sign in to comment.