mui / mui/material-ui

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

Open
#37,764 9 comments 2 reactions 1 assignee View on GitHub

@siriwatknp is already working on this.

Since Jun 30, 2023.

component: FormControl package: joy-ui scope: text field type: enhancement
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Duplicates
  • I have searched the existing issues
Latest version
  • I have tested the 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 

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.