這是 Header.js,其中有按鈕<ReactSvg>,<IconButton>當您單擊它時,它將使用該switchTheme()功能更改頁面主題。當您將鼠標懸停在按鈕上時,它還有一個popover聲明按鈕功能的位置(例如切換主題)。由于某種原因,我將鼠標懸停popover在出現的按鈕上,但即使我單擊得非常快且有力,也不讓我單擊該按鈕。不知何故,該popover按鈕已禁用。呈現按鈕的頭文件:import React, { useState } from 'react'import ReactSvg from './reactSvg'import { Box, Typography, Link, Container, IconButton } from '@material-ui/core'import PhoneIcon from '@material-ui/icons/Phone'import EmailIcon from '@material-ui/icons/Email'import GitHubIcon from '@material-ui/icons/GitHub'import LinkedInIcon from '@material-ui/icons/LinkedIn'import { useStyles } from '../styles/customStyles'import Image from 'material-ui-image'import PopOver from './PopOver'const styles = { image: { maxWidth: 200, minWidth: 200, },}export default function Header({ switchTheme }) { const classes = useStyles() const [anchorEl, setAnchorEl] = useState(null) const handleTheme = () => { switchTheme() } const handleHover = (e) => { setAnchorEl(e.currentTarget) } return ( <> <Box> <IconButton onClick={() => handleTheme()} onMouseOver={(e) => handleHover(e)}> <ReactSvg /> </IconButton> <Typography variant="h3" color="primary"> Staz Christodoulakis </Typography> <Typography variant="body1" color="primary"> Software Engineer · Web/App </Typography> <hr className="solid" /> <Box display="flex" alignItems="center" justifyContent="center" className={classes.root} flexWrap="wrap" > <Link color="secondary" variant="body1" href="tel: 650-409-6202"> <Box display="flex"> <PhoneIcon /> 650 409 6202 </Box> </Link>為什么 onMouseOver 事件會阻塞 onClick 事件?
由 onMouseOver 觸發的 Material-UI 彈出窗口阻止按鈕的 onClick 事件
浮云間
2023-08-18 16:41:54