Skip to content

Commit e12da68

Browse files
committed
fix:pull master
2 parents c539b90 + f7d3bf0 commit e12da68

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

packages/core/src/SelectCascader/index.tsx

Lines changed: 30 additions & 22 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 = {
50-
value: this.getValue(this.props.data, this.props.defaultValue || this.props.value),
51+
state: Istate = {
52+
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

@@ -110,23 +135,6 @@ export default class SelectCascader extends Component<SelectCascaderProps, Istat
110135
}
111136
};
112137

113-
getValue(d: ICascaderDataItem[], val: SelectCascaderValue | undefined) {
114-
let data = d || this.props.data;
115-
let value = val || this.props.value || this.props.defaultValue;
116-
if (!value || !value.length || value.indexOf(undefined) > -1) {
117-
value = [];
118-
for (let i = 0; i < this.props.cols!; i++) {
119-
if (data && data.length) {
120-
value[i] = data[0].value;
121-
if (data[0].children) {
122-
data = data[0].children;
123-
}
124-
}
125-
}
126-
}
127-
return value;
128-
}
129-
130138
getCols = () => {
131139
const { data, cols, pickerItemStyle } = this.props;
132140
const { value } = this.state;
@@ -174,9 +182,9 @@ export default class SelectCascader extends Component<SelectCascaderProps, Istat
174182
const cols = this.getCols();
175183
return (
176184
<Modal
177-
visible={visible}
185+
visible={this.state.modalVisible}
178186
onClosed={() => {
179-
maskClosable && this.props.onDismiss?.();
187+
maskClosable && this.setState({ modalVisible: false, controlVisible: 'state' });
180188
}}
181189
>
182190
<>

0 commit comments

Comments
 (0)