- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们创建了一个通知系统,它使用带有操作按钮和关闭按钮的 Material ui Snackbar。我为 enter
添加了一个监听器事件,以便特定通知的操作将触发并关闭 Snackbar。我遇到的问题是执行此操作后,chrome 的默认行为仍然具有触发通知的按钮。如果按下回车,它不仅会触发通知,还会触发通知中的操作按钮。关于如何防止这种情况有什么建议吗?
import React from 'react';
import { connect } from 'react-redux';
import { withStyles } from '@material-ui/core/styles';
import IconButton from '@material-ui/core/IconButton';
import DeleteIcon from '@material-ui/icons/Delete';
import Tooltip from '@material-ui/core/Tooltip';
import { NotifierConfirm, enqueueInfo } from '@paragon/notification-tools';
import { deleteDocument } from '../../actions/documents';
import { getSelectedDocument } from '../../selectors/documents';
import { jobIsLocked } from '../../modules/jobLocking'; // eslint-disable-line
const styles = ({
border: {
borderRadius: 0,
},
});
class DeleteDocument extends React.Component {
state = {
deleteDocumentOpen: false,
}
onDeleteFile = () => {
if (jobIsLocked()) {
return;
}
this.setState({ deleteDocumentOpen: true });
}
closeDeleteDocument = () => {
this.setState({ deleteDocumentOpen: false });
};
onConfirmDelete = () => {
this.props.onDeleteFile(this.props.selectedDocument.id);
this.setState({ deleteDocumentOpen: false });
}
render() {
const { classes } = this.props;
return (
<div>
<Tooltip disableFocusListener id="delete-tooltip" title="Delete Document">
<div>
<IconButton
className={`${classes.border} deleteDocumentButton`}
disabled={(this.props.selectedDocument == null)}
onClick={this.onDeleteFile}
>
<DeleteIcon />
</IconButton>
</div>
</Tooltip>
<NotifierConfirm
open={this.state.deleteDocumentOpen}
onClose={this.closeDeleteDocument}
onClick={this.onConfirmDelete}
message="Are you sure you want to DELETE this document?"
buttonText="Delete"
/>
</div>
);
}
}
const mapStateToProps = (state) => {
const selectedDocument = getSelectedDocument(state);
return {
selectedDocument,
};
};
function mapDispatchToProps(dispatch) {
return {
onDeleteFile: (documentId) => {
dispatch(deleteDocument(documentId));
},
enqueueInfo,
};
}
export default connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(DeleteDocument));
import React from 'react';
import { withStyles, WithStyles, StyleRulesCallback } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
import Snackbar from '@material-ui/core/Snackbar';
import IconButton from '@material-ui/core/IconButton';
import CloseIcon from '@material-ui/icons/Close';
import RootRef from '@material-ui/core/RootRef';
interface NotifierConfirmProps {
open: boolean;
onClose: any;
onClick: () => void;
message: string;
messageSecondary?: any;
buttonText: string;
}
type OwnProps = NotifierConfirmProps & WithStyles<typeof styles>;
const styles: StyleRulesCallback = () => ({
snackbar: {
marginTop: 85,
zIndex: 10000000,
'& div:first-child': {
'& div:first-child': {
width: '100%',
},
},
},
close: {
padding: 8,
marginLeft: 8,
},
buttonColor: {
backgroundColor: '#F3D06E',
},
messageDiv: {
width: '100%',
}
});
class NotifierConfirmComponent extends React.Component<OwnProps> {
notifierRef: React.RefObject<{}>;
constructor(props: OwnProps) {
super(props);
// create a ref to store the textInput DOM element
this.notifierRef = React.createRef();
this.focusNotifier = this.focusNotifier.bind(this);
}
keyPressHandler = (event: any) => {
if (!this.props.open) return;
if (event.keyCode === 27) {
this.props.onClose();
}
if (event.keyCode === 13) {
this.props.onClick();
}
}
focusNotifier() {
// Explicitly focus the text input using the raw DOM API
// Note: we're accessing "current" to get the DOM node
// this.notifierRef.current.focus(); this will not work
}
componentDidMount() {
document.addEventListener('keyup', this.keyPressHandler, false);
}
componentWillUnmount() {
document.removeEventListener('keyup', this.keyPressHandler, false);
}
render() {
const { classes } = this.props;
return (
<React.Fragment>
<RootRef rootRef={this.notifierRef}>
<Snackbar
className={classes.snackbar}
anchorOrigin={{
vertical: 'top',
horizontal: 'center',
}}
open={this.props.open}
onClose={this.props.onClose}
ContentProps={{
'aria-describedby': 'message-id',
}}
message={
<div className={classes.messageDiv} id="message-id">
{this.props.message}<br />
{this.props.messageSecondary}
</div>}
action={[
<Button
className={`${classes.buttonColor} confirmActionButton`}
variant="contained"
key={this.props.buttonText}
size="small"
onClick={this.props.onClick}
>
{this.props.buttonText}
</Button>,
<IconButton
key="close"
aria-label="Close"
color="inherit"
className={classes.close}
onClick={this.props.onClose}
>
<CloseIcon />
</IconButton>,
]}
/>
</RootRef>
</React.Fragment>
);
}
}
export const NotifierConfirm = withStyles(styles)(NotifierConfirmComponent);
最佳答案
在您的回调中,您应该调用 Event.preventDefault()
或 Event.stopPropagation()
,值得注意的是这两者并不相同。这里的文档:Prevent Default , Stop Propagation
关于reactjs - 如何防止 keyup 事件冒泡到 MUI Snackbar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55619944/
我已将 MUI 从 v4 升级到 v5。但是,我现在很难理解主题如何与可用的不同主题解决方案一起使用。我不太明白在哪里使用 MUI 主题/样式组件以及何时使用情感组件。 在新组件中,我使用 sx 属性
早上好, 我爱上了 MUI,有很多事情可以做。但是,在广泛使用它之后,我注意到 MUI Divider 在它是 Container 或 Paper 组件的子组件时不会显示。我找不到任何关于为什么会这样
我使用 MUI 在我的 React.JS 元素的索引中创建了一个主题。当我尝试将我的风格应用到我的 Appbar主题没有正确修改菜单按钮或菜单本身。按钮看起来是通用的默认值,当它应该与 Appbar
我已经查看了许多关于弹出框 anchor 定的问题,但是在使用 Material 表库中的 MaterialTable 元素时我没有看到任何问题:https://github.com/mbrn/mat
在 Material-UI v5 中,一些 API 使用是从 @mui/material/styles 导入的, 喜欢 useTheme .并且一些 API 使用是从 @mui/styles 导入的,
这个问题在这里已经有了答案: Use calc() function in makeStyles (1 个回答) 10 个月前关闭。 这篇帖子在10个月前被编辑并提交审核,并且未能重新打开该帖子: 原
我想覆盖全局 .Mui-disabled我的主题中的 CSS 规则覆盖。我可以为这样的特定组件执行此操作(在 Material-UI v4.1.x 中): MuiTheme['overrides']
我可能有一个由来已久的问题,但我的按钮无法配合!这是我第一次使用 MUI,所以可能有些地方我不明白。 请看sandbox . 我希望按钮在一行中居中,中间有一点空间。我真的以为 会起作用,但它只是把
我想制作一个“使用条款”复选框,并且我正在使用 FormControlLabel 为其嵌套一个复选框,但我需要创建一个链接,单击该链接会打开一个对话框组件,这是呈现条款,但是当我点击链接“”时,它也会
我创建了一个 Appbar React.js 中的组件,其中包含 3 个按钮,但是当我将鼠标悬停在这些按钮上时,我想更改颜色。背景颜色为#3c52b2文本颜色为 #fff .当我将鼠标悬停在按钮上时,
我正在尝试使用 Drawer 组件,我注意到当抽屉被输入 prop open={true} 时,有一个默认的灰色覆盖层底层页面/div。 是否有经 Material 批准的最佳实践方法来消除调光?我在
我将Material-UIv1.0.0-beta.34 Tooltip与Checkbox和FormControlLabel一起使用,实际上,当我将鼠标悬停在Checkbox上的标签时,在一种情况下,当
复制文件时,我对它们做了很少的事情......是否可以在显示复制文件的文本框中通知用户安装过程中发生了什么?我试图在互联网上找到该信息,但没有运气......不知道要寻找什么...... 最佳答案 我
我在我的应用程序中使用 MUI Card 和 CardMedia 组件,但不知道如何在图像上叠加文本。这是我正在尝试的一个简化示例: this text should o
我想在鼠标悬停在整个 Card 上时设置深度动画。我尝试了这个(所以我是 React 的新手)但我不知道该怎么做: 提前致谢。 最佳答案 constructor(props) { super(
堆栈:Meteor + React + MUI 这是我的“主要”渲染器组件的完整代码: // Sorry for not giving material-UI CSS, // cause it can
这个问题在这里已经有了答案: CSS child selector in MUI (5 个答案) 关闭 1 年前。 是否可以在 MUI 中为 Grid 中的所有 Field 设置样式?我已经知道如何
我目前正在自定义 MUI Select 方法,但是,我发现很难将鼠标悬停在“NarrowDownIcon”上: 我想在鼠标悬停时将此图标的 backgroundColor 更改为“蓝色”,这是我的代码
我在我的整个项目中都使用了脉轮用户界面,但脉轮似乎没有日期选择器组件,所以我尝试使用 Material 的组件,但只有当我删除 index.js 中的 ChakraProvider 时它似乎才不起作用
我想创建一个左侧带有图标的横幅区域。中间是两行(标题和副标题)文本。然而,所有这三个都出现在不同的行上。 您可以在此处查看问题:https://codesandbox.io/s/bold-brook-
我是一名优秀的程序员,十分优秀!