labelPlacement of MUI FormControlLabel not working - javascript

I'm using the FormControlLabel component from MUI and the label is always getting placed at the end, even if I set the labelPlacement prop to "start", "top" or "bottom".
This is my code:
<FormControlLabel
label="Connected account"
labelPlacement="start"
control={
<MDBox display="inline">
<MDTypography variant="caption" mr={2}>
Account Name
</MDTypography>
<MDButton
color="error"
size="small"
sx={{ m: "0.25rem" }}
onClick={() => disconnectAccount(idAccount)}
>
<MDTypography
fontSize="0.6rem"
color="white"
fontWeight="bold"
textTransform="uppercase"
>
Remove Account
</MDTypography>
</MDButton>
</MDBox>
}
sx={{
backgroundColor: "#f7fafc",
mb: "1rem",
borderRadius: "0.5rem",
pl: "1rem"
}}
/>
This is what the UI looks like with labelPlacement set to "end" and "start", respectively, meaning a left margin is added when set to "start":
Am I missing something here?

Related

Pass control prop to child component in react hook form

I'm trying to pass the control prop to my custom component that comes from react-hook-form but it tells that the control is undefined
I did the same thing written in document. I used FormProvider like this:
<FormProvider {...methods}>
<form
style={{
height: "auto",
width: "90%",
padding: "2em",
paddingTop: "0",
textAlign: "center",
backgroundColor: "white",
borderRadius: "10px",
}}
onSubmit={methods.handleSubmit((data) => console.log(data))}
>
<IconButton
color="error"
onClick={() => setRecordControl({ stat: "" })}
>
<Cancel fontSize="large" />
</IconButton>
<h3 style={{ marginBottom: "10px", textAlign: "center" }}>
saving records
</h3>
{filtered.ListColumnInfo.map(
(detail) =>
detail.VisibleColumn && (
<div key={uuidV4()}>
<CustomTextBoxComponent
filtered={detail}
/>
</div>
)
)}
<Button
variant="contained"
fullWidth
color="success"
sx={{ mt: "1em" }}
type="submit"
>
save
</Button>
</form>
</FormProvider>
and I tried to retrieve the control inside of my CustomTextBoxComponent like this:
const CustomTextBoxComponent = ({ filtered }) => {
const { control } = useFormContext();
return (
<Controller
name="input"
render={({ field }) => (
<TextField
fullWidth
placeholder={
filtered.ElsRecord.PersianName !== ""
? filtered.ElsRecord.PersianName
: filtered.ElsRecord.Name
}
sx={{ marginBlock: "1em" }}
{...control}
{...field}
/>
)}
defaultValue=""
/>
);
};
it didn't work. always says the method is null
the picture of Error
how can I solve it?

MUI CardContent and flexBox doesn't work with typography and chip

Below is react code made with MUI. The aim is to create a Card that displays Character Information.
const CharacterPreview = ({ characterKey }: CharacterPreviewProps) => {
return (
<Card sx={{ maxWidth: 256, borderRadius: 4 }}>
<Box
component="a"
href={`/#/${characterKey}`}
display="flex"
position="relative"
sx={{
"&::before": {
content: '""',
display: "block",
position: "absolute",
left: 0,
top: 0,
width: "100%",
height: "100%",
opacity: 0.7,
backgroundImage: `url(${bannerImgUrl})`,
backgroundPosition: "center",
backgroundSize: "cover",
},
}}
width="100%"
>
<Box
flexShrink={1}
sx={{ maxWidth: { xs: "40%", lg: "40%" } }}
alignSelf="flex-end"
display="flex"
flexDirection="column"
zIndex={1}
>
<Box
component="img"
src={iconImgUrl}
width="100%"
height="auto"
maxWidth={256}
sx={{ mt: "auto" }}
/>
</Box>
</Box>
<CardContent>
<Typography variant="h5" component="div">
{characterName}
</Typography>
{/* <Typography variant="body2" color="text.secondary"> */}
{/* {characterInfo.title as string} */}
{/* </Typography> */}
<Chip
label={characterChipInfo}
size="small"
/>
</CardContent>
</Card>
);
};
This is what the final result looks like:
I want the chip component (reads as CRYO in the image and is characterChipInfo in the above code) to be on the same line as the characterName and be separated like a space-between flexbox, however using the Box component with flex-box and justifyContent="space-between" to encase the name Typography and Chip doesn't work. I've also tried along with it changing the Typography display to inline-flex and inline-block, which makes them on the same line but the Box's justifyContent=space-between doesn't work.
You need to use a Stack component of Material UI like so:
CodeSandBox
<Stack
direction="row"
spacing={2}
justifyContent="space-between"
alignItems="center"
>
<Typography variant="h5" component="div">
{characterName}
</Typography>
{/* <Typography variant="body2" color="text.secondary"> */}
{/* {characterInfo.title as string} */}
{/* </Typography> */}
<Chip
label={characterChipInfo}
size="small"
/>
</Stack>

How to center the text in MUI Breadcrumbs

I am using MUI Breadcrumb in my Code. I want to center the Content in Breadcrumb. I Try this code
<BreadcrumbStyle style={{marginTop:30}}>
<Card elevation={3} style={{padding:10}}>
<Breadcrumbs separator={<NavigateNextIcon fontSize="small" />} aria-label="breadcrumb" >
<Link underline="hover" color="inherit" href="/" sx={{ display: "flex", alignItems: "center" }} ><HomeIcon sx={{ mr: 0.5 }} fontSize="inherit" /> Home </Link>
<Typography >Projects </Typography>
<Typography style={{color:"blue", fontWeight:"bold",}} noWrap >React JS Web Application</Typography>
</Breadcrumbs>
</Card>
</BreadcrumbStyle>
I want to center the content in Breadcrumb. I need the expected output
The content is left-aligned by the flex container, not by text-align.
You should be able to fix it by adding this to the Breadcrumbs component:
<Breadcrumbs
separator={<NavigateNextIcon fontSize="small" />}
aria-label="breadcrumb"
sx={{
"& ol": {
justifyContent: "center",
margin: "auto"
}
}}
>
Try style={{textAlign:"center" }} in the Card tag.

How do I change the zAxis of a Paper from MUI?

Hello I want to know how do you change the zAxis of a paper from MUI
As you can see the carousel overlaps my menu and I would like my menu to be on top of everything.
This is how I have it wrapped:
<Box sx={{ background: '#272A31', flexGrow: 0, display: { xs: 'none', md: 'flex' } }}>
<StyledIconButton size="small" edge="start" color="inherit" aria-label="menu" sx={{ mr: 2 }} onClick={handleToggle} ref={anchorRef} >
<GamesIcon />
<Typography variant="h6" component="div" sx={{ flexGrow: 1 }}> GAMES </Typography>
<Popper open={open} anchorEl={anchorRef.current} role={undefined} placement="bottom-start" transition disablePortal >
{({ TransitionProps, placement }) => (
<Grow {...TransitionProps}
style={{
transformOrigin: placement === 'bottom-start' ? 'left top' : 'left bottom',
}}
>
<StyledPaper sx = {{zIndex: 1600}} >
<ClickAwayListener onClickAway={handleClose}>
<MenuList autoFocusItem={open} id="composition-menu" aria-labelledby="composition-button" onKeyDown={handleListKeyDown}>
<StyledMenuItem onClick={handleClose}>JUNGLE RAIDER</StyledMenuItem>
<StyledMenuItem onClick={handleClose}>MEGAMAN TEMPLATE</StyledMenuItem>
<StyledMenuItem onClick={handleClose}>TOWER DEFENSE</StyledMenuItem>
<StyledMenuItem onClick={handleClose}>BLADES AND DUNGEON</StyledMenuItem>
<StyledMenuItem onClick={handleClose}>FIXSPACE</StyledMenuItem>
</MenuList>
</ClickAwayListener>
</StyledPaper>
</Grow>
)}
</Popper>
</StyledIconButton>
</Box>
While my Carousel is wraped in the following way:
<Box mb = {2} mt = {2} sx={{display: 'flex', justifyContent: 'center', alignItems: 'center', zIndex: -1}}>
<Card sx={{ width: 1500, backgroundColor: "transparent"}} >
<Carousel fullHeightHover={false} navButtonsAlwaysVisible={true} duration={500} animation="slide"
navButtonsProps={{
style: {
backgroundColor: '#FF5917',
borderRadius: 0,
}
}} >
{items.map( (item, i) => <Item key={i} item={item} />)}
</Carousel>
</Card>
</Box>
Even though the paper is at z-(1600) and the carousel box at z-(-1) it still overlaps the paper for some reason
https://mui.com/customization/z-index/ check this link. tooptip has highest zindex value. you can add it to your popper

How can I add MUI theme color to inline style?

Lets say I have these tabs below. How can I use the MUI primary and secondary colors for inline CSS? I would like to use colors from my palette to customize this.
<Tabs
value={value}
onChange={handleChange}
variant='fullWidth'
aria-label="simple tabs example"
className="tableViewTabs"
centered
color="primary"
// inkBarStyle={{backgroundColor: '#68C222', width: '33.3%'}}
// tabItemContainerStyle={{backgroundColor: '#FFFFFF', width: '30%'}}
>
<Tab
icon={<GradeIcon/>}
{...a11yProps(0)}
disableFocusRipple={true}
disableRipple = {true}
color="primary"
style={{ textTransform: "none", fontSize: 16, color: value === 0 ? "" : "" }}
/>
<Tab
icon={<ViewAgendaIcon />}
{...a11yProps(1)}
disableFocusRipple={true}
disableRipple={true}
style={{ textTransform: "none", fontSize: 16, fontWeight: value === 1 ? "bold" : "" }}
/>
<Tab
icon={<AppsIcon />}
{...a11yProps(2)}
disableFocusRipple = {true}
disableRipple = {true}
style={{ textTransform: "none", fontSize: 16, fontWeight: value === 2 ? "bold" : "" }}
/>
If you need to use inline styles, you can get the theme object via useTheme hook.
const theme = useTheme()
The theme object contains all data about Material-UI theme like color palette, breakpoints, zIndex... You can inspect the DefaultTheme object here.
return <Tabs {...props} style={{ backgroundColor: theme.palette.primary.main }} />
In MUI v5, you can use the sx prop to quickly add dynamic styles as an alternative to inline styles. It also has better integration with MUI theme as demonstrated by the following examples:
<Box sx={{ color: 'text.secondary' }}>Text</Box>
<div style={{ color: theme.palette.text.secondary }}>Text</Box>
<Box sx={{ border: 1 }}>Text</Box>
<div style={{ border: '1px solid black' }}>Text</Box>
<Box sx={{ borderRadius: 2 }}>Text</Box>
<div style={{ borderRadius: theme.shape.borderRadius * 2 }}>Text</Box>
<Box sx={{ mx: 2 }}>Text</Box>
<div style={{ margin: `0 ${theme.spacing(2)}` }}>Text</Box>
<Box sx={{ fontWeight: 'fontWeightLight' }}>Text</Box>
<div style={{ fontWeight: theme.typography.fontWeightLight }}>Text</Box>
<Box sx={{ zIndex: 'tooltip' }}>Text</Box>
<div style={{ zIndex: theme.zIndex.tooltip }}>Text</Box>
<Box sx={{ boxShadow: 1 }}>Text</Box>
<div style={{ boxShadow: theme.shadows[1] }}>Text</Box>

Categories

Resources