Skip to content

Instantly share code, notes, and snippets.

@hafbau
Last active December 11, 2022 18:14
Show Gist options
  • Save hafbau/1a332cf84455aafc2dcd2716ee14fcc1 to your computer and use it in GitHub Desktop.
Save hafbau/1a332cf84455aafc2dcd2716ee14fcc1 to your computer and use it in GitHub Desktop.
Vertical Tabs Example - React Material UI
import React from 'react';
import Tabs from '@material-ui/core/Tabs'
import Tab from '@material-ui/core/Tab'
import Typography from '@material-ui/core/Typography'
import { withStyles } from '@material-ui/core/withStyles';
class ProfileTabs extends React.PureComponent {
state = { activeIndex: 0 }
handleChange = (_, activeIndex) => this.setState({ activeIndex })
render() {
const { activeIndex } = this.state;
return (
<div
style={{
display: 'flex',
}}
>
<VerticalTabs
value={activeIndex}
onChange={this.handleChange}
>
<MyTab label='item one' />
<MyTab label='item two' />
<MyTab label='item three' />
</VerticalTabs>
{ activeIndex === 0 && <TabContainer>Item One</TabContainer> }
{ activeIndex === 1 && <TabContainer>Item Two</TabContainer> }
{ activeIndex === 2 && <TabContainer>Item Three</TabContainer> }
</div>
)
}
}
const VerticalTabs = withStyles(theme => ({
flexContainer: {
flexDirection: 'column'
},
indicator: {
display: 'none',
}
}))(Tabs)
const MyTab = withStyles(theme => ({
selected: {
color: 'tomato',
borderBottom: '2px solid tomato'
}
}))(Tab);
function TabContainer(props) {
return (
<Typography component="div" style={{ padding: 24 }}>
{props.children}
</Typography>
);
}
export default ProfileTabs;
@dalepres
Copy link

hafbau, I did get a Material-UI tabs working with images with some great help on stackoverflow.com. There were several undocumented features and steps required to make it happen. I'm learning that material-ui is a great and maturing package but may not as mature as I had initially thought. That's not an issue and I appreciate all the great work from those who create and support it. I'm looking forward to learning it more thoroughly.

@Gblack-Hub
Copy link

Thank you.

@chombazm
Copy link

Thanks so much. this is what i really needed 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment