Mui popover'children well positionned but popover goes left - material-ui

I am trying to do a custom mui popover. My custom popover's children are set on the right place but the popover component it self is placed on top left of the screen.
I use forward ref to pass the initial ref to children to two neested level.
I have a Navbar that contains a button to witch i attach the ref, a second component that is my customPopover, in my customPopover it returns a popover containing children passed by customPopover: the code of my CustomPopover:
<AppPopoverArrow
open={open}
ref={ref}
placement={"bottom-end"}
>
<Card className={classes.card}>
<CardHeader
sx={{marginBottom: "20px"}}
title={<Typography sx={{marginBottom: "5px"}} variant="subtitle1">Add a new collaborator</Typography>}
subheader={ <Typography variant="subtitle2">Please enter the email adress to receive the invitation</Typography>
}
/>
<CardContent className={classes.cardContent}>
<TextField sx={{height: 35, width: 320, marginBottom: "20px"}} placeholder="Email" onKeyDown={e => addAdress(e)}/>
{ adresses && <Typography variant="subtitle1" sx={{marginBottom: "15px"}}>{adresses.length} emails adresses added</Typography>}
{ adresses && adresses.map((email: string) => <Typography variant="subtitle2">{email}</Typography>) }
</CardContent>
<div className={classes.cardActionsArea}>
<CardActions>
<CustomButton onClick={onClose} color="secondary">
Cancel
</CustomButton>
<CustomButton onClick={onAddUser} variant="contained" color="primary" disabled={!adresses}>
Add
</CustomButton>
</CardActions>
</div>
</Card>
</AppPopoverArrow>

Related

Textfield Material UI is requiring more than 1 click to work properly

I have a page on my application where there is a DataGrid and some textField to update data from the DataGrid.
The DataGrid has checkbox on each row.
The problem is:
If I just enter the page and select any checkbox and then click on any TextField, the TextField's label goes up and quickly down to default position. I need to click again on the TextField to type anything I want. This problem does not happend if I dont click on any checkbox.
My front end
<div className="main">
<Typography>You are at Update Page</Typography>
<p></p>
<div style={{ height: 300, width: '100%', backgroundColor: '' }}>
<DataGrid
rows={rows}
columns={columns}
pageSize={5}
checkboxSelection
onSelectionModelChange={(itemIdselected) => window.localStorage.setItem('id', itemIdselected)}
>
</DataGrid>
</div>
<p></p>
<Typography>First select which user you want to update</Typography>
<p></p>
<form onSubmit={handleSubmit(OnSubmitUpdate)}>
<TextField label='New name' {...register('Name')} color="primary" style={{ width: '10%' }}></TextField>
<p className="errors">{errors.Name?.message}</p>
<TextField label='New email' {...register('Email')} color="primary" style={{ width: '10%' }}></TextField>
<p className="errors">{errors.Email?.message}</p>
<TextField label='New password' type={'password'} {...register('Password')} color="primary" style={{ width: '10%' }}></TextField>
<p className="errors">{errors.Password?.message}</p>
<ButtonComponent text="Update" type='submit'></ButtonComponent>
<p></p>
<Link to="/" style={{ textDecoration: 'none' }}><ButtonComponent text="Return"></ButtonComponent></Link>
</form>
</div>

How to disable long click effect on a material-ui button?

I have this btn with an icon insdie of it i click for a long time it created and undesiered effect around the icon any clue how to remove this action ?
import React from "react";
import ReactDOM from "react-dom";
import Button from "#material-ui/core/Button";
import ViewListIcon from "#material-ui/icons/ViewList";
function App() {
return (
<div>
<Button style={{ MuiButtonBase: { disableRipple: true } }}>
<ViewListIcon />
</Button>
</div>
);
}
ReactDOM.render(<App />, document.querySelector("#app"));
CodeSandbox
Add disableRipple prop to Button
<Button disableRipple>
<ViewListIcon />
</Button>
According to docs, the prop disableRipple on MUI Buttons, such as Button or IconButton disable ripple effect.
<Button disableRipple>
<ViewListIcon />
</Button>
By default, a ripple is activated when the host element of the matRipple directive receives mouse or touch events. Upon being pressed, a ripple will begin fading in from the point of contact, radiating to cover the host element. Each ripple will fade out only upon release of the mouse or touch.
Without a ripple there is no styling for :focus-visible by default. Be sure to highlight the element by applying separate styles with the .Mui-focusVisible class.
Read more about this here: Ripple.

How to put Button in endAdornment in Material UI Input (like one can do it in TextField)

It is possible to put button in endAdornment in TextField, e.g. with code:
<TextField size="small" type="text" id="m_general_reference" value={this.props.invoice.general_reference}
InputProps={{
endAdornment: (
<InputAdornment>
<Button variant="outlined" size="small" style={{textTransform: 'none', height: '20px'}}>
Check General Reference
</Button>
</InputAdornment>
)
}} />
But this code does not work when TextField is changed to Input. Is there more or less standard markup to put endAdornment button in InputField? I am interested in more or less standard solution only and no hacks (in case of hacks I will go with TextField).

Material UI React - modal data in loop is only showing the last iteration data

I have a list of blog posts. When you click the title of a post a modal opens up to show the entire post. The Material UI React modal is only showing the data from the last iteration no matter which title was picked. Shouldn't the modal data be based on the iteration of the loop?
In my example there are 3 posts. I put the post.id to show which post the modal is for, just for testing, and all 3 posts show 3. Not 1, 2, 3 etc. Any help is appreciated!
{blogs.map(post => (
< Card className = { classes.root } variant = "outlined" >
<CardContent>
<Typography variant="h4" component="h2">
<span onClick={handleOpen}>{post.title}</span>
</Typography>
<Modal
aria-labelledby="transition-modal-title"
aria-describedby="transition-modal-description"
className={classes.modal}
open={open}
onClose={handleClose}
closeAfterTransition
BackdropComponent={Backdrop}
BackdropProps={{
timeout: 500,
}}
>
<Fade in={open}>
<div className={classes.paper}>
{post.id}
</div>
</Fade>
</Modal>
<Typography className={classes.pos} color="textSecondary">
Posted: {post.published} | Author: {post.author}
</Typography>
</CardContent>
</Card>

material-ui Snackbar component error : <div> cannot appear as a descendant of <p>

I'm using a very simple sample of the material ui Snackbar component, that renders the following HTML
<div class="MuiSnackbar-root-352 MuiSnackbar-anchorOriginBottomLeft-358">
<p class="MuiTypography-root-199 MuiTypography-body2-207 MuiPaper-root-121 MuiPaper-elevation6-129 MuiSnackbarContent-root-373" role="alertdialog" aria-describedby="message-id" direction="up" style="transform: translate(0px, 0px); transition: transform 225ms cubic-bezier(0, 0, 0.2, 1) 0ms;">
<div class="MuiSnackbarContent-message-374">
<span id="message-id">TunisiaNet created!</span>
</div>
</p>
</div>
for the following code
<Snackbar
anchorOrigin={{
vertical: 'bottom',
horizontal: 'left',
}}
open={this.state.entityGroupAdded}
autoHideDuration={4000}
onClose={this.handleClose}
ContentProps={{
'aria-describedby': 'message-id',
}}
message={<span id="message-id">{this.state.name} created!</span>}
/>
This naturally leads to an HTML specification incompatibility. The issue is that I don't know how to tell the Snackbar to create a div instead of a p element
I get the error:
0.chunk.js:101009 Warning: validateDOMNesting(...): <div> cannot appear as a descendant of <p>.
in div (created by SnackbarContent)
in p (created by Typography)
in Typography (created by WithStyles(Typography))
in WithStyles(Typography) (created by Paper)
in Paper (created by WithStyles(Paper))
in WithStyles(Paper) (created by SnackbarContent)
in SnackbarContent (created by WithStyles(SnackbarContent))
Might wanna check your Material UI version or any override settings you might have made which includes typography components. I just tested a snackbar with the exact same code and the p tag (which uses typography, this part is causing the error) does not exist as a p tag but a different classname
<div class="MuiSnackbar-root-185 MuiSnackbar-anchorOriginBottomLeft-191">
<div class="MuiTypography-root-313 MuiTypography-body1-322 MuiPaper-root-20 MuiPaper-elevation6-28 MuiSnackbarContent-root-310" role="alertdialog" aria-describedby="message-id" style="transform: translate(0px, 0px); transition: transform 225ms cubic-bezier(0, 0, 0.2, 1) 0ms;">
<div class="MuiSnackbarContent-message-311">
<span id="message-id">Note archived</span></div>
</div>
For other who is looking for an answer other than something wrong with the overrides, most likely if nothing wrong with your overrides, and even before you check for that. Look into your code if it contain a component that inherit the props of Typography component like DialogContentText and you also have another Typography component or a component that will transfer to <p> tag in HTML as a child of that component.
In the the error above message props will become
<p class="MuiTypography-root-199 MuiTypography-body2-207 MuiPaper-root-121 MuiPaper-elevation6-129 MuiSnackbarContent-root-373" role="alertdialog" aria-describedby="message-id" direction="up" style="transform: translate(0px, 0px); transition: transform 225ms cubic-bezier(0, 0, 0.2, 1) 0ms;">
<div class="MuiSnackbarContent-message-374">
<span id="message-id">TunisiaNet created!</span>
</div>
</p>
I think this is not showing anymore in the new versions of material. But if you want to fix something like that take a look;
This will give errors
const someFunction= (): JSX.Element => {
return (
<DialogTitle>
Some title
</DialogTitle>
<DialogContentText>
<Typography variant='h5'>
Sometext
<Typography />
</DialogContentText>
<TextField
autoComplete='off'
margin='dense'
variant="outlined"
id='name'
label='email'
type='email'
fullWidth
/>
);
};
this will fix it
const someFunction= (): JSX.Element => {
return (
<DialogTitle>
Some title
</DialogTitle>
<DialogContentText variant='h5'>
Sometext
</DialogContentText>
<TextField
autoComplete='off'
margin='dense'
variant="outlined"
id='name'
label='email'
type='email'
fullWidth
/>
);
};
In this case for example you can use the normal props of Typography with DialogContentText.
Also you can user component='div' as prop of Typography, it could fix it, I didn't test