The component <FormControl /> does not support the variant prop

It's perplexing to me why <FormControl /> doesn't seem to accept the prop variant. Even though the documentation suggests that this prop is available.

import React from "react";
import { render } from "react-dom";
import FormControl from "@material-ui/core/FormControl";
import Select from "@material-ui/core/Select";
import MenuItem from "@material-ui/core/MenuItem";

const App = () => {
  return (
    <div>
      <FormControl variant="outlined">
        <Select value="foo" onChange={() => {}} autoWidth={true}>
          <MenuItem value="foo">Kitten</MenuItem>
          <MenuItem value="bar">Puppy</MenuItem>
        </Select>
      </FormControl>
    </div>
  );
};

render(<App />, document.getElementById("root"));

Despite following the documentation, it simply doesn't function as expected. Here's a Sandbox link where you can see the issue in action: https://codesandbox.io/s/material-ui-9ut2q

Answer №1

import React, { useState } from "react";
import { render } from "react-dom";
import FormControl from "@material-ui/core/FormControl";
import Select from "@material-ui/core/Select";
import MenuItem from "@material-ui/core/MenuItem";

const App = () => {
  const [state, setValues] = useState({
    defaults: "foo"
  });

  const changeValue = e => {
    setValues({ ...state, defaults: e.target.value });
  };
  return (
    <div>
      <FormControl variant="outlined">
        <Select
          value={state.defaults}
          onChange={e => {
            changeValue(e);
          }}
          autoWidth={true}
        >
          <MenuItem value="foo">Kitten</MenuItem>
          <MenuItem value="bar">Puppy</MenuItem>
        </Select>
      </FormControl>
    </div>
  );
};

render(<App />, document.getElementById("root"));

package.json

{
  "dependencies": {
     "react": "^16.7.0-alpha.2",
     "react-dom": "^16.7.0-alpha.2",
    ...
  },

https://codesandbox.io/s/material-ui-ksggx?fontsize=14

Give it a try and see how it performs.

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 does Code Sandbox, an online in-browser code editor, manage file storage within the browser?

What are the ways in which Code Sandbox and StackBlitz, as online in-browser code editors, store files within the browser? ...

Tips for implementing the new useState value in your code

Using DataGrid Material UI, I am facing an issue where the selected row is not being deleted when clicking on the delete button. The problem arises from setting the ID value in the useState hook and encountering asynchronous behavior in deleting the rows. ...

Error: The term "User" has not been previously defined

I encountered an issue while attempting to authenticate via vkontakte (vk.com) using passport-vkontakte. Error: A ReferenceError: User is not defined Below is the content of my auth.js file. var express = require('express'); var passport ...

Collaborative spreadsheet feature within a browser-based software platform

I am using an Angular-based SPA for my web application. My goal is to be able to open an Excel file within the application itself. Currently, I have a menu button or link that is linked to a specific path, for example //192.168.10.10/sharedExcels/myExcel. ...

Fully responsive header designed for optimal experience at any screen height

I am facing issues with the header and cannot seem to find a solution. My goal is to make the header span 100% of the window screen height. I need a responsive header that adjusts to 100% height, and when resizing for a smaller viewport, nothing should sho ...

showing information from a table column

Utilizing the jQuery DataTables plugin with a JSF <h:dataTable>. The page contains 86 records. +++++++++++++++++++++++++++++++++++++ + SN. + Name + Email + +++++++++++++++++++++++++++++++++++++ + 1 + Name 1 + Email 1 + + ...

Fetching Dependencies with NPM from the package.json file

I am feeling a bit puzzled. While working on my laptop, dependencies were automatically added to my package.json file as I installed them for my project. This is how it appears: "main": "webpack.config.js", "dependencies": { "immutable": "^3.7.6", ...

Creating a dynamic image slider that smoothly glides across a webpage

I've been working on a carousel (image slider) for my website and I need some help. Specifically, I want to reposition the entire slider slightly to the left on the webpage. You can see the slider in action on this site: and I also created a jsfiddle ...

SwiperJs is unable to access undefined properties (such as 'reading includes)

Currently, I am facing an issue with a reviews component that I created using swiperjs in a react and nextjs project. An error keeps popping up from this reviews component stating Unhandled Runtime Error TypeError: Cannot read properties of undefined (read ...

What is the correct way to navigate data through my Node.js API?

I am struggling with getting the JSON response to display at the /api/orders_count endpoint. Here is a breakdown of my setup: In my project, I have various files: Routes file - where the orders_count route is defined: routes/index.js const express = req ...

A step-by-step guide on uploading a file to an AWS S3 bucket using a pre-signed URL in a Node

I am currently using S3 upload function in Node.js to upload files to an S3 bucket. The frontend of the application is built on Angular. However, my client now requires that all uploads be directed to the S3 bucket via a presigned URL. I am wondering if th ...

Store the running of a JavaScript file in memory

It seems highly unlikely that achieving the following is possible without expert confirmation: On page number 1, user and application data is requested as soon as the page loads. Page number 2 utilizes the same script, so requesting the same information w ...

Can the CSS of an iframe be modified if the iframe is located on a different domain?

Is it feasible to modify the CSS of an iframe if the iframe is not located on the same domain? If so, what are some ways to apply and alter CSS for this situation? Any assistance would be greatly appreciated. <iframe id="frame1" width="100%" height="35 ...

Reactjs error: Invariant Violation - Two different nodes with the matching `data-reactid` of .0.5

I recently encountered a problem while working with Reactjs and the "contentEditable" or "edit" mode of html5. <div contenteditable="true"> <p data-reactid=".0.5">Reactjs</p> </div> Whenever I press Enter or Shift Enter to create ...

Unable to adjust the width of a table column within a horizontally scrollable container

I am struggling to resize the columns of a large table with 20 headers. Despite trying to place the table inside a div with overflow:auto, I still cannot achieve horizontal scrolling or make the div expand when resizing the columns. A sample code snippet ...

The program encountered an issue when trying to access properties that were not defined, specifically when trying to read the

An unexpected error occurred during runtime TypeError: Unable to access undefined properties (reading 'navigation') onSwiper={(swiper) => { setTimeout(() => { swiper.params.navigation.prevEl = navigationPrevRef.cur ...

Is there a workaround using jQuery to enable CSS3 functionality across all browsers?

Is there a way in jQuery to make all browsers act as if they have CSS3 capabilities? ...

What could be the reason for encountering TypeScript within the Vue.js source code?

While exploring the vue.js source code, I stumbled upon some unfamiliar syntax that turned out to be TypeScript after further investigation. What baffled me was finding this TypeScript syntax within a ".js" file, when my understanding is that TypeScript ...

Ways to resolve the issue "How to address the React hook error stating "React Hook 'React.useState' is being called conditionally"?"

I encountered an issue while attempting to build my next.js project. How can I resolve it? It seems that the error is related to using hooks conditionally. ./src/lib/session.js 6:29 Error: React Hook "React.useState" is called conditionally. R ...

What could be causing the MIME type error in my Django/React app when trying to load CSS/JS files from AWS?

Recently, I successfully deployed a Django-Rest/React app on Heroku and utilized AWS S3 buckets to host my static and media files. Upon accessing the API URL or admin URL, everything worked smoothly. However, when attempting to access my React URLs, I enco ...