Positioning the close button on the top right edge of a Material-UI Dialog: A step-by-step guide

https://i.sstatic.net/ARTtq.png

How can I include a close icon in the top right corner of the header section?

I'm using the Material UI Dialog and everything works well, but I need a close button in the top section. Can anyone assist me with this?

Answer №1

Key Points to Note:

  • position: 'absolute' is used to adjust the positioning of the close button.

  • overflowY: 'unset' allows for overflow outside the dialog by overriding the relevant style props paper.

  • Utilize MUI's IconButton component along with the CloseIcon for the desired UI.

  • Apply custom styles using MUI's makeStyles style hooks.


References:


Sample code:

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>

Online demo:

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

https://i.sstatic.net/qHzR4.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unresolved styles in React component linked to styles.css file

As I dive into creating a registration page in ReactJS, I encounter a frustrating issue with my styles not applying correctly from the styles.css file. Let's take a look at my RegisterPage.jsx component: export default function RegisterPage() { ret ...

I am experiencing difficulty typing continuously into the input box in reactJS

In one of my components, I have the capability to add and delete input fields multiple times. <> <form onSubmit={optimizeHandler}> <div className="filter-container"> {conditions.map((condition, index) => ...

When configuring Gatsby with Typescript, you may encounter the error message: "You cannot utilize JSX unless the '--jsx' flag is provided."

I am currently working on a Gatsby project and decided to implement Typescript into it. However, I encountered an error in my TSX files which reads: Cannot use JSX unless the '--jsx' flag is provided. What have I tried? I consulted the docume ...

Updating object property values within an array: A step-by-step guide

const alternateData = [ { value: 1, label: "altDesc1" }, { value: 2, label: "altDesc2" }, { value: 3, label: "altDesc3" }, { value: 4, label: "altDesc4" }, { value: 5, label: "altDesc5" }, { value: 6, label: "altDesc6" } ]; cons ...

What causes the Vue.http configuration for vue-resource to be disregarded?

I am currently utilizing Vue.js 2.3.3, Vue Resource 1.3.3, and Vue Router 2.5.3 in my project while trying to configure Vue-Auth. Unfortunately, I keep encountering a console error message that reads auth.js?b7de:487 Error (@websanova/vue-auth): vue-resour ...

Extract the canvas code line from a function without using the eval function

Greetings, fellow Stackers! Please pardon my formatting as this is my debut question on this platform. I am currently working on a basic vector drawing tool. If you want to view the full CodePen code for reference, feel free to click here. Here's t ...

Success is returned as AJAX error

My AJAX call is returning an error as Success instead of a JSON error from ASP.NET MVC. Can someone please advise on how I can resolve this issue? Thank you. [HttpPost] public JsonResult Register(int EventID) { try { ...

Steps to modify the text of the accept and cancel buttons on the MobileDatePicker component

The MobileDatePicker component in the @mui/x-date-pickers package features buttons labeled as OK/CANCEL by default. In version 4 of the DatePicker component, there was a prop called acceptLabel/cancelLabel that allowed changing the text of the buttons. Ho ...

Mui CardContent not displaying transparent background color properly

I recently completed a course that used MUI v4, and I'm now facing challenges with transitioning to v5. Despite my best efforts, I am struggling to replicate all the styles and find myself stuck. This issue relates to my FeaturedMovie.jsx component i ...

The error message "npm ERR! enoent" indicates that npm is unable to locate a specific file

How do I troubleshoot this issue? After attempting the master version, I encountered a similar error. My operating system is OSX Yosemite: bash-3.2$ yo meanjs You're utilizing the official MEAN.JS generator. ? Which version of mean.js would you like ...

What is the process for installing the shadcn component library with yarn or npm?

My latest project involves creating a Notion-inspired app using Next.js and the shadcn/ui library from [https://ui.shadcn.com/]. I attempted to add shadcn/ui to my project using npm and yarn, but encountered some difficulties along the way. ...

The server is unable to process the .get() request for the file rendering

Struggling with basic Express routing here. I want the server to render 'layout2.hbs' when accessing '/1', but all I'm getting is a 304 in the console. Here's the error message: GET / 304 30.902 ms - - GET /style.css 304 3.3 ...

showcasing a map on an HTML webpage

Seeking advice on integrating a map feature in HTML to mark store locations. Working on an app for a business community and need help with this specific functionality. Your assistance would be greatly appreciated! ...

Utilize mouseover to rotate the camera in three.js

Is it possible to utilize Three.js to rotate a camera and view an object from all angles upon hovering with the mouse? ...

Exploring ways to access the SelectField options by clicking on either the text or icon within the input adornment in Material UI

Utilizing Material UI TextField with the 'Select' prop, I transformed it into a SelectField. The input adornment contains text, and I am seeking a way to access the options of the SelectField when clicking on the input adornment text. I'm no ...

Looking for a way to efficiently add multiple value inputs to a JSON object using jQuery or JavaScript?

Here is the HTML input tag code I am working with: <form id="info"> <input id="A" name="A" type="hidden" nodetye="parent" value="A"> <input id="A1" name="A1" type="text" nodetype="child" value="a1val"> <input id="A2" name ...

Can you guide me on how to programmatically set an option in an Angular 5 Material Select dropdown (mat-select) using typescript code?

I am currently working on implementing an Angular 5 Material Data Table with two filter options. One filter is a text input, while the other is a dropdown selection to filter based on a specific field value. The dropdown is implemented using a "mat-select" ...

Troubleshooting the issue with formatting dates in AngularJS

I need help converting 2015-04-17 12:44:38.0 to dd/MM/yyyy format using angularjs <td ng-bind="item.MON_FE_DUEDATE | date:'dd-MM-yyyy'"></td> However, it is still displaying 2015-04-17 12:44:38.0 only. Can anyone please point out w ...

insert a new user into a MongoDB collection

I am facing an issue with adding a user to my collection called users. The code I'm currently using is: var user1 = { Username: "joonyoftv", Password: "joon123", Email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cf ...

Custom marks for the Mui Slider are available for a personalized

https://i.sstatic.net/0Xyra.png Hey everyone, I've encountered an issue with the Mui Slider and its marks. As you can see in the screenshot, I'd like to add some padding/margin (e.g., 8px) to the first and last markers. Currently, my code look ...