Skip to content
npm ↗ GitHub ↗

Documentation

25/Forms and data

Forms

Input, textarea, select, checkbox, radio, switch and file, with help text and error and success states.

Text fields

Solo para enviarte la factura.

https://
HTML
<div class="grid max-w-[640px] gap-5 cb-sm:grid-cols-2">
  <div class="cb-field">
    <label class="cb-field__label" for="f-name">Nombre</label>
    <input class="cb-input" id="f-name" placeholder="María Ramírez" autocomplete="name">
  </div>
  <div class="cb-field">
    <label class="cb-field__label" for="f-email">Correo <span class="cb-field__optional">(opcional)</span></label>
    <input class="cb-input" id="f-email" type="email" placeholder="maria@ejemplo.com" aria-describedby="f-email-hint">
    <p class="cb-field__hint" id="f-email-hint">Solo para enviarte la factura.</p>
  </div>
  <div class="cb-field">
    <label class="cb-field__label" for="f-plan">Plan</label>
    <div class="cb-select"><select class="cb-input" id="f-plan"><option>Básico</option><option>Pro</option><option>Empresa</option></select></div>
  </div>
  <div class="cb-field">
    <label class="cb-field__label" for="f-site">Sitio web</label>
    <div class="cb-input-group"><span class="cb-input-group__addon">https://</span><input class="cb-input" id="f-site" placeholder="ejemplo.com"></div>
  </div>
  <div class="cb-field cb-sm:col-span-2">
    <label class="cb-field__label" for="f-msg">Mensaje</label>
    <textarea class="cb-input cb-textarea" id="f-msg" placeholder="Cuéntanos qué necesitas"></textarea>
  </div>
</div>

Error and success

The error state is enabled with aria-invalid="true" on the input or with cb-field--error. The message only shows in the error or success state.

El NIT no es válido.

Disponible.

HTML
<div class="grid max-w-[640px] gap-5 cb-sm:grid-cols-2">
  <div class="cb-field">
    <label class="cb-field__label" for="f-nit">NIT</label>
    <input class="cb-input" id="f-nit" value="12345" aria-invalid="true" aria-describedby="f-nit-msg">
    <p class="cb-field__message" id="f-nit-msg">El NIT no es válido.</p>
  </div>
  <div class="cb-field cb-field--success">
    <label class="cb-field__label" for="f-user">Usuario</label>
    <input class="cb-input" id="f-user" value="maria.r" aria-describedby="f-user-msg">
    <p class="cb-field__message" id="f-user-msg">Disponible.</p>
  </div>
</div>

Checkbox, radio and switch

Notificaciones
Frecuencia
Preferencias
HTML
<div class="flex flex-wrap gap-10">
  <fieldset class="cb-fieldset">
    <legend class="cb-fieldset__legend">Notificaciones</legend>
    <label class="cb-check"><input class="cb-checkbox" type="checkbox" checked>Correo</label>
    <label class="cb-check"><input class="cb-checkbox" type="checkbox">SMS</label>
    <label class="cb-check"><input class="cb-checkbox" type="checkbox" disabled>WhatsApp</label>
  </fieldset>
  <fieldset class="cb-fieldset">
    <legend class="cb-fieldset__legend">Frecuencia</legend>
    <label class="cb-check"><input class="cb-radio" type="radio" name="freq" checked>Diaria</label>
    <label class="cb-check"><input class="cb-radio" type="radio" name="freq">Semanal</label>
  </fieldset>
  <fieldset class="cb-fieldset">
    <legend class="cb-fieldset__legend">Preferencias</legend>
    <label class="cb-check"><input class="cb-switch" type="checkbox" role="switch" checked><span class="cb-check__text">Modo compacto<span class="cb-check__hint">Reduce el espaciado.</span></span></label>
    <label class="cb-check"><input class="cb-switch" type="checkbox" role="switch">Beta</label>
  </fieldset>
</div>

File and sizes

HTML
<div class="flex max-w-[520px] flex-col gap-4">
  <div class="cb-field">
    <label class="cb-field__label" for="f-file">Adjuntar comprobante</label>
    <input class="cb-file" id="f-file" type="file">
  </div>
  <input class="cb-input cb-input--sm" placeholder="Pequeño" aria-label="Pequeño">
  <input class="cb-input" placeholder="Mediano" aria-label="Mediano">
  <input class="cb-input cb-input--lg" placeholder="Grande" aria-label="Grande">
</div>

Classes and modifiers

ClassDescription
.cb-fieldGroups label, control, hint and message.
.cb-field__label, .cb-field__optionalLabel and optional marker.
.cb-field__hintHelp text.
.cb-field__messageMessage visible only on error or success.
.cb-field--error, .cb-field--successStates. The error is also enabled with aria-invalid="true".
.cb-inputInput, select or textarea. --sm and --lg for sizes.
.cb-textareaAuto height and vertical resizing.
.cb-selectWrapper for the select with its own arrow.
.cb-input-group, .cb-input-group__addonInput with prefix or suffix.
.cb-check, .cb-check__text, .cb-check__hintClickable label for checkbox, radio and switch.
.cb-checkbox, .cb-radio, .cb-switchCustom-styled controls, native underneath.
.cb-fileFile input.
.cb-fieldset, .cb-fieldset__legendOption group.

Accessibility

  • Every control needs an associated label or aria-label.
  • Link hints and errors with aria-describedby.
  • The switch is a checkbox with role="switch": it works with the keyboard without JS.
  • Color is not the only error signal: the message explains it in text.