Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(Dropdown): add dedicated example for controlled Dropdown #2251

Merged
merged 1 commit into from
Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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