Aligning rows of checkboxes in React Material UI

Any suggestions on how I can achieve the following:

I am looking to have two checkboxes, one for Android and one for IOS

placed next to each other in a row. I have tried using Material UI FormGroup, Formlabel, and Checkbox components within a React form.

However, I'm encountering an issue where the checkboxes are stacked vertically instead of horizontally:

This is the code snippet I am currently working with:

 <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>

Is there a way to adjust the alignment using CSS or any other direct method to ensure they are displayed next to each other?

Answer №1

Below are the steps you can take:

 <FormGroup sx={{position: 'flex', flexDirection: 'row', justifyContent: 'center', alignItems:'center'}}> // by removing justifyContent, vertical alignment will be disabled and removing alignItems will disable horizontal alignment
            <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>

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

How to resolve a TypeError saying "Object(...) is not a function"?

I've been attempting to display material-ui tabs as a component on another page, but I'm encountering an error that causes the code to break when loading the page with this component. I've tried two different methods of rendering this compo ...

Resizable table example: Columns cannot be resized in fixed-data-table

I've implemented a feature similar to the Facebook example found here: https://facebook.github.io/fixed-data-table/example-resize.html You can find my source code (using the "old" style with React.createClass) here: https://github.com/facebook/fixed- ...

Why does the same error keep popping up every time I attempt to install my React application?

I am new to React and feeling frustrated as I keep encountering the same error repeatedly. I have tried three different codes individually: npx create-react-app myapp npm init react-app myapp npm install -g create-react-app followed by create-react- ...

Is there a way to integrate the CopyWebpackPlugin into a create-react-app setup without having to eject?

Currently, I am in the process of developing a React application and one of my objectives is to transfer all image files from the source location to the build destination. To accomplish this task, I have been studying various tutorials and have successfull ...

The call in TypeScript React does not match any overload

Encountering an error with a React component that I wrote and seeking assistance. The primary component code snippet: export interface ICode { code: (code: string) => void; } export default class UserCode extends React.Component{ state = { formFil ...

Traversing through objects in react.js

Hello there, I'm currently learning React and JavaScript but facing some challenges with a particular task. Let's dive into it! So, imagine I have an array like this: clients = ["Alex", "Jimmy"] and then I proceed to create another array using th ...

Developing a Burger-licious Menu in React

Seeking a straightforward solution to transfer Vanilla JS code into a React application. Currently working on converting a website from plain HTML/CSS/JS to React, and facing challenges with integrating existing JS functionality, such as a hamburger menu t ...

Search MongoDB using regular expressions that disregard any punctuation marks

I'm currently working on querying a MongoDB collection to find a single item based on a string property using react-router-dom's NavLink. The challenge arises when the prop via NavLink contains hyphens instead of spaces, and there are also names ...

React is unable to assign a class field beyond the scope of axios

class App extends React.Component { app: Application; ... componentDidMound() { axios.get(…).then(res => { this.app.currentUser = res.data.data; // setting value inside lambda function. console.log(this.app.currentUser); // ...

Switch between light and dark themes in antd using React at runtime

Despite finding a similar question on Stack Overflow, the provided answer did not solve my issue. I have attempted to follow the steps mentioned, but unfortunately, there has been no noticeable effect. I am struggling with where to place the config-overrid ...

Leverage the power of openCv.js within your next.js projects

I am attempting to incorporate openCv.js into my next.js application a. I started the project with: npx create-next-app b. Next, I installed: $ yarn add @techstark/opencv-js c. Imported OpenCV with: import cv from "@techstark/opencv-js" d. Ho ...

Steps to update the color of the asterisk in a mandatory field: How to change the

I am looking to change the color of the asterisk in my form fields from black to red. I am currently using the Material UI React library and need some guidance on how to achieve this. You can view the code here: https://codesandbox.io/s/r7lq1jnjl4 For mo ...

Implementing fetch within a custom hook to display a loader within a return function

customFetch hook: import React, { useState, useEffect } from 'react'; const customFetch = (url, options) => { const [response, setResponse] = useState(null); const [error, setError] = useState(null); useEffect(() => { (async () ...

Optimal strategy for enhancing React Native dependencies

After joining a new company, I discovered numerous outdated project dependencies such as [email protected], react-native-firebase, and react-native. My goal now is to update all of them, but the challenge lies in the fact that four other developers ar ...

Encountering a React error when attempting to generate a URL for an image in Sanity

Server Error Error: The asset reference 'e173af30-fd2d-42ed-a364-d92a2cddf32c' is malformed. It should be in the format of an id such as "image-Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000-jpg".https://i.stack.imgur.com/koC26.png https://i.stack.imgur.com/ ...

Unexpectedly, the React custom component is failing to render as intended

I am anticipating the text "SMALL Medium, Big" to be displayed on the screen but unfortunately it's not showing up function Box(prop){ const ele = <div className={prop.cn}> </div> return ele } ...

data not corresponding to interface

I am encountering an issue that says Type '({ name: string; href: string; icon: IconDefinition; } | { name: string; href: string; icon: IconDefinition; childs: { name: string; href: string; icon: IconDefinition; }[]; })[]' is missing the followin ...

What is the reason behind SyntheticEvent not functioning properly in Next.js with React?

Currently, I am utilizing Next.js and encountered an issue with stopping my form using e.preventDefault(), which proved to be ineffective. After some troubleshooting, I discovered a workable solution by replacing e.preventDefault() with e.nativeEvent.preve ...

React Context failing to update when clicking on modal opening button

Currently, I am facing an issue where I am attempting to trigger a modal by updating the state of the component within a Context Provider. Despite the button registering a click successfully, the Modal fails to open. Below is the code snippet containing ...

When utilizing Axios to communicate with a backend server, an error message of "The requested resource could not be found (404)" may be displayed

Currently, I am developing a Web Application using React. The application features a login/register function for user authentication. To achieve this, I have set up an express server to handle HTTP requests to interact with a MYSQL database. Two specific e ...