Skip to content

Label

The name of a control, for when a control needs its own layout. Inside a Field it points at the Field's control by itself; outside, give it htmlFor.

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

On this page
  1. A label with a count
  2. Optional
  3. When to use it
  4. For everyone
  5. Props

A label with a count

Write in the field: the count follows.

33 / 120

People who see the key in the list read this to know whether they can delete it.

Code
import { useState } from 'react';
import { Hint, Label, Textarea } from '@sypnia/ui/react';

// When a control needs its own layout, such as a count written beside the label, use the parts on their own.
export default function Custom() {
  const [text, setText] = useState('Nightly copy of the orders table.');
  return (
    <div className="sy-field">
      <div className="sy-row sy-row--between">
        <Label htmlFor="purpose">What this key is for</Label>
        <output htmlFor="purpose" className="sy-text--muted">{text.length} / 120</output>
      </div>
      <Textarea id="purpose" maxLength={120} value={text} onChange={(e) => setText(e.target.value)} aria-describedby="purpose-hint" />
      <Hint id="purpose-hint">People who see the key in the list read this to know whether they can delete it.</Hint>
    </div>
  );
}

Optional

Code
import { Label } from '@sypnia/ui/react';

// Mark what can be left empty, not what is required: most fields in a good form are required.
export default function Optional() {
  return (
    <div className="sy-stack">
      <div className="sy-field"><Label htmlFor="org">Organization name</Label><input id="org" className="sy-input" defaultValue="Northwind" /></div>
      <div className="sy-field"><Label htmlFor="vat" optional>Tax number</Label><input id="vat" className="sy-input sy-input--machine" /></div>
    </div>
  );
}

When to use it

Use it when

  • A label with something beside it, such as a count or a link.
  • Mark fields that can be left empty with optional.

Do not use it when

  • Ordinary fields: a Field writes the label, the hint and the error for you.
  • Placeholders instead of labels: they disappear as soon as someone writes.

For everyone

  • Every control has a visible label tied with for.
  • «optional» is part of the label, so it is read with it.

Props

LabelTypeDefault
htmlFor string
optional boolean
  1. A label with a count
  2. Optional
  3. When to use it
  4. For everyone
  5. Props

    Search pages, sections and terms