How do I Change a button's aspect ratio on click? - css

I am using MUI v5 AppBar to create a navigation bar with Tabs. When the Tabs are clicked, I want the background of the clicked Tab to blend with the background of the main page in the following manner:
The problem is the Tabs are rendered as buttons, and will only appear centered in the appBar when clicked. I can adjust the styling when clicked to increase the height but that will increase the height of the whole button and even the bottom section doesn't blend in with the background as desired as shown here:
Is there a way to increase the proportions of the buttons unevenly on the top and bottom to achieve this and how will I get the background of the button to blend seamlessly with the rest of the page without the visible shadow.
Here's a sample of my current code:
<Box
sx={{
textTransform: "none",
flexGrow: 1,
display: { xs: "none", md: "flex" },
}}
>
<Tabs
value={selectedTab}
onChange={handleChange}
TabIndicatorProps={{hidden: true}}
sx={{
"& button": { borderRadius: 1 },
"& button.Mui-selected": {
color: "black",
backgroundColor: "#e5e5e5",
height: 70,
},
}}
>
<Tab value="one" label="Invoice" />
<Tab value="two" label="Students" />
<Tab value="three" label="Reports" />
</Tabs>
</Box>
Any answer to either question is highly appreciated. Thank you.

Try this out:
<Box
sx={{
textTransform: "none",
backgroundColor: "#295fab",
flexGrow: 1,
padding: "0px 5px",
paddingTop: "16px",
display: { xs: "none", md: "flex" }
}}
>
<Tabs
value={value}
onChange={handleChange}
TabIndicatorProps={{ hidden: true }}
sx={{
"& button": {
borderTopLeftRadius: 6,
borderTopRightRadius: 6,
padding: "5px 25px",
paddingTop: "16px"
},
"& button.Mui-selected": {
color: "black",
backgroundColor: "#e5e5e5"
}
}}
>
<Tab value="one" label="Invoices" />
<Tab value="two" label="Students" />
<Tab value="three" label="Reports" />
</Tabs>
</Box>

Related

Mui Button inside link not occupying entire height

I have a button inside a link inside a div that's not occupying the entire height of the div so what ends up happening is that the link gets clicked but not the button. I tried giving the button a height of 100% and removing padding but it doesn't seem to work.
Here's the element:
<div
style={{
display: "flex",
gap: "20px",
flexDirection: "column",
}}
>
<Link
to="/regions"
style={{
pointerEvents: regions > 0 ? "none" : "auto",
lineHeight: "0rem",
color: "black",
}}
>
<Button
variant="outlined"
sx={{
width: "400px",
color: "white",
"&:disabled": {
backgroundColor: "rgba(255,255,255,0.1)",
color: "white",
},
}}
onClick={() => handleClick("regions")}
disabled={regions > 0 ? true : false}
>
Region Test
</Button>
</Link>
{regionScore > 0 && (
<Box sx={{ width: "400px" }}>
<LinearProgress
color="success"
variant="determinate"
value={regionScore}
sx={{
backgroundColor: "transparent",
border: "1px solid black",
height: "20px",
borderRadius: "20px",
}}
/>
</Box>
)}
</div>
Any ideas?

How to Horizontally Center an element inside a MUI Typography Component

I am using the MUI V5 in a react project and I am trying to center the logo in an AppBar on extra small screens but no mattter what I do nothing seems to be working. The Typography comonent is wrapped inside a ToolBar wrapped inside an AppBar that only appears on xs screens.
Here's my current code.
<Box sx={{ display: 'flex' }}>
<CssBaseline />
<AppBar
elevation={0}
position="fixed"
sx={{
display: { xs: 'flex', sm: 'none' },
width: { sm: `calc(100% - ${drawerWidth}px)` },
ml: { sm: `${drawerWidth}px` },
bgcolor: 'gray',
}}
>
<Toolbar >
<IconButton
color="inherit"
aria-label="open drawer"
edge="start"
onClick={handleDrawerToggle}
sx={{ mr: 2, display: { sm: 'none' } }}
>
<MenuIcon />
</IconButton>
<Typography
variant="h5"
noWrap
component="a"
href=""
sx={{
flexGrow: 1,
bgcolor: 'red',
display: { xs: 'flex', sm: 'none' },
flexGrow: 1,
fontFamily: 'monospace',
fontWeight: 700,
letterSpacing: '.3rem',
color: 'inherit',
textDecoration: 'none',
}}
>
LOGO
</Typography>
</Toolbar>
</AppBar>
I have throw everything I can at it but nothing seems to work. Any help is highly appreaciated.
Best Way to handle spacing with MUI is using Grid component.
Your code would be like this:
return (
<Box sx={{ display: "flex" }}>
<CssBaseline />
<AppBar
elevation={0}
position="fixed"
sx={{
display: { xs: "flex", sm: "none" },
width: { sm: `calc(100% - ${drawerWidth}px)` },
ml: { sm: `${drawerWidth}px` },
bgcolor: "gray",
}}
>
<Toolbar>
<Grid
container
spacing={1}
sx={{ alignItems: "center", justifyContent: "space-between" }}
>
<Grid item xs={4} sx={{ textAlign: "start" }}>
<IconButton
color="inherit"
aria-label="open drawer"
edge="start"
// onClick={handleDrawerToggle}
sx={{ mr: 2 }}
>
<MenuIcon />
</IconButton>
</Grid>
<Grid item xs sx={{ textAlign: "center" }}>
<Typography
variant="h5"
noWrap
component="a"
href=""
sx={{
bgcolor: "red",
fontFamily: "monospace",
fontWeight: 700,
letterSpacing: ".3rem",
color: "inherit",
textDecoration: "none",
}}
>
LOGO
</Typography>
</Grid>
<Grid item xs={4}></Grid>
</Grid>
</Toolbar>
</AppBar>
</Box>
);
MUI Grid docs
Not a big expert in MUI, but try defining the flex direction, then define the align items or justify content to be centre depending on the direction.

How can a Box be aligned to the end of a toolbar without affecting content before it?

I have an app bar and a mini side drawer variant with code near identical to that which is given as example on material-ui. I am having trouble aligning a box with some info about the logged in user to the end of the app bar. Right now I am using grid containers, but these cause breaking bugs as screen size decreases. How can I force this box to the end of the toolbar while keeping any other content in the tool bar aligned to the start?
<AppBar
position="fixed"
className={clsx(classes.appBar, {
[classes.appBarShift]: open,
})}
>
<Toolbar>
<Grid container>
<a href="/home">
<SVGLOGO className="logo_stack" />
<SVGLOGOHORI className="logo" />
</a>
<Typography className={classes.envFlag} hidden={hidden}>
You are on the {process.env.REACT_APP_ENVIRONMENT} environment. Click{" "}
here to go to production.
</Typography>
</Grid>
<Grid container justifyContent="flex-end">
<Box
style={{
display: "flex",
alignItems: "center",
backgroundColor: "#0672cb",
height: "64px",
padding: "10px 24px 10px 24px",
}}
>
<i class="icon_class" style={{ fontSize: "24px", color: "#fff", marginRight: "10px" }}></i>
<Box style={{ marginLeft: "10px" }}>
<Typography
style={{
color: "#FFF",
fontWeight: 400,
fontSize: 14,
}}
>
{loggedUser}
</Typography>
<Typography
style={{
color: "#FFF",
fontWeight: 400,
fontSize: 14,
}}
>
{userRole}
</Typography>
<Typography
style={{
color: "#FFF",
fontWeight: 400,
fontSize: 14,
}}
>
{userExperience}
</Typography>
</Box>
</Box>
</Grid>
</Toolbar>
</AppBar>

Hiding Scrollbar from Material UI Treeview, while maintaining scroll functionality

How do I maintain the vertical scroll functionality, while at the same time, hiding the scrollbar in Material UI's Treeview API? I have tried a few combinations of styling directly in the tree view and tree item components to hide the scrollbar, but neither worked for me.
<TreeView
aria-label="icon expansion"
defaultCollapseIcon={<ExpandMoreIcon />}
defaultExpandIcon={<ChevronRightIcon />}
sx={{ height: 240, flexGrow: 1, overflowY: 'auto', overflowX: 'hidden' }}
>
<StyledTreeItem
label={
<Grid container>
<Grid item xs={3}>
Watchlist
</Grid>
<Grid item xs={8}>
</Grid>
</Grid>
}
nodeId="1"
style={{ padding: '0.2vw' }}>
<Grid container style={{ width: '100%' }}>
<LiveStockTable
minHeight={500}
maxHeight={1000}
subscribedTickers={props.subscribedTickers} />
</Grid>
</StyledTreeItem>
</TreeView>
and the StyledTreeItem:
const StyledTreeItem = styled(TreeItem)<StyledTreeItemProps>({
position: "relative",
"&:before": {
pointerEvents: "none",
content: '""',
position: "absolute",
overflow: 'hidden'
},
[`& .${treeItemClasses.group}`]: {
marginLeft: 0,
paddingLeft: 0,
}
})

Material UI - remove border from one of the textfields

I'm trying to make an input with an icon on the left. something like this:
I've already created the input. my plan is to add the input and icon in a grid. remove input's border and add it to the grid container.
I'm not able to remove the border. I've tried using the spread operator but I was getting errors.
there are other inputs using the same styles and they need the border.
How can I remove border for this input ?
const useStylesCustom = makeStyles((theme) => ({
root: {
border: '1px solid #e2e2e1',
overflow: 'hidden',
borderRadius: 2,
backgroundColor: '#fff',
transition: theme.transitions.create(['border-color', 'box-shadow']),
'&:hover': {
backgroundColor: '#fff',
},
'&$focused': {
backgroundColor: '#fff',
borderColor: '#DFDFDF',
},
'&$error': {
borderColor: theme.palette.error.main,
},
},
focused: {},
error: {},
}));
<Grid container>
<Grid xs={2} style={{ alignSelf: 'center', textAlign: 'center' }} item>
<img src="/img/usa_flag.svg" height="25" />
</Grid>
<Grid item xs={10}>
<TextField
fullWidth
label='Phone number'
variant='filled'
value={lastName}
style={{ border: '0' }}
InputProps={{ classes, disableUnderline: true }}
onChange={(e) => setLastName(e.target.value)}
/>
</Grid>
</Grid>
You can remove the variant and no border will be displayed:
<Grid container style={{border: "1px solid black"}}>
<Grid xs={2} style={{ alignSelf: 'center', textAlign: 'center' }} item>
<img src="/img/usa_flag.svg" height="25" />
</Grid>
<Grid item xs={10}>
<TextField
fullWidth
label='Phone number'
value={"lastName"}
style={{ border: '0' }}
InputProps={{ classes, disableUnderline: true }}
/>
</Grid>
</Grid>
Here is a sandbox.

Resources