【发布时间】:2022-01-15 08:32:35
【问题描述】:
我正在尝试将 Snackbar 放置在右上角并带有一些 top: 自定义,但我无法正确设置它。
这是我的尝试:
import React from "react";
import { Snackbar, Alert } from "@mui/material";
import { styled } from "@mui/material/styles";
const StyledSnackbar = styled(Snackbar)(({ theme, props }) => ({
"& MuiSnackbar-root": {
top: theme.spacing(15),
},
}));
export default function Notification(props) {
const { notify, setNotify } = props;
return (
<StyledSnackbar
open={notify.isOpen}
autoHideDuration={3000}
anchorOrigin={{ vertical: "top", horizontal: "right" }}
>
<Alert severity={notify.type}>{notify.message}</Alert>
</StyledSnackbar>
);
}
然后我尝试了
const StyledSnackbar = styled(Snackbar)(() => ({
"& MuiSnackbar-root": {
top: "100px",
},
}));
但还是不行,Snackbar 固定在顶部/右侧
【问题讨论】:
标签: javascript reactjs typescript material-ui