Material UI Tab label font-size is really small - reactjs

I started to use material ui tabs and I'm having issues with the font size of the Tab labels because they are really small...
This is my code:
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '#material-ui/core/styles';
import AppBar from '#material-ui/core/AppBar';
import Tabs from '#material-ui/core/Tabs';
import Tab from '#material-ui/core/Tab';
import Typography from '#material-ui/core/Typography';
function TabContainer(props) {
return (
<Typography component="div" style={{ padding: 8 * 3 }}>
{props.children}
</Typography>
);
}
TabContainer.propTypes = {
children: PropTypes.node.isRequired,
};
const styles = theme => ({
root: {
flexGrow: 1,
backgroundColor: theme.palette.background.paper,
},
tabRoot: {
backgroundColor: theme.palette.background.paper,
flexGrow: 1,
color: 'black',
fontWeight: 'bold'
}
});
class SimpleTabs extends React.Component {
state = {
value: 0,
};
handleChange = (event, value) => {
this.setState({ value });
};
render() {
const { classes } = this.props;
const { value } = this.state;
return (
<div className={classes.root}>
<AppBar position="static">
<Tabs className={classes.tabRoot} value={value} onChange={this.handleChange}>
<Tab label="Item One" />
<Tab label="Item Two" />
</Tabs>
</AppBar>
{value === 0 && <TabContainer>Item One</TabContainer>}
{value === 1 && <TabContainer>Item Two</TabContainer>}
{value === 2 && <TabContainer>Item Three</TabContainer>}
</div>
);
}
}
SimpleTabs.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(SimpleTabs);
Is there any way to increase the size of those labels?

Material-ui Tab component label prop type is node. So if you want to add styles you need to put plain text inside div or span, o another html component and add className.
<Tab label={<span className={classes.tabLabel}>Label</span>}/>

1. You can set the style of the tab, and use an own wrapper component, e.g. like TabBigger:
import React from 'react';
import { withStyles } from '#material-ui/core/styles';
import AppBar from '#material-ui/core/AppBar';
import Tabs from '#material-ui/core/Tabs';
import Tab from '#material-ui/core/Tab';
import Typography from '#material-ui/core/Typography';
const styles = theme => ({
root: { backgroundColor: '#0af' },
tabRoot: { backgroundColor: '#0a6' },
label: {
backgroundColor: '#aa0',
fontSize: '22px'
},
});
function TabContainer(props) {
return (
<Typography component="div" style={{ padding: 8 * 3 }}>
{props.children}
</Typography>
);
}
const TabBigger = withStyles(styles)(( props )=>{
return (
<Tab className={props.classes.label} {...props}/>
);
});
class SimpleTabs extends React.Component {
state = {
value: 0,
};
handleChange = (event, value) => {
this.setState({ value });
};
render() {
const { classes } = this.props;
const { value } = this.state;
return (
<div className={classes.root}>
<AppBar position="static">
<Tabs className={classes.tabRoot} value={value} onChange={this.handleChange}>
<TabBigger label="Item One" />
<TabBigger label="Item Two" />
</Tabs>
</AppBar>
{value === 0 && <TabContainer>Item One</TabContainer>}
{value === 1 && <TabContainer>Item Two</TabContainer>}
{value === 2 && <TabContainer>Item Three</TabContainer>}
</div>
);
}
}
export default withStyles(styles)(SimpleTabs);
2. Alternatively, you might want to set the style of the tab-label (instead of the whole Tab component) with the MUI-rule labelContainer:
<Tab classes={{ root: { props.classes.tab }, labelContainer: props.classes.label }} />

With new versions of MUI you can specify the label component directly in the component
import React from 'react';
import { withStyles } from '#material-ui/core/styles';
import AppBar from '#material-ui/core/AppBar';
import Tabs from '#material-ui/core/Tabs';
import Tab from '#material-ui/core/Tab';
import Typography from '#material-ui/core/Typography';
const styles = theme => ({
root: { backgroundColor: '#0af' },
tabRoot: { backgroundColor: '#0a6' },
});
function TabContainer(props) {
return (
<Typography component="div" style={{ padding: 8 * 3 }}>
{props.children}
</Typography>
);
}
class SimpleTabs extends React.Component {
state = {
value: 0,
};
handleChange = (event, value) => {
this.setState({ value });
};
render() {
const { classes } = this.props;
const { value } = this.state;
return (
<div className={classes.root}>
<AppBar position="static">
<Tabs className={classes.tabRoot} value={value} onChange={this.handleChange}>
<Tab label={(<Typography variant="h6">Item One</Typography>)} />
<Tab label={(<Typography variant="h6">Item Two</Typography>)} />
</Tabs>
</AppBar>
{value === 0 && <TabContainer>Item One</TabContainer>}
{value === 1 && <TabContainer>Item Two</TabContainer>}
{value === 2 && <TabContainer>Item Three</TabContainer>}
</div>
);
}
}
export default withStyles(styles)(SimpleTabs);

Related

Mui grid is causing last two elements of an array to show up larger, and will not display side by side card grid

I have implemented an MUI card grid to display contents of my infinite scroll. However, the last two elements of the returned contents are showing up larger for some reason. Also the grid wont display cards side by side without a map function, which I cannot use or my infinite scroll breaks.
All data is mock data
Any solutions to either part would be wonderful!
Infinite Scroll Component
`
import { useRef, useCallback, useState, useEffect } from 'react'
import {
Box,
CardMedia,
CardContent,
Grid,
Paper,
Typography,
} from "#mui/material";
import { styled } from '#mui/material/styles';
import CountryListCard from '../CountryListCard/CountryListCard';
import Card4 from '../CountryListCard/HomeCards/HomeCountryCard'
import { useInfiniteQuery } from 'react-query'
import { getPostsPage } from '../../services/countries.service'
import { makeStyles } from "#material-ui/core/styles";
const useStyles = makeStyles({
gridContainer: {
paddingLeft: "40px",
paddingRight: "40px",
}
});
const Item = styled(Paper)(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
...theme.typography.body2,
padding: theme.spacing(2),
textAlign: 'center',
color: theme.palette.text.secondary,
}));
const HomeScroll = () => {
const classes = useStyles();
const {
fetchNextPage, //function
hasNextPage, // boolean
isFetchingNextPage, // boolean
data,
status,
error
} = useInfiniteQuery('/country', ({ pageParam = 1 }) => getPostsPage(pageParam), {
getNextPageParam: (lastPage, allPages) => {
return lastPage.length ? allPages.length + 1 : undefined
}
})
const intObserver = useRef()
const lastPostRef = useCallback(country => {
if (isFetchingNextPage) return
if (intObserver.current) intObserver.current.disconnect()
intObserver.current = new IntersectionObserver(countries => {
if (countries[0].isIntersecting && hasNextPage) {
console.log('We are near the last post!')
fetchNextPage()
}
})
if (country) intObserver.current.observe(country)
}, [isFetchingNextPage, fetchNextPage, hasNextPage])
if (status === 'error') return <p className='center'>Error: {error.message}</p>
const content = data?.pages.map(pg => {
return pg.map((country, i) => {
if (pg.length === i + 1) {
return (
<Grid container spacing={2}>
<Grid item xs>
<CountryListCard ref={lastPostRef} key={country.id} country={country} />
</Grid>
</Grid>
)
}
return (
<Grid container spacing={2}>
<Grid item xs={6}>
<CountryListCard key={country.id} country={country} />
</Grid>
</Grid>
)
})
})
return (
<>
<Grid container spacing={2}>
<Grid item xs={6}>
{content}
</Grid>
</Grid>
{/* <Review ref={lastPostRef} key={country._id} country={country} review={review}/> */}
{isFetchingNextPage && <p className="center">Loading More Posts...</p>}
<p className="center">Back to Top</p>
</>
)
}
export default HomeScroll;
Card Components
`
import {
CardMedia,
CardContent,
CardActions,
Grid,
Box,
Paper,
Typography,
} from "#mui/material";
import { makeStyles } from "#material-ui/core/styles";
import { styled } from '#mui/material/styles';
import React, { useState, useEffect, useContext } from "react";
import { Link, useLocation, useNavigate } from "react-router-dom";
import MenuList from "../menu/menuItem";
import Flash from "../../components/Flash";
import { AuthContext } from "../../services/auth.context";
import Card4 from './HomeCards/HomeCountryCard';
const Item = styled(Paper)(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
...theme.typography.body2,
padding: theme.spacing(2),
textAlign: 'center',
color: theme.palette.text.secondary,
}));
const useStyles = makeStyles({
gridContainer: {
paddingLeft: "40px",
paddingRight: "40px"
}
});
const CountryListCard = React.forwardRef(({ country }, ref) => {
const location = useLocation();
const navigate = useNavigate();
const { isAuthenticated, user } = useContext(AuthContext);
const classes = useStyles();
const rows =[{
country: country,
}]
const postBody = (
<>
<Card4 country={country} key={country.id}/>
</>
)
const content = ref
? <div ref={ref}>{postBody}</div>
: <div>{postBody}</div>
const handleViewClick = () => {
navigate(`/country/${country._id}`);
};
return (
<>
{location.state?.message && (
<Flash type={location.state.type} message={location.state.message} />
)}
{content}
{user && isAuthenticated && (
<Grid item xl={6} md={6} sm={12} xs={12}>
<MenuList countryId={country._id} />
</Grid>
)}
</>
);
})
export default CountryListCard;
`
`
import {
Rating,
Grid,
} from "#mui/material";
import React, { useState, useEffect, useContext } from "react";
import { useNavigate } from "react-router-dom";
import { Card, Col, Row, Button, Text } from "#nextui-org/react";
const Card4 = ({ country }) => {
const navigate = useNavigate();
const handleViewClick = () => {
navigate(`/country/${country._id}`);
};
return (
<>
<Card isPressable>
<Card.Body css={{ p: 0 }}>
<Card.Image
src={country.images[0].image}
objectFit="cover"
width="100%"
height={140}
alt={country.title}
/>
<Rating name="simple-controlled" value={country.overallRating} readOnly/>
</Card.Body>
<Card.Footer css={{ justifyItems: "flex-start" }}>
<Row wrap="wrap" justify="space-between" align="center">
<Text b>{country.title}</Text>
<Button flat auto rounded color="secondary"
onClick={handleViewClick}
>
<Text
css={{ color: "inherit" }}
size={12}
weight="bold"
transform="uppercase"
>
View Country
</Text>
</Button>
</Row>
</Card.Footer>
</Card>
</>
);
};
export default Card4
Picture of the problem
picture](https://i.stack.imgur.com/QObLp.png)
I tried adding the mui code to all different elements, I tried using a map function instead of infinite scroll but that was unfeasible, I tried other frontend libraries and got the same issues. I also tried changing all kinds of different spacing and sizing of elements.

usecontext without child component?

I'm wanting to pass a state from my WeatherComponent through to my UserForm component and ideally would like to do this without making the UserForm a child component. At the moment I have the UserForm as a child component and that component is working fine when I render it because it's getting the weather state from the WeatherComponent. But now when I want to render my WeatherComponent it renders the UserComponent as well.
Is there another way I could use useContext or a method that doesn't rely on making a child component?
WeatherComponent:
import axios from 'axios';
import { useEffect, useState, createContext } from 'react';
import { Weather } from '../types';
import { MdWbSunny } from 'react-icons/md';
import { IoIosPartlySunny } from 'react-icons/io';
import { BsFillCloudSnowFill } from 'react-icons/bs';
import { Title, Text, Container } from '#mantine/core';
import UserForm from './UserForm';
export const WeatherContext = createContext<any>(null);
const WeatherComponent = () => {
const [weather, setWeather] = useState<Weather | null>();
const fetchWeatherData = async () => {
const response = await axios.get('http://mock-api-call/weather/get-weather');
setWeather(response.data.result.weather);
};
useEffect(() => {
fetchWeatherData();
}, []);
return (
<Container>
<WeatherContext.Provider value={weather?.forcast}>
<UserForm />
</WeatherContext.Provider>
<Title order={2}>
{weather?.forcast === 'Sunny' ? (
<MdWbSunny data-testid="sunny" />
) : weather?.forcast === 'Snowing' ? (
<BsFillCloudSnowFill data-testid="snowing" />
) : (
<IoIosPartlySunny data-testid="overcast" />
)}
</Title>
<Text size="xl" data-testid="forcast">
{weather?.forcast}
</Text>
<Text size="lg" data-testid="temp">
Temp: {`${weather?.min} to ${weather?.max}`}
</Text>
<Text size="md" data-testid="description">
{weather?.description}
</Text>
</Container>
);
};
export default WeatherComponent;
UserForm:
import React, { useContext, useState } from 'react';
import { Container, Title, TextInput, Button, Group, Header } from '#mantine/core';
import { useStateWithLocalStorage } from './UseStateWithLocalStorage';
import { WeatherContext } from './WeatherComponent';
import { MdWbSunny } from 'react-icons/md';
import { BsFillCloudSnowFill } from 'react-icons/bs';
import { IoIosPartlySunny } from 'react-icons/io';
const UserForm = () => {
const [inputValue, setInputValue] = useStateWithLocalStorage('', 'form');
const [show, setShow] = useState(true);
const weatherIcon = useContext(WeatherContext);
function handleChange(event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) {
setInputValue(() => ({
[event.target.name]: event.target.value,
}));
}
return (
<Header height={56} mb={120}>
<Container
style={{
display: 'flex',
flexDirection: 'row',
backgroundColor: 'gray',
justifyContent: 'space-between',
color: 'white',
alignItems: 'center',
padding: '10px',
fontSize: '25px',
fontWeight: 'bold',
boxShadow: '0 3px 6px 0 #555',
}}
>
<Group>
<Title order={2}>Welcome </Title>
{show && (
<TextInput
type="text"
name="name"
id="name"
placeholder="enter your name"
onChange={handleChange}
value={inputValue.name}
/>
)}
{show && <Button onClick={() => setShow((prev) => !prev)}>SAVE</Button>}
<Title order={2}>{inputValue.name ? inputValue.name : ''}</Title>
</Group>
<Group style={{ display: 'flex', justifyContent: 'flex-end' }}>
<Title order={2}>
{weatherIcon === 'Sunny' ? (
<MdWbSunny data-testid="sunny" />
) : weatherIcon === 'Snowing' ? (
<BsFillCloudSnowFill data-testid="snowing" />
) : (
<IoIosPartlySunny data-testid="overcast" />
)}
</Title>
</Group>
</Container>
</Header>
);
};
export default UserForm;

Pass the Material UI Tab heading as a URL parameter React

I want to pass the selected date as a parameter when the showtime button is clicked. I couldn't find a way and I'm new to React. looking for suggestions.
Following is my code
import React, { useEffect, useState }from "react";
import PropTypes from "prop-types";
import { makeStyles } from "#material-ui/core/styles";
import AppBar from "#material-ui/core/AppBar";
import Tabs from "#material-ui/core/Tabs";
import Tab from "#material-ui/core/Tab";
import PhoneIcon from "#material-ui/icons/Phone";
import FavoriteIcon from "#material-ui/icons/Favorite";
import PersonPinIcon from "#material-ui/icons/PersonPin";
import HelpIcon from "#material-ui/icons/Help";
import ShoppingBasket from "#material-ui/icons/ShoppingBasket";
import ThumbDown from "#material-ui/icons/ThumbDown";
import ThumbUp from "#material-ui/icons/ThumbUp";
import Typography from "#material-ui/core/Typography";
import Box from "#material-ui/core/Box";
import { DateRangeSharp } from "#material-ui/icons";
import { List, ListItem, ListItemText } from "#material-ui/core";
import Button from '#material-ui/core/Button';
import queryString from 'query-string';
import { Link, useLocation } from 'react-router-dom';
function TabPanel(props) {
const { children, value, index, ...other } = props;
return (
<div
role="tabpanel"
hidden={value !== index}
id={`scrollable-force-tabpanel-${index}`}
aria-labelledby={`scrollable-force-tab-${index}`}
{...other}
>
{value === index && (
<Box p={3}>
<Typography>{children}</Typography>
</Box>
)}
</div>
);
}
TabPanel.propTypes = {
children: PropTypes.node,
index: PropTypes.any.isRequired,
value: PropTypes.any.isRequired
};
function a11yProps(index) {
return {
id: `scrollable-force-tab-${index}`,
"aria-controls": `scrollable-force-tabpanel-${index}`,
};
}
const useStyles = makeStyles((theme) => ({
root: {
flexGrow: 1,
width: "100%",
backgroundColor: theme.palette.background.paper
}
}));
export default function ScrollableTabsButtonForce() {
const classes = useStyles();
const [value, setValue ] = React.useState(0);
const [venuesDates, setvenuesDates] = React.useState([]);
const [showtimesData] = React.useState([]);
useEffect(() => {
const url = "http://sandbox-api.tickets.lk/v1/movie/3232/showtime";
const requestOptions = (token) => {
return ({
method: 'GET',
headers: { 'Content-Type': 'application/json', 'client_token': 'ebd86470-7e90-4ece-9e89-1b6d4d2cbb61' }
})
};
const fetchData = async () => {
try {
const response = await fetch(url, requestOptions());
const json = await response.json();
// console.log(json);
// console.log(json.data.venueDateShowtime)
setvenuesDates(json.data.venueDateShowtime);
}
catch (error) {
console.log("error",error);
}
};
fetchData();
})
const search = useLocation().search;
const Mid = new URLSearchParams(search).get('movieid');
const Mname = new URLSearchParams(search).get('name');
// console.log(Mname)
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<div className={classes.root}>
<AppBar
position="static"
style={{ background: "#333545", minHeight: 60 }}
>
<Tabs
value={value}
onChange={handleChange}
variant="scrollable"
scrollButtons="on"
indicatorColor="secondary"
textColor="primary"
aria-label="scrollable force tabs example"
style={{ minHeight: 60 }}
wrapped
>
{venuesDates.map((showtdates) => {
return (
<Tab
label={showtdates.date}
{...a11yProps(0)}
style={{ color: "#fff", fontSize: 20, minHeight: 60 }}
/>
);
})}
</Tabs>
</AppBar>
{/* map over dates and create TabPanel */}
{/* // check if theater property exists and create a list of theaters as an example */}
{venuesDates.map((date, idx) => {
const venues = date.hasOwnProperty("venues")
? date.venues.map((venues) => (
<ListItem>
<ListItemText
primary={venues.venue}
secondary={venues.venueId}
/>
{date.venues.map((date)=> {
const showtimes = venues.hasOwnProperty("showtimes")
? venues.showtimes.map((showtimes) => (
// <ListItemText primary={showtimes.showtime} />
<Link to={'/seat-booking?movieid=' + Mid +"&name=" + Mname + "&theater=" + venues.venueId +
"&movieDate=" + "showtdates.date" + "&showtimes=" + showtimes.showtimeId}
style={{ textDecoration: 'none', color: 'white' }}>
<Button variant="contained" color="primary" style={{margin:5}}>
{showtimes.showtime}
</Button>
</Link>
))
:null;
return(
<List>{showtimes}</List>
)
})}
</ListItem>
))
: null;
return (
<TabPanel value={value} index={idx}>
<List>{venues}</List>
</TabPanel>
);
})}
</div>
);
}
I really want to get the selected date from the Tab heading and pass as a parameter as mentioned below.
I need to change the "&movieDate=" + "showtdates.date" ===> as "&movieDate=" + (selected tab heading name)
{date.venues.map((date)=> {
const showtimes = venues.hasOwnProperty("showtimes")
? venues.showtimes.map((showtimes) => (
// <ListItemText primary={showtimes.showtime} />
<Link to={'/seat-booking?movieid=' + Mid +"&name=" + Mname + "&theater=" + venues.venueId +
"&movieDate=" + "showtdates.date" + "&showtimes=" + showtimes.showtimeId}
style={{ textDecoration: 'none', color: 'white' }}>
<Button variant="contained" color="primary" style={{margin:5}}>
{showtimes.showtime}
</Button>
</Link>
))
:null;
return(
<List>{showtimes}</List>
)
})}

I cannot get the updated value from the global state (REDUX) when I use Material-UI

I cannot get the updated state of isAuthenticated when I have Material-UI code.
Is there any way that I can update the state when I have Material-UI code.
import React from "react";
import clsx from "clsx";
import { withStyles } from "#material-ui/core/styles";
import MUILink from "#material-ui/core/Link";
import AppBar from "../UI/components/AppBar";
import Toolbar, { styles as toolbarStyles } from "../UI/components/Toolbar";
import { Link } from "react-router-dom";
import { connect } from 'react-redux';
const styles = theme => ({
title: {
fontSize: 24
},
placeholder: toolbarStyles(theme).root,
toolbar: {
justifyContent: "space-between"
},
left: {
flex: 1
},
leftLinkActive: {
color: theme.palette.common.white
},
right: {
flex: 1,
display: "flex",
justifyContent: "flex-end"
},
rightLink: {
fontSize: 16,
color: theme.palette.common.white,
marginLeft: theme.spacing(3)
},
linkSecondary: {
color: theme.palette.secondary.main
}
});
const Navbar = (props,{isAuthenticated,loading}) => {
const { classes } = props;
const authLinks = (
<div className={classes.right}>
<MUILink
variant="h6"
underline="none"
component={Link} to="/log-out"
className={clsx(classes.rightLink, classes.linkSecondary)}
>
{"Log out"}
</MUILink>
</div>
);
const guestLinks = (
<div className={classes.right}>
<MUILink
color="inherit"
variant="h6"
underline="none"
component={Link} to="/sign-in"
className={classes.rightLink}
>
{"Sign In"}
</MUILink>
<MUILink
variant="h6"
underline="none"
component={Link} to="/sign-up"
className={clsx(classes.rightLink, classes.linkSecondary)}
>
{"Sign Up"}
</MUILink>
</div>
);
return (
<div>
<AppBar position="fixed">
<Toolbar className={classes.toolbar}>
<div className={classes.left} />
<MUILink
variant="h6"
underline="none"
color="inherit"
className={classes.title}
component={Link} to="/"
>
{"buzzer"}
</MUILink>
{!loading && (
<React.Fragment>{isAuthenticated ? authLinks : guestLinks}</React.Fragment>
)}
</Toolbar>
</AppBar>
<div className={classes.placeholder} />
</div>
);
};
const mapStateToProps = state =>({
isAuthenticated:state.auth.isAuthenticated,
loading:state.auth.loading
})
export default connect(mapStateToProps)((withStyles(styles)(Navbar)));
I want that the Navbar to change based on the condition of isAuthenticated. If user is authenticated I want to display only authLink, if the user is not authenticated I want to display the guestLink.
{isAuthenticated,loading} will be injected inside props, and not as a second parameter:
const Navbar = (props) => {
const { classes, isAuthenticated,loading } = props;

material-ui button active style

I am trying to workout how I would have appbar buttons that link to components show a different style when active.
I should also note: this is a my first material-ui app and the docs are not so clear.
Basically I want an underline on the button that is active.
<Button color="inherit" component={Link} to={"/"}>Home</Button>
<Button color="inherit" component={Link} to={"/About"}>About</Button>
My full code.
import React, {useState } from 'react';
import { Link as Links } from 'react-router-dom';
import ReactDOM from 'react-dom';
import { makeStyles } from '#material-ui/core/styles';
import AppBar from '#material-ui/core/AppBar';
import Fab from '#material-ui/core/Fab';
//import Icon from '#material-ui/core/Icon';
import Toolbar from '#material-ui/core/Toolbar';
import Link from '#material-ui/core/Link';
import Typography from '#material-ui/core/Typography';
import Button from '#material-ui/core/Button';
import IconButton from '#material-ui/core/IconButton';
import MenuIcon from '#material-ui/icons/Menu';
const useStyles = makeStyles(theme => ({
root: {
flexGrow: 1,
},
menuButton: {
marginRight: theme.spacing(2),
},
fab: {
position: 'absolute',
background:'red',
bottom: theme.spacing(2),
right: theme.spacing(2),
"&:hover, &:focus":{
background:'black',
}
},
title: {
flexGrow: 1,
align:'center',
},
}));
function Nav() {
const classes = useStyles();
const [icon,setIcon] = useState(false)
const fabIcon = {
color: 'white',
fontSize: 40,
};
const handleClick = e => {
setIcon(!icon)
{ icon ? document.getElementById("player").play() : document.getElementById("player").pause() }
}
return (
<div className={classes.root}>
<AppBar position="static">
<Toolbar>
<IconButton edge="start" className={classes.menuButton} color="inherit" aria-label="Menu">
<MenuIcon />
</IconButton>
<Typography variant="h6" align="center" className={classes.title}>
News
</Typography>
<Button color="inherit">Login</Button>
<Button color="inherit" component={Links} to={"/"} linkButton={true}>Home</Button>
<Button color="inherit" component={Links} to={"/about"}>About</Button>
</Toolbar>
</AppBar>
<AppBar position="static">
</AppBar>
<audio id="player">
<source
src="https://samcloud.spacial.com/api/listen?sid=106487&m=sc&rid=184639"
type="audio/mpeg"
/>
</audio>
<Fab aria-label='test' className={classes.fab}>
<i className='large material-icons' style={fabIcon} onClick={handleClick}>
{ icon ? 'play_circle_outline' : 'pause_circle_outline'}</i>
</Fab>
</div>
);
}
export default class GrandChild extends React.Component {
componentDidMount() {
setTimeout(function(){ document.getElementById("player").play() }, 3000);
}
value() {
return ReactDOM.findDOMNode(this.refs.input).value;
}
render() {
return (
<div>
<Nav />
</div>
);
}
}
I recently had the same issue, and I solved it by using NavLink instead of Link from react-router-dom!
Example:
<Button
className={classes.button}
component={NavLink}
to="/page-link"
>
This will add the class ".active" to active buttons.
Using material's makeStyles hook, you can then style the buttons with this class:
const useStyles = makeStyles({
button: {
"&.active": {
background:'black',
},
},
});
If you're not using any third-party library like Gatsby, React-router then you should consider about this Tabs
Code:
import React from 'react';
import { makeStyles, Theme } from '#material-ui/core/styles';
import AppBar from '#material-ui/core/AppBar';
import Tabs from '#material-ui/core/Tabs';
import Tab from '#material-ui/core/Tab';
import Typography from '#material-ui/core/Typography';
import Box from '#material-ui/core/Box';
interface TabPanelProps {
children?: React.ReactNode;
index: any;
value: any;
}
function TabPanel(props: TabPanelProps) {
const { children, value, index, ...other } = props;
return (
<div
role="tabpanel"
hidden={value !== index}
id={`simple-tabpanel-${index}`}
aria-labelledby={`simple-tab-${index}`}
{...other}
>
{value === index && (
<Box p={3}>
<Typography>{children}</Typography>
</Box>
)}
</div>
);
}
function a11yProps(index: any) {
return {
id: `simple-tab-${index}`,
'aria-controls': `simple-tabpanel-${index}`,
};
}
const useStyles = makeStyles((theme: Theme) => ({
root: {
flexGrow: 1,
backgroundColor: theme.palette.background.paper,
},
}));
export default function SimpleTabs() {
const classes = useStyles();
const [value, setValue] = React.useState(0);
const handleChange = (event: React.ChangeEvent<{}>, newValue: number) => {
setValue(newValue);
};
return (
<div className={classes.root}>
<AppBar position="static">
<Tabs value={value} onChange={handleChange} aria-label="simple tabs example">
<Tab label="Item One" {...a11yProps(0)} />
<Tab label="Item Two" {...a11yProps(1)} />
<Tab label="Item Three" {...a11yProps(2)} />
</Tabs>
</AppBar>
<TabPanel value={value} index={0}>
Item One
</TabPanel>
<TabPanel value={value} index={1}>
Item Two
</TabPanel>
<TabPanel value={value} index={2}>
Item Three
</TabPanel>
</div>
);
}
To master in Material UI Tabs

Resources