Skip to content

Components

Inputs and actions

Controls people press and type into, built on native elements.

Components
Button, link, field, input, select, combobox, date, file upload, choice, switch, segmented control, slider and range

Button

Triggers an action. Four variants; use one primary per view.

Split button

An action joined to an icon button that opens a menu of its variants.

States

Filled buttons darken on hover and again on press. Secondary: hover darkens the border (and lightens the fill in dark theme); press steps the fill one gray. Tertiary: a gray fill on hover, darker on press.

Busy

Stingray.busy() blocks the button until the work is done, then confirms with a check. The label changes in place, so the width stays.

Use

  • A verb and object in sentence case: "Approve record".
  • A count for bulk or destructive actions: "Delete 3 records".
  • Secondary for other actions; tertiary for cancel.
  • Danger for destructive actions, confirmed in a dialog.

Avoid

  • "OK", "Yes" or "Submit".
  • A button that only navigates: use a link.
  • Disabling a button to hide a problem: explain on press.

Accessibility: a native <button>. Loading sets aria-busy, which keeps focus and blocks a second press. Icon-only buttons need aria-label and a tooltip. Targets are at least 28px, 44px in relaxed density.

Component tokens

Field and text input

A label, optional help, the input and an error. Errors add an icon and a doubled border, not color alone.

Use

  • A visible label above every input; mark optional ones "(optional)".
  • Help text linked with aria-describedby.
  • A width that fits the expected value.
  • The right type and autocomplete.
  • One field for a one-time code: sg-input--code with autocomplete="one-time-code".
  • Validation on blur or submit, saying what to do.

Avoid

  • Placeholder text as the label.
  • A red asterisk for required fields.
  • A bottom-border-only field.
  • Errors that only say "Invalid".
  • Validating on every keystroke.

Accessibility: a <label for> on every input. Set aria-invalid="true" and put the message in aria-describedby. With several errors on submit, focus a summary that links to each field.

Component tokens

Textarea

A multi-line field, at least three lines tall. It resizes vertically only.

Use a character counter only for a real limit, announced politely. Avoid auto-growing textareas in tables.

Select

A native <select> in a styled wrapper.

Use

  • One choice from about 4 to 15 options.
  • A natural order over alphabetical, when one exists.

Avoid

  • Fewer than 4 options: use radios.
  • More than about 15: use a combobox.

Checkbox and radio

A checkbox is an independent yes or no; a radio is one choice from up to seven. The whole label row is the target.

Use

  • A <fieldset> and <legend> around every group.
  • Indeterminate for a partly selected parent: input.indeterminate = true (the demo's data-indeterminate is docs-only).
  • Labels that say what is chosen, not "Enable".

Avoid

  • A checkbox that acts at once: use a switch.
  • More than seven radios: use a select.
  • Pre-checked consent boxes.
Component tokens

Switch

A setting that takes effect immediately.

Use for settings that apply now, with the current value in the label. Avoid in forms with a Save button: use a checkbox. Held, the thumb stretches toward where it goes. On a phone, flipping it gives a short haptic tap, unless haptics are off.

Component tokens

Segmented control

Two to five exclusive options on one line, built from native radios.

Use

  • To change how the same data is shown or filtered.
  • Short labels that never wrap.

Avoid

  • Navigation between pages: use tabs or links.
  • More than five segments: use a select.
Component tokens

Slider and range

A value within known limits, on a native range input. A range has two thumbs that never cross.

Use

  • When position matters more than the exact number.
  • The value beside the track, with its unit.
  • A step that fits the data: 5 for prices, 1 for days.

Avoid

  • An exact amount: use a field.
  • More than about 200 steps without a field beside it.
Component tokens

Combobox

A text field that filters a list as people type. Focus stays in the field.

Options can show an avatar and sit in labelled groups. A footer can show the count and keys.

Combobox keyboard
KeyDoes
Down UpOpen the list, then move through it.
EnterPick the active option.
EscClose the list; again, clear the field. Never closes a surrounding dialog while open.

Use

  • One choice from more than about 15 options.
  • sg-combobox__meta for a second fact, like a team.
  • A top group of likely picks.
  • A hidden input for the value; it is filled only on a pick.

Avoid

  • Fewer than 15 options: use a select.
  • Opening the list on focus.
Component tokens

Date and date range

The native date input, styled. A range is two dates; the end never falls before the start, and presets fill both.

Use

  • type="date" for every date entry. The value is always YYYY-MM-DD.
  • data-sg-range presets: days counting today, or month.

Avoid

  • Three selects for day, month and year.
  • A custom calendar widget.
  • A birth date picker that opens on today: let people type.

File upload

Attaches files to a record. Each pick adds to the list; a file over the size limit is listed with the reason and not kept.

Show a progress bar under the file name while it uploads, or an sg-field__error line if it fails.

Use

  • accept and data-max-size (bytes), with the same limits in the help text.
  • sg:fileschange to start uploads. The input holds the kept files, so a plain submit works.

Avoid

  • Uploading before save, unless the row shows progress and can be cancelled.
  • A drop zone with no button text.
Component tokens