react-toolbox/react-toolbox

required attribute not functioning for Dropdown

Open

#1,789 建立於 2018年1月18日

在 GitHub 查看
 (4 留言) (0 反應) (0 負責人)JavaScript (8,676 star) (1,036 fork)batch import
Type: Buggood first issue

描述

I'm using 2.0.0-beta.12 and I've noticed that the required attribute does not function as expected:

class DropdownTest extends React.Component {
  state = { value: null }

  handleChange = (value) => {
    this.setState({value: value})
  }

  render() {
    return (
      <Dropdown
        required
        onChange={this.handleChange}
        source={[{value: 1, label: 'option 1' }, {value: 2, label: 'option 2' }]}
        value={this.state.value}
      />
    )
  }
}

const Form = () => (
  <form>
    <DropdownTest />
    <Button type="submit" raised primary>Submit</Button>
  </form>
)

In this example, the submit button still executes the default submit function. I was able to use the Input component with the required attribute and get the desired functionality.

貢獻者指南