Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React Material UI – Checkbox – Row alignment

I could appreciate any leads for the following:

I want two checkboxes:

Android and IOS

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

to be placed beside each other. I used Material UI FormGroup, Formlabel and Checkbox in a React form.

The problem I could not solve is the checkboxes are aligned one below another:

This is my code:

 <FormGroup **row**>
            <FormControlLabel
              control={
                <Checkbox
                  size="small"
                  checked={Android}
                  onChange={handlePlatformSelectionChange}
                  name="Android"
                />
              }
              label="Android"
            />
            <FormControlLabel
              control={
                <Checkbox
                  size="small"
                  checked={Ios}
                  onChange={handlePlatformSelectionChange}
                  name="Ios"
                />
              }
              label="iOS"
            />
          </FormGroup>

Can I override this alignment in CSS or is there any direct way to align it one beside another?

>Solution :

You can do the following:

 <FormGroup sx={{position: 'flex', flexDirection: 'row', justifyContent: 'center', alignItems:'center'}}> // remove justifyContent to disable vertical alignement and alignItems to disable horizontal alignement
            <FormControlLabel
              control={
                <Checkbox
                  size="small"
                  checked={Android}
                  onChange={handlePlatformSelectionChange}
                  name="Android"
                />
              }
              label="Android"
            />
            <FormControlLabel
              control={
                <Checkbox
                  size="small"
                  checked={Ios}
                  onChange={handlePlatformSelectionChange}
                  name="Ios"
                />
              }
              label="iOS"
            />
          </FormGroup>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading