-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ClickAwayListener] Fix support for portal (#20406)
- Loading branch information
1 parent
e271861
commit a2b2463
Showing
10 changed files
with
263 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
docs/src/pages/components/click-away-listener/PortalClickAway.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import ClickAwayListener from '@material-ui/core/ClickAwayListener'; | ||
import Portal from '@material-ui/core/Portal'; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
dropdown: { | ||
position: 'fixed', | ||
width: 200, | ||
top: '50%', | ||
left: '50%', | ||
transform: 'translate(-50%, -50%)', | ||
border: '1px solid', | ||
padding: theme.spacing(1), | ||
backgroundColor: theme.palette.background.paper, | ||
}, | ||
})); | ||
|
||
export default function PortalClickAway() { | ||
const classes = useStyles(); | ||
const [open, setOpen] = React.useState(false); | ||
|
||
const handleClick = () => { | ||
setOpen((prev) => !prev); | ||
}; | ||
|
||
const handleClickAway = () => { | ||
setOpen(false); | ||
}; | ||
|
||
return ( | ||
<ClickAwayListener onClickAway={handleClickAway}> | ||
<div> | ||
<button type="button" onClick={handleClick}> | ||
Open menu dropdown | ||
</button> | ||
{open ? ( | ||
<Portal> | ||
<div className={classes.dropdown}> | ||
Click me, I will stay visible until you click outside. | ||
</div> | ||
</Portal> | ||
) : null} | ||
</div> | ||
</ClickAwayListener> | ||
); | ||
} |
49 changes: 49 additions & 0 deletions
49
docs/src/pages/components/click-away-listener/PortalClickAway.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
import { makeStyles, createStyles, Theme } from '@material-ui/core/styles'; | ||
import ClickAwayListener from '@material-ui/core/ClickAwayListener'; | ||
import Portal from '@material-ui/core/Portal'; | ||
|
||
const useStyles = makeStyles((theme: Theme) => | ||
createStyles({ | ||
dropdown: { | ||
position: 'fixed', | ||
width: 200, | ||
top: '50%', | ||
left: '50%', | ||
transform: 'translate(-50%, -50%)', | ||
border: '1px solid', | ||
padding: theme.spacing(1), | ||
backgroundColor: theme.palette.background.paper, | ||
}, | ||
}), | ||
); | ||
|
||
export default function PortalClickAway() { | ||
const classes = useStyles(); | ||
const [open, setOpen] = React.useState(false); | ||
|
||
const handleClick = () => { | ||
setOpen((prev) => !prev); | ||
}; | ||
|
||
const handleClickAway = () => { | ||
setOpen(false); | ||
}; | ||
|
||
return ( | ||
<ClickAwayListener onClickAway={handleClickAway}> | ||
<div> | ||
<button type="button" onClick={handleClick}> | ||
Open menu dropdown | ||
</button> | ||
{open ? ( | ||
<Portal> | ||
<div className={classes.dropdown}> | ||
Click me, I will stay visible until you click outside. | ||
</div> | ||
</Portal> | ||
) : null} | ||
</div> | ||
</ClickAwayListener> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.