Can we not customize a nested component using the 'styled()' function in MUI?

Looking at the code snippet below, my attempt to style an MUI Stack component within an MUI Dialog component seems to be falling short. The Stack styles are not being applied as expected:

const CustomDialog = styled(Dialog)(({ theme }) => ({

    '& .MuiDialog-paper': {
        backgroundColor: theme.palette.error.light,
        color: theme.palette.background.default,
        textAlign: 'center',
    },
    '& .MuiDialogContent-root': {
        marginTop: 2,
        marginBottom: 2,
    },
    '& .MuiStack-root': {
        direction: 'row',
        spacing: 1,
        padding: 1,
    },
    '& .MuiButton-root': {

        ':first-of-type': {
            color: theme.palette.error.light,
            backgroundColor: theme.palette.background.default,
            ':hover': {
                backgroundColor: theme.palette.error.dark
            }
        },
        ':last-of-type': {
            backgroundColor: theme.palette.success.main,
            ':hover': {
                backgroundColor: theme.palette.success.dark
            }
        }


    }

}));

Now, see the CustomDialog in action:

    <CustomDialog>
        <DialogTitle>
            ...
        </DialogTitle>

        <DialogContent>
            ...
        </DialogContent>

        <Stack>
            <Button>
                ...
            </Button>

            <Button>
                ...
            </Button>
        </Stack>

    </CustomDialog>;

The intention was for the Stack to display the buttons side by side, but currently they are stacked vertically instead.

Answer №1

When working with the Stack component, you have the option to add a direction prop to customize the layout according to your preferences. Below is a code example for you to experiment with:

<Stack direction="row">
            <Button>
               ...
            </Button>

            <Button>
                ...
            </Button>
        </Stack>

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

The display of JSON data is not loading properly

Having some trouble displaying data in my app. Not sure if I'm missing something or making a mistake. Check out my code below. Projects.js: import Res2 from './images/Res/res2.jpg' import Res3 from './images/Res/res3.jpg' import ...

Monitoring changes within the browser width with Angular 2 to automatically refresh the model

One of the challenges I faced in my Angular 2 application was implementing responsive design by adjusting styles based on browser window width. Below is a snippet of SCSS code showing how I achieved this: .content{ /*styles for narrow screens*/ @m ...

Add a click event to elements that match

I must admit that I am not particularly knowledgeable in Javascript/jQuery and my question might come across as trivial. However, I am trying to assign a click event to every element on the page with the following code: $(document).ready(function () { ...

The position of the HTML class shifts when the window is resized

I am in the process of creating a basic website layout that resembles this design. However, I am facing an issue where the webpage does not adapt well to different window sizes. Specifically, the elements with the classes .gameInfo and .playerList overlap ...

elements that overlap exclusively in IE 8

Here's the information I need help with: http://jsfiddle.net/ktpmm5/Z5z8n/ The page can be accessed here: In IE 8, my paging element is shifted to the left and covers the heading. This issue does not occur in Chrome, FF, and Opera. I've been t ...

switchMap: Triggering multiple requests simultaneously (2)

Currently, I am utilizing Angular 2 RC-4 and facing an issue where a network request is being triggered twice whenever there is a change in the input box. This is what my code looks like: component.ts this.term = new Control(); this.suggestions = this. ...

Sending react table information to react modal

As a beginner with React, I'm facing challenges in passing data from react-table to an "edit" modal and haven't found a suitable solution yet. The data is fetched from the database using Axios API call and displayed in a react-table. My objective ...

Error encountered during compression of build artifacts with exit status 2

An issue occurred when attempting to deploy the application to Cloud Foundry following the installation of packages. Application type: Next.js ...

Is it necessary to have uniform spacing between links in a responsive navigation menu?

I am attempting to create a horizontal menu navigation system. I have multiple links in the navigation, and my goal is to evenly space them horizontally. Is there a way to achieve uniform spacing between links in a horizontal menu? HTML: <div id= ...

Adjust the body class dynamically based on the URL in AngularJS

Here is the link to my website To Log In - http://localhost/ang/#/login To Access Dashboard - http://localhost/ang/#/dashboard See below for the HTML code for the body tag If the current URL is http://localhost/ang/#/login, then the body should include ...

Error when compiling with Component Lab's Autocomplete function for SVG Icons in Material UI

Upon running my project on the browser, I encountered the following error: Error message: ./node_modules/@material-ui/lab/esm/internal/svg-icons/Close.js Attempted import error: 'createSvgIcon' is not exported from '@material-ui/core/utils ...

Angular JS is experiencing issues with two modules not functioning properly on a single page

Angular JS is a new technology for me. I have two modules, first2a and first22. Each module contains a controller named model1 and model2. Here is the HTML code: <!DOCTYPE html> <html > <head> <link rel="icon" ...

Code error detected on basic webpage

I've been experimenting with my local storage and have encountered a strange issue. The code example that I had previously tested successfully is now not working, and I can't figure out what went wrong. Check out this link for additional informa ...

Javascript: A Fun Game of Questions and Answers

When using JavaScript exclusively, I have an array consisting of four questions, four correct answers, and four incorrect answers. The use of arrays is essential to maintain order in the data. As each question is displayed, a random number is generated by ...

What is the process for incorporating CSS, JavaScript, and images into a Django project?

Within the static folder, I have created a CSS file called resume.css with the following structure: static css resume.css In my settings.py file, I did not make any changes to the static code. I have referenced the index.html file in my vie ...

Ways to address the dependencies problems when using npm install @types/react?

Encountering an issue with the @types/react package. This pertains to a small UI project developed on top of the nextron platform. Everything was functioning smoothly until I had to reinstall my Windows OS. Attempting to rebuild the project using yarn an ...

Loading CSS dynamically at runtime can be seen as a mix of both success and failure

I have been attempting to optimize my app by loading fonts on demand. By retrieving fonts from a project directory generated by the app, it is able to gather all necessary data. My primary concern is whether there is an equivalent of 'app-storage://& ...

Determine whether an element is visible following a state update using React Testing Library in a Next.js application

I'm looking to test a NextJS component of mine, specifically a searchbar that includes a div which should only display if the "search" state is not empty. const SearchBar = () => { const [search, setSearch] = useState(""); const handleSear ...

Automating the logout process in React when a JWT token expires

One of my projects consists of 5 pages where I have stored a JWT token in local storage. In which screen should I implement the code for automatic logout and what will be the React code? App.js <BrowserRouter> <Switch> <Route exact pa ...

Discover the "route" of a JSON element using JavaScript

I've been struggling to retrieve the "path" of a specific AngularJS scope variable. My end goal is to utilize this "path" as the ng-model for dynamically generated forms. Below is my current code: my_code.js: var my_data = { name: "fred", numbe ...