Is the first child component of Material UI Stack not properly aligned?

Is there a CSS issue that needs fixing? I am working on creating a vertical list of checkboxes with labels using the <Stack /> component from Material UI.

I have tried implementing this in the sandbox provided (check out demo.tsx): https://codesandbox.io/embed/basicstack-material-demo-forked-q8kb4q?fontsize=14&hidenavigation=1&theme=dark

The code snippet is as follows:

export default function BasicStack() {
  return (
    <Box sx={{ width: "100%" }}>
      <Stack spacing={2}>
        <FormControlLabel control={<Checkbox />} label="Test1" />
        <FormControlLabel control={<Checkbox />} label="Test2" />
        <FormControlLabel control={<Checkbox />} label="Test3" />
      </Stack>
    </Box>
  );
}

In the demo, you will notice that only the first child component is not aligned properly. A quick fix would be to add sx={{marginLeft: 0.1}} only to the first <FormControlLabel />. However, this might not be the most elegant solution. Can anyone shed light on why this misalignment occurs and suggest a better approach to fix it?

Answer №1

I believe the issue lies with the spacing=2 setting. You may want to consider removing it in order for the indentation to display correctly.

<Stack>
  <FormControlLabel control={<Checkbox />} label="Test1" />
  <FormControlLabel control={<Checkbox />} label="Test2" />
  <FormControlLabel control={<Checkbox />} label="Test3" />
</Stack>

https://i.sstatic.net/OeyS5.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

Different placeholder text rendered in two text styles

Can an input box placeholder have two different styles? Here's the design I have in mind: https://i.stack.imgur.com/7OH9A.png ...

Activate Material-UI tab based on the current route visited

I recently started working on a new react-redux app, and as a beginner in React, I decided to incorporate Material-UI tabs into my project. The goal was to have the URL change when users select a tab, which I managed to achieve with the code snippet below: ...

Issue with modal-embedded React text input not functioning properly

I have designed a custom modal that displays a child element function MyModal({ children, setShow, }: { children: JSX.Element; setShow: (data: boolean) => void; }) { return ( <div className="absolute top-0 w-full h-screen fle ...

Dotted line for the tooltip cursor in recharts

I am in the process of creating a chart and one of the requirements is to have the "hover line" for the tooltip displayed as a dashed line instead of a solid line. While many recharts components have a "strokeDasharray" property that allows for dashed line ...

Resolving type error issues related to using refs in a React hook

I have implemented a custom hook called useFadeIn import { useRef, useEffect } from 'react'; export const useFadeIn = (delay = 0) => { const elementRef = useRef<HTMLElement>(null); useEffect(() => { if (!elementRef.current) ...

Zooming out on mobile devices on a webpage using Bootstrap 4

After creating a web app and styling it with bootstrap 4, I incorporated a media query to adjust font size and padding on mobile devices. The code snippet used for this purpose is as follows: @media (max-width: 1200px) and (orientation: portrait) { .con ...

What are some techniques for styling a field when the div id is not specified?

I need to customize a data field within a table, but I am unable to locate or identify its div ID. Here is the page source: <tbody> <tr> <td style="font-size:12px; text-align:center;" name=""> <div sty ...

Guide to navigating to a different webpage with Node.js

I am a beginner user of NodeJS and I have a specific request. I need assistance with setting up a page redirect from one page to another upon clicking on a link. Any guidance provided will be greatly appreciated. Here is the code snippet: app.js var expr ...

The <h1> element is not responding to the style attribute

Exploring HTML as a beginner has led me to an interesting issue. I've been practicing my newfound skills on W3Schools' platform and everything was running smoothly until I encountered a discrepancy in how the code is rendered on Wordpress. The s ...

ReactJS - PropType validation failure

PropTypes is not validating (ignore!!!) this simple component, I've tried everything but it's not working as expected. import React, { useEffect, useState } from "react"; import PropTypes from "prop-types"; import Item from & ...

Exploring Cypress Component Testing within a NextJS project

Could someone assist me with understanding how to utilize the cypress plugin for nextJS in order to execute Cypress Components Test package.json "devDependencies": { "@cypress/react": "^5.3.4", "@cypress/webp ...

Ways to convert JSON object from express into an array

I am looking for a solution on how to tidy up a returned JSON object into an array. My goal is to separate and eliminate any unnecessary punctuation from the recipe_method property of a JSON object retrieved from my database. Below is the data for recipe_ ...

Issue with the alignment of form input fields and buttons in Mozilla Firefox

Fixing Form Field Alignment Issue in Firefox After encountering and solving a form field alignment issue myself, I realized that the problem persisted in Firefox while displaying correctly in Chrome. Here's how I resolved it, although I am open to mo ...

React-router v4 changes the URL but fails to display the component

React-router v4 is what I'm working with, no Redux involved. Here's the code snippet: class MainPage extends Component { render() { return ( <div className="MainPage"> <BrowserRouter> ...

Tips for importing an external JavaScript file and accessing its data within a ReactJS project?

Currently, I am working on a React project using create-react-app. My objective is to load an external JavaScript file (hosted in IIS) and utilize the data it contains. To fetch this file, I am including a script in my index.html like so: <script type ...

React form validation feature that becomes visible upon input of accurate data

I have set up a simple login form and incorporated form validation with material UI. However, the validation messages are appearing even when there is text in the input fields. Here is the code for LoginComponent: LoginComponent import React from "reac ...

What is the best way to use JavaScript to conceal a section of a form div?

After receiving some code from a certain platform and implementing it to hide part of my form div element, I noticed that the element hides and unhides quickly when running in a browser. This rapid hiding and showing behavior occurs when clicking on the bu ...

The list in the navbar is misaligned and not centered vertically within the flex container

I've been working with flex for a while now, but I'm struggling to vertically align the content of my navbar to the center in the code. <nav className="nav navbar"> <h3> Logo </h3> <ul className= &q ...

Utilize properties with pseudo-elements in Material UI

import React from "react"; import { Box } from "@material-ui/core"; import { makeStyles } from '@material-ui/core/styles'; const useStyles = makeStyles({ box: { '&::before': { content: props => `$ ...

Deliver the PDF generated document to Django Rest API

I have successfully created a PDF from an HTML file, Now, I am looking to automatically email the PDF as soon as it is generated. To achieve this, I need to send it to Django REST for backend processing. However, I am facing difficulties in figuring out h ...