【问题标题】:Material-UI Dialog How to place the close button on the top right border of the dialogMaterial-UI Dialog 如何在对话框的右上角放置关闭按钮
【发布时间】:2020-08-02 17:49:28
【问题描述】:

想在标题部分右上角添加一个关闭图标。

请帮我解决这个问题。我使用了 Material UI 对话框。一切正常,但我想在顶部有一个关闭按钮。

【问题讨论】:

标签: javascript html css reactjs material-ui


【解决方案1】:

一些注意点:

  • position: 'absolute' 启用调整close button 的位置。

  • overflowY: 'unset' 通过覆盖相关样式道具paper 来启用对话框外溢出。

  • 将 MUI IconButton 与图标 CloseIcon 一起用于需求 UI。

  • 使用 MUI makeStyles 样式挂钩自定义样式。


参考:


示例代码:

import { makeStyles } from "@material-ui/core/styles";

const useStyles = makeStyles(theme => ({
  paper: {
    overflowY: 'unset',
  },
  customizedButton: {
    position: 'absolute',
    left: '95%',
    top: '-9%',
    backgroundColor: 'lightgray',
    color: 'gray',
  }
}));
import CloseIcon from '@material-ui/icons/Close';
import { IconButton } from '@material-ui/core';

<Dialog
  classes={{paper: classes.paper}}
>
  <DialogActions>
    <IconButton className={classes.customizedButton}>
      <CloseIcon />
    </IconButton>
    ...
  </DialogActions>
</Dialog>

在线演示:

https://stackblitz.com/edit/mz5jx2?file=demo.js

【讨论】:

    猜你喜欢
    • 2017-07-10
    • 1970-01-01
    • 1970-01-01
    • 2021-10-12
    • 1970-01-01
    • 1970-01-01
    • 2020-01-28
    • 2021-09-09
    • 1970-01-01
    相关资源
    最近更新 更多