Skip to content

Commit

Permalink
docs(Dropdown): add dedicated example for controlled Dropdown (#2251)
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter authored Oct 25, 2017
1 parent 5841dd7 commit 28c8af9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { Component } from 'react'
import { Dropdown, Grid, Segment } from 'semantic-ui-react'

const options = [
{ key: 1, text: 'One', value: 1 },
{ key: 2, text: 'Two', value: 2 },
{ key: 3, text: 'Three', value: 3 },
]

export default class DropdownExampleControlled extends Component {
state = {}

handleChange = (e, { value }) => this.setState({ value })

render() {
const { value } = this.state

return (
<Grid columns={2}>
<Grid.Column>
<Dropdown
onChange={this.handleChange}
options={options}
placeholder='Choose an option'
selection
value={value}
/>
</Grid.Column>
<Grid.Column>
<Segment secondary>
<pre>Current value: {value}</pre>
</Segment>
</Grid.Column>
</Grid>
)
}
}
6 changes: 5 additions & 1 deletion docs/app/Examples/modules/Dropdown/Usage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ const DropdownUsageExamples = () => (
description='A dropdown can choose whether or not to change the value when navigating the menu with arrow keys.'
examplePath='modules/Dropdown/Usage/DropdownExampleSelectOnNavigation'
/>

<ComponentExample
title='Controlled'
description='A dropdown can behave like an controlled input.'
examplePath='modules/Dropdown/Usage/DropdownExampleControlled'
/>
<ComponentExample
title='Uncontrolled'
description='A dropdown can behave like an uncontrolled input.'
Expand Down

0 comments on commit 28c8af9

Please sign in to comment.