mui / material-ui

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
https://mui.com/material-ui/
MIT License
93.87k stars 32.26k forks source link

[Joy][FormControl] A FormControl can contain only one control component #37764

Open antipopp opened 1 year ago

antipopp commented 1 year ago

Duplicates

Latest version

Steps to reproduce 🕹

Addind a decorator to an Input component, within a FormControl, results in a console error citing:

Joy: A FormControl can contain only one control component (Autocomplete | Input | Textarea | Select | RadioGroup)
You should not mix those components inside a single FormControl instance 

    in Input (created by InputDecorators)

    in InputDecorators

Link to live example: https://codesandbox.io/s/misty-brook-jjy9q2

import * as React from 'react';
import Divider from '@mui/joy/Divider';
import Input from '@mui/joy/Input';
import Select from '@mui/joy/Select';
import Option from '@mui/joy/Option';
import { FormControl } from '@mui/joy';

export default function InputDecorators() {
  const [currency, setCurrency] = React.useState('dollar');
  return (
    <FormControl>
    <Input
      placeholder="Amount"
      startDecorator={{ dollar: '$', baht: '฿', yen: '¥' }[currency]}
      endDecorator={
        <React.Fragment>
          <Divider orientation="vertical" />
          <Select
            variant="plain"
            value={currency}
            onChange={(_, value) => setCurrency(value!)}
            sx={{ mr: -1.5, '&:hover': { bgcolor: 'transparent' } }}
          >
            <Option value="dollar">US dollar</Option>
            <Option value="baht">Thai baht</Option>
            <Option value="yen">Japanese yen</Option>
          </Select>
        </React.Fragment>
      }
      sx={{ width: 300 }}
    />
    </FormControl>
  );
}

Current behavior 😯

No response

Expected behavior 🤔

Not a breaking issue, but still should not show any error as it should be an expected behavior.

Context 🔦

No response

Your environment 🌎

npx @mui/envinfo ``` System: OS: Linux 6.1 Manjaro Linux Binaries: Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node Yarn: 1.22.19 - /usr/bin/yarn npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm Browsers: Edge: 114.0.1823.51 (Official build) (64-bit) npmPackages: @emotion/react: ^11.11.1 => 11.11.1 @emotion/styled: ^11.11.0 => 11.11.0 @mui/base: 5.0.0-beta.3 @mui/core-downloads-tracker: 5.13.4 @mui/icons-material: ^5.11.16 => 5.11.16 @mui/joy: ^5.0.0-alpha.85 => 5.0.0-alpha.85 @mui/lab: ^5.0.0-alpha.124 => 5.0.0-alpha.132 @mui/material: ^5.13.5 => 5.13.5 @mui/private-theming: 5.13.1 @mui/styled-engine: 5.13.2 @mui/styles: ^5.11.13 => 5.13.2 @mui/system: ^5.11.14 => 5.13.5 @mui/types: 7.2.4 @mui/utils: 5.13.1 @mui/x-data-grid: ^6.7.0 => 6.7.0 @mui/x-date-pickers: ^6.7.0 => 6.7.0 @types/react: ^18.0.29 => 18.2.12 react: ^18.2.0 => 18.2.0 react-dom: ^18.2.0 => 18.2.0 typescript: ^5.0.2 => 5.1.3 ```
siriwatknp commented 1 year ago

Thanks for reporting the issue! Using Select as a decorator of an Input makes sense. Let me see what I can do.

adrien-constant commented 1 year ago

I'm also trying to get rid of the warning. Even if I specify htmlFor in FormLabel slotProps manually, the warning is raised.

Hanggi commented 9 months ago

Can we ignore the error currently?

adrien-constant commented 9 months ago

Can we ignore the error currently?

yes, it is just a warning, everything will work as intended in many cases it could be a warning that makes sense, but not in this case probably the devs will be able to remove it

dwmkerr commented 8 months ago

I have a similar issue when I have a FormControl that contains a number of Checkbox elements to create a select list like so:

image

In this view the pills are all Checkbox components, which I think is legit based on:

https://mui.com/joy-ui/react-checkbox/#choice-chips

I would love to know if there's a way to flag a component as none-form control or something so that I can eliminate these warnings

codebdy commented 7 months ago

if I use nest FormControlls this warning happend:A FormControl can contain only one control component (Autocomplete | Input | Textarea | Select | RadioGroup)。my customized input maybe use Modal ,and form & FormControls in the Modal, this waning offen occured

arifire21 commented 4 months ago

I'm currently getting this error for multiple form items, but I am not nesting any components. I made sure each has their own FormControls, any idea why this is happening?

stuller commented 3 months ago

also getting this error using RadioGroup example from https://mui.com/joy-ui/react-radio-button/#variants