Skip to content

InputGroup

An input with something attached to it: a unit, a fixed start or end, an icon or a small button. The whole thing looks and behaves as one field.

import { InputGroup } from '@sypnia/ui/react'

On this page
  1. Units and fixed parts
  2. With an icon and a button
  3. States
  4. When to use it
  5. For everyone
  6. Props

Units and fixed parts

The person types only what changes.

per minute
https://.sypnia.app

Lowercase letters, numbers and dashes.

US$
Code
import { Field, FormGrid, Input, InputGroup } from '@sypnia/ui/react';

export default function Units() {
  return (
    <FormGrid>
      <Field label="Request limit"><InputGroup end="per minute"><Input type="number" defaultValue={600} /></InputGroup></Field>
      <Field label="Project address" hint="Lowercase letters, numbers and dashes.">
        <InputGroup start="https://" end=".sypnia.app"><Input machine defaultValue="storefront" /></InputGroup>
      </Field>
      <Field label="Monthly budget"><InputGroup start="US$"><Input type="number" defaultValue={250} /></InputGroup></Field>
    </FormGrid>
  );
}

With an icon and a button

Press «Suggest» for another name.

A name that tells you where the key is used.

Code
import { useState } from 'react';
import { Button, Field, FormGrid, Icon, Input, InputGroup } from '@sypnia/ui/react';

const words = ['amber', 'harbor', 'linen', 'meadow', 'quartz', 'willow'];
export default function WithAButton() {
  const [name, setName] = useState('amber-harbor');
  const suggest = () => setName(`${words[Math.floor(Math.random() * 6)]}-${words[Math.floor(Math.random() * 6)]}`);
  return (
    <FormGrid>
      <Field label="Key name" hint="A name that tells you where the key is used.">
        <InputGroup start={<Icon name="key" />} end={<Button size="sm" variant="quiet" onClick={suggest}>Suggest</Button>}>
          <Input value={name} onChange={(e) => setName(e.target.value)} />
        </InputGroup>
      </Field>
    </FormGrid>
  );
}

States

An error and a disabled value. Press Tab to see the focus around the group.

seconds

Write a number between 1 and 60.

GB

Set by your plan.

Code
import { Field, FormGrid, Input, InputGroup } from '@sypnia/ui/react';

// The whole group lights up on focus and turns red on error: it behaves as one field.
export default function States() {
  return (
    <FormGrid>
      <Field label="Timeout" error="Write a number between 1 and 60.">
        <InputGroup end="seconds"><Input type="number" defaultValue={90} /></InputGroup>
      </Field>
      <Field label="Storage included" hint="Set by your plan.">
        <InputGroup end="GB"><Input disabled defaultValue="8" /></InputGroup>
      </Field>
    </FormGrid>
  );
}

When to use it

Use it when

  • The value has a unit or a fixed part the person should not type: «per minute», «https://», «GB».
  • A small action belongs to the field: suggest a value, show a password, copy.
  • An icon says what kind of value it is.

Do not use it when

  • The extra text is help: write it in the hint of the Field.
  • The button is the main action of the form: put it in Actions.
  • You need search, a password or a value to copy: SearchInput, PasswordInput and CopyField are already built with it.

For everyone

  • The label of the Field still points at the input inside.
  • Text add-ons are read as plain text next to the field; say the unit in the label or hint too when it is essential.
  • The focus ring and the error border are drawn around the whole group.
  • A button inside is its own Tab stop, after the input.

Props

InputGroupTypeDefault
className string
end ReactNode
start ReactNode
  1. Units and fixed parts
  2. With an icon and a button
  3. States
  4. When to use it
  5. For everyone
  6. Props

    Search pages, sections and terms