Tips for implementing a Dialog Box within a Card Action Button Group

I'm currently exploring the option of incorporating a Dialog box as a button within a Button Group, which is then nested inside a CardActions component in Material UI.

Previously, I had success with using regular Buttons instead of a Dialog, where the 3 buttons within the CardActions were evenly justified across the width of the component. I am now aiming to maintain this layout while implementing an onClick action that triggers a pop-up Dialog box.

The structure I have is as follows:

<CardActions>
    <ButtonGroup
        orientation="horizontal"
        color="secondary"
        aria-label="vertical contained primary button group"
        variant="text"
        fullWidth
    >
        <1 /> 
        <2 />
         Services</Button>
    </ButtonGroup>
</CardActions>

Components '1', '2', and '3' are files that contain:

import React from 'react';
import Button from '@material-ui/core/Button';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import DialogContentText from '@material-ui/core/DialogContentText';
import DialogTitle from '@material-ui/core/DialogTitle';
import LaunchIcon from '@material-ui/icons/Launch';

export default function ScrollDialog() {
  const [open, setOpen] = React.useState(false);
  const [scroll, setScroll] = React.useState('paper');

  const handleClickOpen = (scrollType) => () => {
    setOpen(true);
    setScroll(scrollType);
  };

  const handleClose = () => {
    setOpen(false);
  };

  const descriptionElementRef = React.useRef(null);

  React.useEffect(() => {
    if (open) {
      const { current: descriptionElement } = descriptionElementRef;
      if (descriptionElement !== null) {
        descriptionElement.focus();
      }
    }
  }, [open]);

  return (
    <div>
      <Button  color="secondary"  onClick={handleClickOpen('paper')}>
        1
      </Button>

      <Dialog
        open={open}
        onClose={handleClose}
        scroll={scroll}
        aria-labelledby="scroll-dialog-title"
        aria-describedby="scroll-dialog-description"
        maxWidth="sm"
      >
        <DialogTitle id="scroll-dialog-title">Sampling Techniques</DialogTitle>
        <DialogContent dividers={scroll === 'paper'}>
          <DialogContentText
            id="scroll-dialog-description"
            ref={descriptionElementRef}
            tabIndex={-1}
          >
           
          </DialogContentText>
        </DialogContent>
        <DialogActions>
          
          
          <Button onClick={handleClose} color="primary">
            Close
          </Button>
        </DialogActions>
      </Dialog>
    </div>
  );
}

Although the Dialog displays as expected like a modal, the alignment styling of the buttons from the ButtonGroup within Card Actions doesn't remain intact - unlike when regular buttons were directly utilized in that specific Card Action component.

Hence my question - is it feasible to embed a Dialog box within a Card Action?

Answer №1

The styling of the .MuiButtonGroup-root is set to display as an inline-flex container. To ensure that the 3 buttons in the CardActions section are evenly spaced across the width of the component, you can use width: "100%" and

justifyContent: "space-evenly"
.

This will result in a visually pleasing layout where the buttons are evenly distributed.

const useStyles = makeStyles({
  customBtnGroup: {
    width: "100%",
    justifyContent: "space-evenly"
  }
});

<ButtonGroup classes={{ root: classes.customBtnGroup }}>

https://codesandbox.io/s/material-demo-forked-w8j5u?file=/demo.js

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

Obtaining the date without the time in TypeScript and MongoDB

I'm working with TypeScript and have the following code snippet: const EmployeeDetailsSchema: mongoose.Schema = new mongoose.Schema({ employeeId: { type: String }, advance: { lastAdvanceClosedOn: { type: String }, pending: { type: String ...

javascript unable to delete cookie

After conducting extensive research across various articles and links on deleting cookies using JavaScript, I have encountered an issue where the JavaScript code does not seem to be functioning as expected. The code I utilized for setting cookie values usi ...

Button with a Jquery icon design

Hello, I am currently working on implementing an icon button that can collapse and expand text. Although I have successfully implemented the logic for collapsing/expanding, I am facing difficulties in creating the actual icon button. The theme I am require ...

Activate the opening of a .docx file in a new tab by utilizing an anchor tag

I have attached a docx file containing the terms and conditions for our project. Now, I would like to open it in a new tab. By clicking this link, you can view the <a title="click to view terms and conditions" style="color:blue;" target="_blank" href ...

Navigate a user upon completion of an update

My webpage requires users to click an update link, which triggers a process of fetching data from an API that takes a few minutes. I don't want users to have to constantly refresh the page to know when the process is complete and they can continue. Is ...

Incorporate a progress bar into the Material-UI table design

I have the following example of a Material-UI table: import React from "react"; import clsx from "clsx"; import { createStyles, lighten, makeStyles, Theme } from "@material-ui/core/styles"; import Table from "@mat ...

Retrieving a Promise's value for an HTML Element

Hello, I'm new to working with React and JavaScript and could use some assistance. I have a function that returns a Promise that includes an interface. My goal is to access a variable in the interface and use it within <dl><dt>{//string va ...

javascript code to sort an array of objects within a nested array

I need assistance with removing the deleted status from the children key in a nested array of objects using JavaScript. Currently, when I try to filter out the deleted status, I receive an error stating "cannot return filter of undefined." The goal is to ...

A Node.js feature that enables atomic file replacement, triggering watchers only once

I have a unique scenario where I need to handle two types of processes. One process is responsible for writing a file, while the other processes are required to read it whenever there is a change. In my research, I came across fs.watch as a solution to ke ...

Tips on creating a responsive div element within the viewport?

I have a variety of nested div elements within a parent div, set up like this: #mycontent > div { width: 14.28%; } <div id="myheader">some header content</div> <div class="container" id="mycontent"> <div class="outerdiv" id= ...

I'm having trouble making the colors change on my Icon font/sprite rollover

I am currently attempting to position some related icons above my main navigation menu. The goal is to change the text and icon colors when a user hovers over a specific area (the tag with large padding). Unfortunately, I am facing challenges in achieving ...

What is the process for assigning the value returned from an Angular HTTP request to ng-bind?

I am trying to retrieve a value from an HTTP request in AngularJS and set it as the result in a variable that is bound to ng-bind. The goal is for the value returned from the HTTP request to be displayed when text is typed into an input field. Below is th ...

The Node.js application appears to be unresponsive on the designated port

When specifying port 30000, my app ends up listening on a different port unexpectedly. Below is the code snippet I have written: var express = require('express'); var bodyParser = require('body-parser'); var path = require('path& ...

What are the methods for handling JSON type in a web server?

Hey there! I'm currently working on making an AJAX call from the browser to a web service. The data is being sent as JSON from the browser to the web service. I'm wondering if there is a different way to retrieve it as a string and then deseriali ...

What is the process of converting an arrow function into an asynchronous one?

In the code snippet below, I am checking for the existence of a file and if it is present, I am parsing the JSON data from it: fs.access(dbPath, (err) => { if (err) throw err else{ console.log('Database found. Processin ...

Routes inoperative as intended

When using a standard expressroute for this login, I have noticed that even if the req.body.password is incorrect, I am still getting redirected to '/login'. router.post('/student/login', (req, res) => { if (req.body.password === ...

The function view() is not displaying the CSS and JS files properly

Having trouble with loading the css and js on my view: This is how I set up the controller: return view('home.news') ->with("news", $news); And here's how the route is defined: Route::get('/news/{id}&apos ...

A dialog box resembling a tooltip

Are there any jQuery plugins available that mimic the functionality of the tooltip dialog in the Flow App? (See screenshot here: ). I am currently working on a web app that requires a lot of tooltip dialogs. If there isn't a plugin available, could s ...

Ways to display and conceal a div when hovering over another div

Currently, I have 4 divs grouped under the class "menubut." I am attempting to create a small overlay that appears when hovering over the menubut classes. Additionally, I want another div called "red" to show up about one-tenth of the size of the menubut ...

The functionality of Angular Views is experiencing issues

I'm confused as to why the JavaScript isn't functioning properly. Whenever I click on the links, the views fail to load. <html ng-app> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/a ...