How to make mui textfield with chips in react js?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

To make mui textfield with chips, use autocomplete with render tags attribute and pass your chip component in render tags attribute. It will make mui textfield with chips.

Today, I am going to show you, how to make mui textfield with chips in react js.

Installation

Install the following packages to use mui textfield in react js.

npm

npm install @mui/material @emotion/react @emotion/styled

yarn

yarn add @mui/material @emotion/react @emotion/styled

MUI material textfield with chips example.

The below code is an example of making with chips using mui textfield.

App.js

import React from "react";
import Chip from '@mui/material/Chip';
import TextField from '@mui/material/TextField';
import Autocomplete from '@mui/material/Autocomplete';
import "./App.css";

export default function App() {
  return (
    <div className="App">
      <Autocomplete
        multiple
        id="tags-filled"
        options={[]}
        freeSolo
        renderTags={(value, getTagProps) =>
          value.map((option, index) => (
            <Chip
              variant="outlined"
              label={option}
              {...getTagProps({ index })}
            />
          ))
        }
        renderInput={(params) => (
          <TextField
            {...params}
            variant="filled"
            label="freeSolo"
            placeholder="Favorites"
          />
        )}
      />
    </div>
  );
};

In the above code example, I have used the @mui/material TextField component and made mui with chips of MUI Textfield.

Check the output of the above code example.

React, Mui Textfield chips

All the best 👍

Premium Content

You can get all the below premium content directly in your mail when you subscribe us

Books

Portfolio Template

View | Get Source Code

Cheat Sheets

Cheat Sheets Books are basically Important useful notes which we use in our day-to-day life.

I'm working on some more Cheat Sheets book on Jquery, TypeScript, React js and for other languages. I will send it once it's completed.

Related Posts