react-component / m-picker

React Mobile Picker(web & react-native)

Home Page:http://react-component.github.io/m-picker/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MultiPicker logic incorrect, when not set selectedValue.

zhang740 opened this issue · comments

If not set selectedValue, is no has event fire when reselect the first item.

core code:

MultiPicker.tsx:

    const selectedValue = this.getValue();
    const colElements = React.Children.map(children, (col: any, i) => {
      return React.cloneElement(col, {
        selectedValue: selectedValue[i],
        onValueChange: (...args) => this.onValueChange(i, ...args),
      });
    });

the getValue implement in MultiPickerMixin.tsx:

  getValue() {
    const { children, selectedValue } = this.props;
    if (selectedValue && selectedValue.length) {
      return selectedValue;
    } else {
      if (!children) {
        return [];
      }
      return React.Children.map(children, (c: any) => {
        const cc: any = React.Children.toArray(c.props.children);
        return cc && cc[0] && cc[0].props.value;
      });
    }
  },

If not set selectedValue, the result of getValue() alway equel the first item's value of picker's children of multipicker.

What's your problem?

Can you give a reproducible demo?

selectedValue is required for MultiPicker.