'Material-UI, my Toggle Switch are so ugly

I'm new with Material UI and I don't understand why my Toggle looks like that...1 and 2

I don't have any compilations issues and my code is very simple :

    return (
    <Grid container spacing={2}>
        <Grid item xs={6}><Button variant="contained" >{exploitantLigne.raisonSociale}</Button></Grid>
        <Grid item xs={3}></Grid>
        <Grid item xs={3}>
        <FormGroup>
          <FormControlLabel control={<Switch defaultChecked />} color="primary" label="" />
        </FormGroup>
        </Grid>
    </Grid>
  );

And of course, in SandBox everything works perfectly !

Here is my Package.json, Do Idid anything wrong ?

    {
  "name": "ve-session",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@emotion/react": "^11.7.1",
    "@emotion/styled": "^11.6.0",
    "@material-ui/core": "^4.12.3",
    "@mui/icons-material": "^5.4.2",
    "@mui/lab": "^5.0.0-alpha.69",
    "@mui/material": "^5.4.2",
    "@mui/styled-engine-sc": "^5.4.2",
    "@mui/styles": "^5.4.2",
    "@testing-library/jest-dom": "^5.16.2",
    "@testing-library/react": "^12.1.3",
    "@testing-library/user-event": "^13.5.0",
    "@types/react": "^17.0.39",
    "@types/react-dom": "^17.0.11",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router-dom": "^6.2.1",
    "react-scripts": "5.0.0",
    "styled-components": "^5.3.3",
    "ts-loader": "^9.2.6",
    "typescript": "^4.5.5",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Thanks !



Solution 1:[1]

I assume that there is a mismatch between the MUI component imports and the version you've installed. I just used the correct way of importing the components. See the sandbox link
And code below

import "./styles.css";
import Switch from "@mui/material/Switch";
import Grid from "@mui/material/Grid";
import Button from "@mui/material/Button";
import FormGroup from "@mui/material/FormGroup";
import FormControlLabel from "@mui/material/FormControlLabel";

export default function App() {
  return (
    <Grid container spacing={2}>
      <Grid item xs={6} sx={{ pl: "10px" }}>
        <Button variant="contained">exploitantLigne.raisonSociale</Button>
      </Grid>
      <Grid item xs={3}></Grid>
      <Grid item xs={3}>
        <FormGroup>
          <FormControlLabel
            control={<Switch defaultChecked />}
            color="primary"
            label=""
          />
        </FormGroup>
      </Grid>
    </Grid>
  );
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1