Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build forms with material ui in react correctly

I am confused about the different form components in material ui.

There are six components which are relevant to forms which do not include specific input fields:
- FormControl
- FormLabel
- FormControlLabel
- FormGroup
- InputLabel
- FormHelperText

When you look at their examples Signin and Signup a plain html form tag is added on top.

Could someone explain when to use what component to build forms correctly?

like image 677
siva Avatar asked Mar 27 '20 19:03

siva


People also ask

How do I create a form in material UI React?

Create a Form Let's start by creating a new file in our project called Form. js . This component will return a form and we will be using the TextField and Button components from Material-UI. We will pass down the handleClose prop from the ModalDialog component to use in a cancel button.

How does material UI Integrate With React?

First, create a new react application, react-materialui-app using Create React App or Rollup bundler by following instruction in Creating a React application chapter. Next, open the application in your favorite editor. Next, create src folder under the root directory of the application.

Is material UI GOOD FOR React?

First up, Material UI (MUI) is an excellent React UI framework with multiple pre-built components and templates. For example, it includes pre-built sliders, drop-down menus, and navigational tools, so you don't need to waste time developing your own.

How do I use material UI in react?

What is Material UI? 1 Getting started. First, we need to set up and install the new react app by using the create-react-app command line tool. 2 Adding Nav bar. Let’s add the Navbar to our Header. ... 3 Material ui svg icons. Material UI provides us with SVG material icons to use in our react app. ... 4 Grid. ... 5 Contact form. ...

How to implement Google Material Design in react app?

Material UI provides us React components that implement google material design. First, we need to set up and install the new react app by using the create-react-app command line tool. Open your terminal and run following commands. Next, we need to change our working directory by using below commands.

What is material UI?

What is Material UI? Material UI is one of the famous React UI frameworks with 6 million monthly npm downloads and 43k GitHub stars. Material UI provides us React components that implement google material design.

How to manage multi-step forms in react apps?

Handling and managing forms in React apps are hard and could be a puzzle, especially for multi-step forms. The first step of the form asks for basic information (first name, last name, and email). Step two asks them to enter their city, occupation, bio and the last step asks them for the confirmation of user details.


1 Answers

The M-UI docs can be difficult to parse through at first. If you go to the demo section of the API for inputs/form in the docs, you can click on the expand code icon <> and see the expanded version of their code for better context.

For simple forms you can use a basic HTML/JSX form tag and set your onSubmit prop there and have the M-UI component TextField as your inputs inside of the enveloping form tags. You can then target name/value properties for each TextField.

That will let you get comfortable with the API for TextField which is the most basic of the M-UI input components. From there it will become more apparent when you need to reach for components like FormControls and labels.

like image 112
Jon Deavers Avatar answered Oct 12 '22 10:10

Jon Deavers