reactjsmaterial-uibootstrap-5mui-autocomplete

React: How to override input class in Material UI Autocomplete


I am working on a React project, where I have been using Bootstrap for front-end. I have integrated Autocomplete library from Material-UI.

#ref: https://material-ui.com/components/autocomplete/

Problem: I am trying to integrate form-control class inside the input tag. But it's not working.

Tried:

<Autocomplete
    id="combo-box-demo"
    options={this.props.customers}
    onChange={(_, value) => {
    console.log(value);
    }}
    getOptionLabel={(option) => option.name}
    style={{ width: 300 }}
    renderInput={(params) => (
    <div ref={params.InputProps.ref}>
        <input
        className="form-control"
        placeholder="Search by client name"
        type="text"
        {...params.inputProps}
        />
    </div>
    )}
/>

Result

Result

Expectation

enter image description here


Solution

  • I ended up having a solution with CSS. I copied the css code of .form-control class and put in combo-box-demo ID.

    input#combo-box-demo {
      display: block;
      width: 100%;
      padding: 0.375rem 0.75rem;
      font-size: 1rem;
      font-weight: 400;
      line-height: 1.5;
      color: #212529;
      background-color: #fff;
      background-clip: padding-box;
      border: 1px solid #ced4da;
      -webkit-appearance: none;
      -moz-appearance: none;
      appearance: none;
      border-radius: 0.25rem;
      transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    }