Skip to content

Commit

Permalink
Picker.Stack API调整
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeLin committed Aug 15, 2017
1 parent 6817932 commit 52868b9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
30 changes: 17 additions & 13 deletions components/Picker/StackPicker.jsx
Expand Up @@ -12,15 +12,13 @@ class PickerStack extends Component {

constructor(props) {
super(props);

const resolvedProps = this.resolveProps(props, props.value); // 解决 value PropType定义的eslint报错

this.columns = {};

this.state = {
visible: false,
...resolvedProps,
...this.resolveProps(props, props.value),
};
this.onMaskClick = this.onMaskClick.bind(this);
this.onCancel = this.onCancel.bind(this);
}

componentDidMount() {
Expand Down Expand Up @@ -59,7 +57,6 @@ class PickerStack extends Component {

obtainItem(list, value) {
const { valueMember } = this.props;

return list.filter(item => item[valueMember] === value)[0];
}

Expand All @@ -69,7 +66,6 @@ class PickerStack extends Component {
let errorMsg = null;

cVal && (value[index] = cVal);

errorMsg = validate(value);

if (isLast && !errorMsg) {
Expand All @@ -90,18 +86,26 @@ class PickerStack extends Component {
}

close(isCancel) {
const { onCancel } = this.props;

this.setState({ visible: false });

if (isCancel) {
this.setState({
value: [...this.state.displayValue],
});
onCancel();
}
}

onMaskClick() {
const { onMaskClick } = this.props;
this.close(true);
onMaskClick && onMaskClick();
}

onCancel() {
const { onCancel } = this.props;
this.close(true);
onCancel && onCancel();
}

reposition() {
const { dataSource, valueMember, disabled, displayItems, itemHeight, cols } = this.props;

Expand Down Expand Up @@ -215,10 +219,10 @@ class PickerStack extends Component {
<div className={wrapperCls} onClick={stopEventPropagation}>
<Popup
visible={visible}
onMaskClick={() => this.close(true)}>
onMaskClick={this.onMaskClick}>
<div className={`${prefixCls}-wrapper`}>
<div className={`${prefixCls}-header`}>
<div className={`${prefixCls}-cancel`} onClick={() => this.close(true)}>取消</div>
<div className={`${prefixCls}-cancel`} onClick={this.onCancel}>取消</div>
<div className={`${prefixCls}-title`}>{ title }</div>
<div className={`${prefixCls}-submit`} />
</div>
Expand Down
1 change: 0 additions & 1 deletion examples/pages/PickerPage.jsx
Expand Up @@ -235,7 +235,6 @@ class Page extends Component {
<Picker.Stack
dataSource={District}
displayRender={selected => selected.map(item => item.label).join('-')}
onOk={() => {}}
/>
</Cell>

Expand Down

0 comments on commit 52868b9

Please sign in to comment.