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

[Tabs][BottomNavigation] Use value over index property #7741

Merged
merged 1 commit into from
Aug 12, 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
Expand Up @@ -17,7 +17,7 @@ const styles = {

class LabelBottomNavigation extends Component {
state = {
value: 0,
value: 'recents',
};

handleChange = (event, value) => {
Expand All @@ -29,14 +29,12 @@ class LabelBottomNavigation extends Component {
const { value } = this.state;

return (
<div className={classes.root}>
<BottomNavigation value={value} onChange={this.handleChange}>
<BottomNavigationButton label="Recents" icon={<RestoreIcon />} />
<BottomNavigationButton label="Favorites" icon={<FavoriteIcon />} />
<BottomNavigationButton label="Nearby" icon={<LocationOnIcon />} />
<BottomNavigationButton label="Folder" icon={<FolderIcon />} />
</BottomNavigation>
</div>
<BottomNavigation value={value} onChange={this.handleChange} className={classes.root}>
<BottomNavigationButton label="Recents" value="recents" icon={<RestoreIcon />} />
<BottomNavigationButton label="Favorites" value="favorites" icon={<FavoriteIcon />} />
<BottomNavigationButton label="Nearby" value="nearby" icon={<LocationOnIcon />} />
<BottomNavigationButton label="Folder" value="folder" icon={<FolderIcon />} />
</BottomNavigation>
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ class SimpleBottomNavigation extends Component {
const { value } = this.state;

return (
<div className={classes.root}>
<BottomNavigation value={value} onChange={this.handleChange} showLabels>
<BottomNavigationButton label="Recents" icon={<RestoreIcon />} />
<BottomNavigationButton label="Favorites" icon={<FavoriteIcon />} />
<BottomNavigationButton label="Nearby" icon={<LocationOnIcon />} />
</BottomNavigation>
</div>
<BottomNavigation
value={value}
onChange={this.handleChange}
showLabels
className={classes.root}
>
<BottomNavigationButton label="Recents" icon={<RestoreIcon />} />
<BottomNavigationButton label="Favorites" icon={<FavoriteIcon />} />
<BottomNavigationButton label="Nearby" icon={<LocationOnIcon />} />
</BottomNavigation>
);
}
}
Expand Down
28 changes: 16 additions & 12 deletions docs/src/pages/component-demos/tabs/BasicTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import { withStyles } from 'material-ui/styles';
import AppBar from 'material-ui/AppBar';
import Tabs, { Tab } from 'material-ui/Tabs';

const TabContainer = props =>
<div style={{ padding: 20 }}>
{props.children}
</div>;
function TabContainer(props) {
return (
<div style={{ padding: 20 }}>
{props.children}
</div>
);
}

TabContainer.propTypes = {
children: PropTypes.node.isRequired,
Expand All @@ -26,34 +29,35 @@ const styles = theme => ({

class BasicTabs extends Component {
state = {
index: 0,
value: 0,
};

handleChange = (event, index) => {
this.setState({ index });
handleChange = (event, value) => {
this.setState({ value });
};

render() {
const classes = this.props.classes;
const { classes } = this.props;
const { value } = this.state;

return (
<div className={classes.root}>
<AppBar position="static">
<Tabs index={this.state.index} onChange={this.handleChange}>
<Tabs value={value} onChange={this.handleChange}>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
</Tabs>
</AppBar>
{this.state.index === 0 &&
{value === 0 &&
<TabContainer>
{'Item One'}
</TabContainer>}
{this.state.index === 1 &&
{value === 1 &&
<TabContainer>
{'Item Two'}
</TabContainer>}
{this.state.index === 2 &&
{value === 2 &&
<TabContainer>
{'Item Three'}
</TabContainer>}
Expand Down
34 changes: 19 additions & 15 deletions docs/src/pages/component-demos/tabs/BasicTabsWrappedLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import { withStyles } from 'material-ui/styles';
import AppBar from 'material-ui/AppBar';
import Tabs, { Tab } from 'material-ui/Tabs';

const TabContainer = props =>
<div style={{ padding: 20 }}>
{props.children}
</div>;
function TabContainer(props) {
return (
<div style={{ padding: 20 }}>
{props.children}
</div>
);
}

TabContainer.propTypes = {
children: PropTypes.node.isRequired,
Expand All @@ -26,34 +29,35 @@ const styles = theme => ({

class BasicTabsWrappedLabel extends Component {
state = {
index: 0,
value: 'one',
};

handleChange = (event, index) => {
this.setState({ index });
handleChange = (event, value) => {
this.setState({ value });
};

render() {
const classes = this.props.classes;
const { classes } = this.props;
const { value } = this.state;

return (
<div className={classes.root}>
<AppBar position="static">
<Tabs index={this.state.index} onChange={this.handleChange}>
<Tab label="New Arrivals in the Longest Text of Nonfiction" />
<Tab label="Item Two" />
<Tab label="Item Three" />
<Tabs value={value} onChange={this.handleChange}>
<Tab value="one" label="New Arrivals in the Longest Text of Nonfiction" />
<Tab value="two" label="Item Two" />
<Tab value="three" label="Item Three" />
</Tabs>
</AppBar>
{this.state.index === 0 &&
{value === 'one' &&
<TabContainer>
{'Item One'}
</TabContainer>}
{this.state.index === 1 &&
{value === 'two' &&
<TabContainer>
{'Item Two'}
</TabContainer>}
{this.state.index === 2 &&
{value === 'three' &&
<TabContainer>
{'Item Three'}
</TabContainer>}
Expand Down
10 changes: 5 additions & 5 deletions docs/src/pages/component-demos/tabs/CenteredTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ const styles = theme => ({

class CenteredTabs extends Component {
state = {
index: 0,
value: 0,
};

handleChange = (event, index) => {
this.setState({ index });
handleChange = (event, value) => {
this.setState({ value });
};

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

return (
<Paper className={classes.root}>
<Tabs
index={this.state.index}
value={this.state.value}
onChange={this.handleChange}
indicatorColor="primary"
textColor="primary"
Expand Down
8 changes: 4 additions & 4 deletions docs/src/pages/component-demos/tabs/DisabledTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import Tabs, { Tab } from 'material-ui/Tabs';

class DisabledTabs extends Component {
state = {
index: 0,
value: 0,
};

handleChange = (event, index) => {
this.setState({ index });
handleChange = (event, value) => {
this.setState({ value });
};

render() {
return (
<Paper>
<Tabs
index={this.state.index}
value={this.state.value}
indicatorColor="primary"
textColor="primary"
onChange={this.handleChange}
Expand Down
25 changes: 14 additions & 11 deletions docs/src/pages/component-demos/tabs/FullWidthTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import SwipeableViews from 'react-swipeable-views';
import AppBar from 'material-ui/AppBar';
import Tabs, { Tab } from 'material-ui/Tabs';

const TabContainer = props =>
<div style={{ padding: 24 }}>
{props.children}
</div>;
function TabContainer(props) {
return (
<div style={{ padding: 20 }}>
{props.children}
</div>
);
}

TabContainer.propTypes = {
children: PropTypes.node.isRequired,
Expand All @@ -25,25 +28,25 @@ const styles = theme => ({

class FullWidthTabs extends Component {
state = {
index: 0,
value: 0,
};

handleChange = (event, index) => {
this.setState({ index });
handleChange = (event, value) => {
this.setState({ value });
};

handleChangeIndex = index => {
this.setState({ index });
this.setState({ value: index });
};

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

return (
<div className={classes.root} style={{ width: 500 }}>
<AppBar position="static" color="default">
<Tabs
index={this.state.index}
value={this.state.value}
onChange={this.handleChange}
indicatorColor="primary"
textColor="primary"
Expand All @@ -54,7 +57,7 @@ class FullWidthTabs extends Component {
<Tab label="Item Three" />
</Tabs>
</AppBar>
<SwipeableViews index={this.state.index} onChangeIndex={this.handleChangeIndex}>
<SwipeableViews index={this.state.value} onChangeIndex={this.handleChangeIndex}>
<TabContainer>
{'Item One'}
</TabContainer>
Expand Down
8 changes: 4 additions & 4 deletions docs/src/pages/component-demos/tabs/IconLabelTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import PersonPinIcon from 'material-ui-icons/PersonPin';

export default class IconLabelTabs extends Component {
state = {
index: 0,
value: 0,
};

handleChange = (event, index) => {
this.setState({ index });
handleChange = (event, value) => {
this.setState({ value });
};

render() {
return (
<Paper style={{ width: 500 }}>
<Tabs
index={this.state.index}
value={this.state.value}
onChange={this.handleChange}
fullWidth
indicatorColor="accent"
Expand Down
10 changes: 5 additions & 5 deletions docs/src/pages/component-demos/tabs/IconTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ import PersonPinIcon from 'material-ui-icons/PersonPin';

export default class IconTabs extends Component {
state = {
index: 0,
value: 0,
};

handleChange = (event, index) => {
this.setState({ index });
handleChange = (event, value) => {
this.setState({ value });
};

render() {
return (
<Paper style={{ width: 500 }}>
<Tabs
index={this.state.index}
value={this.state.value}
onChange={this.handleChange}
fullWidth
indicatorColor="primary"
textColor="primary"
fullWidth
>
<Tab icon={<PhoneIcon />} />
<Tab icon={<FavoriteIcon />} />
Expand Down
Loading