Skip to content

Commit

Permalink
[SelectField] First implementation (mui#8023)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari authored Sep 6, 2017
1 parent 0fb26fa commit 50261b9
Show file tree
Hide file tree
Showing 93 changed files with 1,598 additions and 238 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
command: yarn size
- run:
name: Can we generate the docs?
command: yarn docs:build
command: yarn docs:api && yarn docs:build
test_browser:
<<: *defaults
steps:
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/demos/dialogs/ConfirmationDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const styles = theme => ({

class ConfirmationDialogDemo extends React.Component {
state = {
anchorEl: undefined,
anchorEl: null,
open: false,
value: 'Dione',
};
Expand Down
6 changes: 3 additions & 3 deletions docs/src/pages/demos/menus/LongMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ITEM_HEIGHT = 48;

class LongMenu extends React.Component {
state = {
anchorEl: undefined,
anchorEl: null,
open: false,
};

Expand Down Expand Up @@ -54,9 +54,9 @@ class LongMenu extends React.Component {
anchorEl={this.state.anchorEl}
open={this.state.open}
onRequestClose={this.handleRequestClose}
style={{ maxHeight: ITEM_HEIGHT * 4.5 }}
MenuListProps={{
PaperProps={{
style: {
maxHeight: ITEM_HEIGHT * 4.5,
width: 200,
},
}}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/demos/menus/SimpleListMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const options = [

class SimpleListMenu extends React.Component {
state = {
anchorEl: undefined,
anchorEl: null,
open: false,
selectedIndex: 1,
};
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/demos/menus/SimpleMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Menu, { MenuItem } from 'material-ui/Menu';

class SimpleMenu extends React.Component {
state = {
anchorEl: undefined,
anchorEl: null,
open: false,
};

Expand Down
4 changes: 0 additions & 4 deletions docs/src/pages/demos/menus/menus.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,3 @@ If text in a simple menu wraps to a second line, use a simple dialog instead. Si
If the height of a menu prevents all menu items from being displayed, the menu can scroll internally.

{{demo='pages/demos/menus/LongMenu.js'}}

## TextField select menus

Coming soon...
91 changes: 91 additions & 0 deletions docs/src/pages/demos/selects/MultipleSelect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* eslint-disable flowtype/require-valid-file-annotation */

import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from 'material-ui/styles';
import Input, { InputLabel } from 'material-ui/Input';
import { MenuItem } from 'material-ui/Menu';
import { FormControl } from 'material-ui/Form';
import Select from 'material-ui/Select';

const styles = theme => ({
container: {
display: 'flex',
flexWrap: 'wrap',
},
formControl: {
margin: theme.spacing.unit,
minWidth: 120,
maxWidth: 300,
},
});

const ITEM_HEIGHT = 48;
const ITEM_PADDING_TOP = 8;

const names = [
'Oliver Hansen',
'Van Henry',
'April Tucker',
'Ralph Hubbard',
'Omar Alexander',
'Carlos Abbott',
'Miriam Wagner',
'Bradley Wilkerson',
'Virginia Andrews',
'Kelly Snyder',
];

class MultipleSelect extends React.Component {
state = {
name: [],
};

handleChange = event => {
this.setState({ name: event.target.value });
};

render() {
const classes = this.props.classes;

return (
<div className={classes.container}>
<FormControl className={classes.formControl}>
<InputLabel htmlFor="name-multiple">Name</InputLabel>
<Select
multiple
value={this.state.name}
onChange={this.handleChange}
input={<Input id="name-multiple" />}
MenuProps={{
PaperProps: {
style: {
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
width: 200,
},
},
}}
>
{names.map(name => (
<MenuItem
key={name}
value={name}
style={{
fontWeight: this.state.name.indexOf(name) !== -1 ? '500' : '400',
}}
>
{name}
</MenuItem>
))}
</Select>
</FormControl>
</div>
);
}
}

MultipleSelect.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(MultipleSelect);
127 changes: 127 additions & 0 deletions docs/src/pages/demos/selects/NativeSelect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/* eslint-disable flowtype/require-valid-file-annotation */

import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from 'material-ui/styles';
import Input, { InputLabel } from 'material-ui/Input';
import { FormControl, FormHelperText } from 'material-ui/Form';
import Select from 'material-ui/Select';

const styles = theme => ({
container: {
display: 'flex',
flexWrap: 'wrap',
},
formControl: {
margin: theme.spacing.unit,
minWidth: 120,
},
});

class NativeSelect extends React.Component {
state = {
age: '',
name: 'hai',
};

handleChange = name => event => {
this.setState({ [name]: event.target.value });
};

render() {
const classes = this.props.classes;

return (
<div className={classes.container}>
<FormControl className={classes.formControl}>
<InputLabel htmlFor="age-native-simple">Age</InputLabel>
<Select
native
value={this.state.age}
onChange={this.handleChange('age')}
input={<Input id="age-native-simple" />}
>
<option value="" />
<option value={10}>Ten</option>
<option value={20}>Twenty</option>
<option value={30}>Thirty</option>
</Select>
</FormControl>
<FormControl className={classes.formControl}>
<InputLabel htmlFor="age-native-helper">Age</InputLabel>
<Select
native
value={this.state.age}
onChange={this.handleChange('age')}
input={<Input id="age-native-helper" />}
>
<option value="" />
<option value={10}>Ten</option>
<option value={20}>Twenty</option>
<option value={30}>Thirty</option>
</Select>
<FormHelperText>Some important helper text</FormHelperText>
</FormControl>
<FormControl className={classes.formControl} disabled>
<InputLabel htmlFor="name-native-disabled">Name</InputLabel>
<Select
native
value={this.state.name}
onChange={this.handleChange('name')}
input={<Input id="name-native-disabled" />}
>
<option value="" />
<optgroup label="Author">
<option value="hai">Hai</option>
</optgroup>
<optgroup label="Contributors">
<option value="olivier">Olivier</option>
<option value="kevin">Kevin</option>
</optgroup>
</Select>
<FormHelperText>Disabled</FormHelperText>
</FormControl>
<FormControl className={classes.formControl} error>
<InputLabel htmlFor="name-native-error">Name</InputLabel>
<Select
native
value={this.state.name}
onChange={this.handleChange('name')}
input={<Input id="name-native-error" />}
>
<option value="" />
<optgroup label="Author">
<option value="hai">Hai</option>
</optgroup>
<optgroup label="Contributors">
<option value="olivier">Olivier</option>
<option value="kevin">Kevin</option>
</optgroup>
</Select>
<FormHelperText>Error</FormHelperText>
</FormControl>
<FormControl className={classes.formControl}>
<InputLabel htmlFor="name-input">Name</InputLabel>
<Input id="name-input" />
<FormHelperText>Alignement with an input</FormHelperText>
</FormControl>
<FormControl className={classes.formControl}>
<InputLabel htmlFor="uncontrolled-native">Name</InputLabel>
<Select native defaultValue={30} input={<Input id="uncontrolled-native" />}>
<option value="" />
<option value={10}>Ten</option>
<option value={20}>Twenty</option>
<option value={30}>Thirty</option>
</Select>
<FormHelperText>Uncontrolled</FormHelperText>
</FormControl>
</div>
);
}
}

NativeSelect.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(NativeSelect);
Loading

0 comments on commit 50261b9

Please sign in to comment.