MUI Modal [tabindex]? - css

I have tried incorporating a modal into my project, but the modal is not able to close and the height is covering the entire screen length. When I inspect element, it says:
[tabindex]:
outline: none;
height: 100%
How do I get rid of this height: 100% ?
This is the code (from MUI example + my styled component):
import React from 'react';
import Modal from '#mui/material/Modal';
import styled from 'styled-components';
import Box from '#mui/material/Box';
import Typography from '#mui/material/Typography';
const style = {
position: 'absolute' as 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: 400,
bgcolor: 'background.paper',
border: '2px solid #000',
boxShadow: 24,
p: 4,
};
export function FeedbackButton() {
const [open, setOpen] = React.useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
return (
<>
<FButton onClick={handleOpen}>FeedBack</FButton>
<Modal
open={open}
onClose={handleClose}
aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description"
>
<Box sx={style}>
<Typography id="modal-modal-title" variant="h6" component="h2">
Text in a modal
</Typography>
<Typography id="modal-modal-description" sx={{ mt: 2 }}>
Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
</Typography>
</Box>
</Modal>
</>
);
}
const FButton = styled.button`
position: absolute;
background: white;
bottom: 15px;
right: 15px;
padding: 16px;
border-radius: 10px;
font-size: 20px;
font-family: Verlag;
`;
the problems with height 100% are:
if I set the modal style to a fixed height limit, it doesn't close when I click outside of it because of the overflow
looks ugly
TLDR: How do I exempt this one element from [tabindex]?

try setting your own height like in the example
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: 400,
hieght: 600,

Related

Vertical Fixed Box at bottom of screen using MUI

So far I have tried this:
import "./styles.css";
import { Box, Typography } from "#mui/material";
import styled from "#emotion/styled";
export default function App() {
const MainStyle = styled("div")(({ theme }) => ({
position: "fixed",
zIndex: 99999,
right: 0,
bottom: 0
}));
return (
<MainStyle>
<Box sx={{ transform: "rotate(-90deg)", backgroundColor: "blue" }}>
<Typography sx={{ color: "white" }}>CHAT WITH US!</Typography>
</Box>
</MainStyle>
);
}
The problem with this is that half the box is out of the screen and is not all the way to the right.
My goal is to have it all the way in the right corner but also show the entire box like up against the side like https://proxy-seller.com/ have their "chat with us, we are online" just I want it on the right side.
writing-mode: vertical-rl; you can the mentioned css property.
Simple html example for writing-mode: vertical-rl, you can lear more about it from this.
.main {
position: relative;
}
.text {
writing-mode: vertical-rl;
border: 2px solid #000;
position: absolute;
top: 15px;
right: 15px;
height: 120px;
}
<main class="main">
<h1 class="text">Test text</h1>
</main>

Material UI Advanced Button - Text Alignment for Small Screensizes

React / Material-UI Novice here. I am trying to configure a set of buttons inside my app Bar that have a background picture to make it look a little cleaner. I have used a lot of code from examples online (shock) and got it to a place where i am happy with how it has formatted on a full size view (md++). However, when i downsize it to a small breakpoint though, the button image then stack instead (which is what i want) but i lose my text to the left. I have tried shifting to the right in many different ways but i dont think thats the right way to do it, is there something i am missing in making the text flex, i want the text to be in the middle?
import React from 'react'
import { AppBar, Toolbar } from "#mui/material";
import { makeStyles } from '#mui/styles'
import Button from '#mui/material/Button'
import Stack from '#mui/material/Stack'
import ButtonBase from '#mui/material/ButtonBase';
import { styled } from '#mui/material/styles';
import Typography from '#mui/material/Typography';
import Box from '#mui/material/Box';
const useStyles = makeStyles(theme => ({
button: {
...theme.typography.mainmenu,
borderRadius: "40px",
marginLeft: "1px",
height: "45px",
"&:hover": {
backgroundColor: theme.palette.secondary
}
},
}))
const images = [
{
url: '/assets/breakfastMenu.jpg',
title: 'Breakfast',
width: '33.33%',
},
{
url: '/assets/steak.jpg',
title: 'Mains',
width: '33.33%',
},
{
url: '/assets/desserts.jpg',
title: 'Desserts',
width: '33.33%',
},
];
const Image = styled('span')(({ theme }) => ({
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
color: theme.palette.common.primary,
}));
const ImageButton = styled(ButtonBase)(({ theme }) => ({
position: 'relative',
height: 150,
[theme.breakpoints.down('sm')]: {
width: '100% !important', // Overrides inline-style
height: 100,
},
'&:hover, &.Mui-focusVisible': {
zIndex: 1,
'& .MuiImageBackdrop-root': {
opacity: 0.15,
},
'& .MuiImageMarked-root': {
opacity: 0,
},
'& .MuiTypography-root': {
border: '4px solid currentColor',
},
},
}));
const ImageSrc = styled('span')({
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
backgroundSize: 'cover',
backgroundPosition: 'center 40%',
});
const ImageBackdrop = styled('span')(({ theme }) => ({
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
backgroundColor: theme.palette.common.black,
opacity: 0.4,
transition: theme.transitions.create('opacity'),
}));
const ImageMarked = styled('span')(({ theme }) => ({
height: 3,
width: 18,
backgroundColor: theme.palette.common.white,
position: 'absolute',
bottom: -2,
left: 'calc(50% - 9px)',
transition: theme.transitions.create('opacity'),
}));
const Header = () => {
const classes = useStyles();
return (<React.Fragment><AppBar position="sticky" className={classes.appBar}>
<Toolbar disableGutters className={classes.mainToolbar} sx={{ justifyContent: "center" }}>
<Stack direction="row" justifyContent="space-between" alignItems="center" spacing={10}>
{/* <Button variant="contained" color="secondary" className={classes.button}>Breakfast</Button>
<Button variant="contained" color="secondary" className={classes.button}>Mains</Button>
<Button variant="contained" color="secondary" className={classes.button}>Desserts</Button> */}
<Box sx={{ display: 'flex', flexWrap: 'wrap', minWidth: 900, width: '100%' }}>
{images.map((image) => (
<ImageButton
focusRipple
key={image.title}
style={{
width: image.width,
}}
>
<ImageSrc style={{
backgroundImage: `url(${image.url})`
}} />
<ImageBackdrop className="MuiImageBackdrop-root" />
<Image>
<Typography
component="span"
variant="subtitle1"
color="white"
fontWeight="bold"
sx={{
position: 'relative',
p: "7em",
pt: "2em",
pb: (theme) => `calc(${theme.spacing(1)} + 6px)`,
}}
>
{image.title}
<ImageMarked className="MuiImageMarked-root" />
</Typography>
</Image>
</ImageButton>
))}
</Box>
</Stack>
</Toolbar>
</AppBar>
</React.Fragment >
)
}
export default Header
I have moved on from this, but in case anybody finds it, using MUI i completely adapted my application by using:
import useMediaQuery from '#mui/material/useMediaQuery'
and some example like:
const matches = useMediaQuery(theme.breakpoints.down("md"))
to control when the application changes its styles

How can I remove the elevation (box shadow) from a material-ui AppBar over one small section?

I'm trying to get rid of the elevation shadow of the navbar over the sidebar.
I'm using Material-UI's AppBar for my NavBar component.
export default function NavBar() {
return (
<div>
<AppBar position="fixed" elevation={4}>
<Toolbar variant="regular">
<IconButton edge="start" color="inherit" aria-label="menu">
<MenuIcon />
</IconButton>
</Toolbar>
</AppBar>
</div>
);
}
I am using a custom sidebar component,
.sidebar {
left: 0;
top: 64px;
height: 100vh;
width: 70px;
background-color: #3f50b5;
position: fixed;
}
.sidebar::before{
display: none;
}
I don't want to lose the elevation/shadow of the entire NavBar, just the section on the left where it's over the Sidebar.
Adding this because I spent a lot of timing finding a simple answer to removing the elevation.
The simplest way to remove the shadow is by adding elevation prop to the AppBar.
<AppBar position="fixed" elevation={0}>
you could add a ::after pseudo element to your navbar to do the job. This element would have the width of your sidebar, and would be have a top property accordingly to your navbar.
Given the AppBar itself has some different breakpoints you would need to change top accordingly:
const useStyles = makeStyles((theme) => ({
root: {
"&::after": {
position: "absolute",
content: '""',
width: "70px",
height: "8px",
top: "48px",
backgroundColor: theme.palette.primary.main,
[theme.breakpoints.down("xs")]: {
top: "56px"
},
"#media (orientation: landscape)": {
top: "48px"
},
[theme.breakpoints.up("sm")]: {
top: "64px"
}
}
}
}));
export default function NavBar() {
const classes = useStyles();
return (
<div>
<AppBar classes={{ root: classes.root }} position="fixed" elevation={4}>
<Toolbar variant="regular">
<IconButton edge="start" color="inherit" aria-label="menu">
<MenuIcon />
</IconButton>
</Toolbar>
</AppBar>
</div>
);
}
I created a sandbox with only the navbar, and a darker shadow to enhance contrast:

How refacto css class to material-ui class

Hi everyone 😌
I'm using material-UI for a project and i have try to use popover for display metadata of a document but the problem with MUI popover is that they put a z-index of 1500 and block all event like mouseEnter/mouseLeave but I have buttons and collapse on this div my user should be able to use for navigate or display an another infos so after hours to trying to tweak the comportement of the MUI popover I have think about to do it with a pure css component.
For this I have go grab old css from a another project and I'm stuck to pass it into the way MUI accept selector.
My problem is that I don't see how pass this:
.popover__wrapper {
position: relative;
}
.popover__content {
opacity: 0;
visibility: hidden;
position: absolute;
left: -100px;
transform: translate(0, 10px);
background-color: #bfbfbf;
padding: 1.5rem;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26);
width: auto;
text-align: center;
}
.popover__content:before {
position: absolute;
z-index: -1;
content: "";
right: calc(50% - 10px);
top: -8px;
border-style: solid;
border-width: 0 10px 10px 10px;
border-color: transparent transparent #bfbfbf transparent;
transition-duration: 0.3s;
transition-property: transform;
}
.popover__wrapper:hover .popover__content {
z-index: 10;
opacity: 1;
visibility: visible;
transform: translate(0, -20px);
transition: all 0.5s cubic-bezier(0.75, -0.02, 0.2, 0.97);
}
into a MUI css if i can call this like that:
popover__content: {
opacity: 0,
visibility: "hidden",
position: "absolute",
left: "-150px",
transform: "translate(0, 10px)",
width: "100%",
"&:before": {
position: "absolute",
zIndex: "-1",
right: "calc(50% - 10px)",
transitionDuration: "0.3s",
transitionProperty: "transform",
},
"&:hover": {
zIndex: "10",
opacity: "1",
visibility: "visible",
transform: "translate(0, -20px)",
transition: " all 0.5s cubic-bezier(0.75, -0.02, 0.2, 0.97)",
},
},
I have check the MUI theming doc but my brain still stuck on this ..
Thanks by advance for your help have a great day all !
I fix the popover problem with this css and hooks this let me create the behaviors wanted to the DOM :
import React, { useState } from "react"
import { useSelector } from "react-redux"
import {
Grid, List, ListItem, Paper, Typography,
Divider, makeStyles, ListItemIcon,
ListItemText, Box,
} from "#material-ui/core"
import DescriptionIcon from "#material-ui/icons/Description"
const useStyles = makeStyles((theme) => ({
container: {
padding: theme.spacing(1),
borderRadius: theme.spacing(1.5),
background: "#FFFFFF",
boxShadow: "2px 2px 4px rgba(0, 0, 0, 0.0449219)",
},
title: {
color: "#4873c5",
},
paragraph: {
color: "#818181",
},
popover: {
zIndex: 2,
position: "absolute",
top: theme.spacing(-1),
left: theme.spacing(-24),
},
arrowRight: {
width: 0,
height: 0,
borderTop: "10px solid transparent",
borderBottom: "10px solid transparent",
borderLeft: "10px solid black",
position: "absolute",
right: theme.spacing(-1),
top: theme.spacing(2),
},
}))
const stages = [{ name: "Drafting", docs: 15 }, { name: "To Execute", docs: 5 }, { name: "Signature", docs: 10 }]
const tags = [{ name: "HR", docs: 10 }, { name: "Sales", docs: 4 }, { name: "Fundraising", docs: 1 }]
export default function ActiveDocuments() {
const classes = useStyles()
const documents = useSelector(state => state.documents)
const [popoverDetails, setPopoverDetails] = useState(null)
const onMouseLeaveDetails = (e) => {
if (e.relatedTarget.id === "activeDocumentsContainer")
return
setPopoverDetails(null)
}
// in case moving precisely on the diagonal of arrow
const hoverProtection = () => {
if (popoverDetails)
setPopoverDetails(null)
}
return (
<>
<Paper style={{ padding: 16 }} onMouseEnter={hoverProtection} id="activeDocumentsContainer">
<Box display="flex">
<Typography style={{ fontWeight: "bold", flexGrow: 1 }}>Active Documents</Typography>
<Typography>{documents.length}</Typography>
</Box>
<List id="testlist">
{stages.map((stage, idx) => (
<ListItem disableGutters key={idx}>
<div onMouseOver={() => setPopoverDetails(stage.name)}
onMouseLeave={onMouseLeaveDetails}>
<Typography className={classes.title}>
{stage.name}
</Typography>
{popoverDetails === stage.name && (
<Paper className={classes.popover} onMouseLeave={() => setPopoverDetails(null)}>
<div className={classes.arrowRight} />
<List>
{tags.map((tag, idx) => (
<ListItem key={idx}>
<Typography className={classes.title}>{tag.name}</Typography>
</ListItem>
))}
</List>
<Box>
<Typography style={{ fontWeight: "bold" }}>Latest Documents</Typography>
<List>
{documents.map((document, idx) => (
<ListItem key={idx}>
<ListItemIcon style={{ color: "#4873c5" }}>
<DescriptionIcon />
</ListItemIcon>
<ListItemText className={classes.title}>{document.filename}</ListItemText>
</ListItem>
))}
</List>
</Box>
</Paper>
)}
</div>
</ListItem>
))}
</List>
</Paper>
<List>
<ListItem>
<Grid container>
<Grid item xs={12} sm={12} md={12} lg={12} xl={12}>
<Typography className={classes.title}>Template</Typography>
</Grid>
<Grid item xs={12} sm={12} md={12} lg={12} xl={12}>
<Typography className={classes.paragraph} variant="body2">5 new this week</Typography>
</Grid>
</Grid>
</ListItem>
<Divider varient="fullWidth" style={{ backgroundColor: "#dcdee1" }} />
<ListItem>
<Grid container>
<Grid item xs={12} sm={12} md={12} lg={12} xl={12}>
<Typography className={classes.title}>Signed</Typography>
</Grid>
<Grid item xs={12} sm={12} md={12} lg={12} xl={12}>
<Typography className={classes.paragraph} variant="body2">8 new this week</Typography>
</Grid>
</Grid>
</ListItem>
</List>
</>
)
}
I gonna open an issue on MUI github repo for ask them to fix this annoying behavior in the popover component.

React / Material UI - <CardHeader> css

Using React & Material UI I'm trying to layout 3 divs within a <Card> <CardHeader/> such that it has a left, center and right alignment respectively as shown below.
The change is trivial, I need to remove the padding and change to display: inherit but it seems this <div> exists between the exposed style & titleStyle for <CardHeader> and <CardHeader title={someElement}/>
The hierarchy looks like:
...<div><div.myCardHeader><div><span><myTitleElement>...
Being so new to React and styles, I'm unsure how to get to it.
Some representative code follows.
Thanks for help.
// #flow
import React, { Component } from 'react';
import Paper from 'material-ui/Paper';
import { Card, CardActions, CardHeader, CardMedia, CardTitle, CardText } from 'material-ui/Card';
const style = {
paper: {
height: 250,
width: 200,
margin: 20,
},
card: {
header: {
container: {
display: 'flex', /* establish flex container */
justifyContent: 'space-between',
backgroundColor: 'lightblue'
},
padding: 1,
height: 26
}
}
};
const POCardTitle = () => (
<div className="myContainer" style={style.card.header.container}>
<div style={{ width: 25, height: 26, border: '2px dashed red' }}> - </div>
<div style={{ width: 25, height: 26, border: '2px dashed blue' }}> - </div>
<div style={{ width: 25, height: 26, border: '2px dashed green' }}> - </div>
</div>
);
export default class POCard extends Component {
render() {
return (
<div>
<Paper style={style.paper} zDepth={2} >
<Card >
<CardHeader className="myCardHeader"
style={style.card.header}
titleStyle={{ paddingRight: 0, display: 'inline' }}
title={<POCardTitle />}
/>
</Card>
</Paper>
</div>
);
}
}
I managed to get there courtesy of https://www.styled-components.com
and the following:
const StyledHeader = styled(CardHeader) `
padding: 0px !important;
height: 26px !important;
> div {
display: inherit !important;
padding-right: 0px !important;
}
`;
I could find no other way to get to the "first div" after the component through regular CSS...

Resources