Skip to Content

Input group

Input let users enter and edit data.

import * as React from 'react';
import { InputGroup, Surface, ToggleSwitch } from '@itwin/itwinui-react';

export default () => {
  const [option1, setOption1] = React.useState(true);
  const [option2, setOption2] = React.useState(false);

  return (
    <Surface>
      <InputGroup label='Toggle group' className='demo-input-group'>
        <ToggleSwitch
          onChange={(event) => setOption1(event.target.checked)}
          checked={option1}
          label='Toggle feature No.1'
        />
        <ToggleSwitch checked={true} disabled label='This you cannot change' />
        <ToggleSwitch
          onChange={(event) => setOption2(event.target.checked)}
          label='Toggle feature No.2'
          checked={option2}
        />
      </InputGroup>
    </Surface>
  );
};

Input group is a container to enhance an input by adding an icon, text, or a button in front or behind the input field as a “help text”.

Usage

import * as React from 'react';
import { InputGroup, Checkbox } from '@itwin/itwinui-react';

export default () => {
  const option1Label = 'Football';
  const option2Label = 'Hockey';
  const [option1, setOption1] = React.useState(true);
  const [option2, setOption2] = React.useState(false);
  const [allOptions, setAllOptions] = React.useState(false);
  const [isIndeterminate, setIsIndeterminate] = React.useState(true);
  React.useEffect(() => {
    if (option1 && option2) {
      setAllOptions(true);
      setIsIndeterminate(false);
      return;
    }
    if (option1 || option2) {
      setAllOptions(false);
      setIsIndeterminate(true);
    } else {
      setAllOptions(false);
      setIsIndeterminate(false);
    }
  }, [option1, option2]);
  const onAllChange = (value) => {
    setAllOptions(value);
    setIsIndeterminate(false);
    setOption1(value);
    setOption2(value);
  };
  return (
    <InputGroup label='Select your hobbies' message='Choose some hobbies'>
      <Checkbox
        onChange={(event) => onAllChange(event.target.checked)}
        label='Select all'
        indeterminate={isIndeterminate}
        checked={allOptions}
      />
      <Checkbox
        onChange={(event) => setOption1(event.target.checked)}
        label={option1Label}
        checked={option1}
      />
      <Checkbox
        onChange={(event) => setOption2(event.target.checked)}
        label={option2Label}
        checked={option2}
      />
    </InputGroup>
  );
};

Multiple add-ons are supported and can be mixed with checkbox, radio, toggle switch input version.

import { InputGroup, Radio } from '@itwin/itwinui-react';

export default () => {
  return (
    <>
      <InputGroup label='Radio group' message='Tell me how happy you are'>
        <Radio name='choice' value='option1' label={'Very Happy'} />
        <Radio name='choice' value='option2' label={'Not Happy'} />
      </InputGroup>
    </>
  );
};

Props

Prop Description Default
label
Label of the group.
ReactNode
status
Status of the group.
"positive" | "warning" | "negative"
message
Message below the group. Does not apply to 'inline' group.
When typeof message === "string", it is automatically wrapped with {@link StatusMessage}. If you are passing a non-string message that is not <StatusMessage>, you may need to wrap it with <StatusMessage> yourself for proper styling of message.
ReactNode
displayStyle
You can choose between default and inline.
"default" | "inline"
'default'
disabled
Disable whole group.
boolean
false
required
Whether the whole input group is required.
boolean
false
svgIcon
Custom icon. If group has status, default status icon is used instead.
Element
children
Child inputs inside group.
ReactNode
labelProps
Passes properties for label.
DetailedHTMLProps<LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>
messageProps
Passes properties for message.
Pick<Omit<Omit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & { ...; }, "as" | keyof StatusMessageProps> & StatusMessageProps & { ...; }, "iconProps" | "contentProps">
innerProps
Passes properties for inner input group element.
DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
as
"symbol" | "object" | "div" | "a" | "abbr" | "address" | "area" | "article" | "aside" | "audio" | "b" | "base" | "bdi" | "bdo" | "big" | "blockquote" | "body" | "br" | "button" | "canvas" | ... 158 more ... | FunctionComponent<...>