Skip to content

Commit f7d3bf0

Browse files
committed
chore(SelectCascader): majorization SelectCascader
1 parent b5ed8db commit f7d3bf0

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

packages/core/src/SelectCascader/index.tsx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export interface SelectCascaderProps {
3535

3636
export interface Istate {
3737
value: SelectCascaderValue;
38+
modalVisible: boolean;
39+
controlVisible: 'state' | 'props';
3840
}
3941

4042
export default class SelectCascader extends Component<SelectCascaderProps, Istate> {
@@ -46,14 +48,26 @@ export default class SelectCascader extends Component<SelectCascaderProps, Istat
4648
cols: 3,
4749
maskClosable: true,
4850
};
49-
state = {
51+
state: Istate = {
5052
value: new Array<SelectCascaderOneValue>(),
53+
modalVisible: this.props.visible,
54+
controlVisible: 'props',
5155
};
5256

5357
static getDerivedStateFromProps(props: SelectCascaderProps, state: Istate) {
54-
if (JSON.stringify(props.value) === JSON.stringify(state.value)) {
58+
if (
59+
JSON.stringify(props.value) === JSON.stringify(state.value) &&
60+
state.controlVisible === 'props' &&
61+
state.modalVisible === props.visible
62+
) {
5563
return null;
5664
}
65+
if (JSON.stringify(props.value) === JSON.stringify(state.value)) {
66+
return {
67+
modalVisible: state.controlVisible === 'props' ? props.visible : state.modalVisible,
68+
controlVisible: 'props',
69+
};
70+
}
5771
const getValue = (d: ICascaderDataItem[], val: SelectCascaderValue | undefined) => {
5872
let data = d || props.data;
5973
let value = val || props.value || props.defaultValue;
@@ -70,8 +84,19 @@ export default class SelectCascader extends Component<SelectCascaderProps, Istat
7084
}
7185
return value;
7286
};
87+
if (
88+
JSON.stringify(props.value) !== JSON.stringify(state.value) &&
89+
state.controlVisible === 'props' &&
90+
state.modalVisible === props.visible
91+
) {
92+
return {
93+
value: getValue(props.data, props.value),
94+
};
95+
}
7396
return {
7497
value: getValue(props.data, props.value),
98+
modalVisible: state.controlVisible === 'props' ? props.visible : state.modalVisible,
99+
controlVisible: 'props',
75100
};
76101
}
77102

@@ -157,9 +182,9 @@ export default class SelectCascader extends Component<SelectCascaderProps, Istat
157182
const cols = this.getCols();
158183
return (
159184
<Modal
160-
visible={visible}
185+
visible={this.state.modalVisible}
161186
onClosed={() => {
162-
maskClosable && this.props.onDismiss?.();
187+
maskClosable && this.setState({ modalVisible: false, controlVisible: 'state' });
163188
}}
164189
>
165190
<>

0 commit comments

Comments
 (0)