Skip to content

Input group

hc-input-group composes an hc-input with leading / trailing addons — text, an icon, or a real hc-button — on one bordered surface with a single shared focus ring. It is mostly CSS; the inner <input> gives up its own border so the group owns it.

The inner <input> and <button> are ordinary elements, so htmx wiring (data-hx-*) goes on them directly — the group is purely visual.

https://
$USD

A trailing button can toggle a password field’s visibility. This is the one opt-in behavior of the group: add data-hc-password-toggle and call installPasswordToggle() (it is included in the auto-init bundle).

import { installPasswordToggle } from '@hypermedia-components/core';
installPasswordToggle();

The behavior toggles the input’s type between password and text and reflects aria-pressed plus the aria-label. Customize the wording with data-hc-label-show / data-hc-label-hide (defaults “Show password” / “Hide password”). It never reads the field value and makes no network call.

  • Give the <input> an accessible name (aria-label here, or a <label> when wrapped in hc-field). A decorative icon addon should be aria-hidden="true".
  • A meaningful text addon (a unit like USD, a prefix like https://) is read in source order — fine for screen readers; keep it short.
  • The focus ring is shared: focusing the field rings the whole group via :focus-within. An inner button keeps its own focus outline.
  • The password toggle is a real <button type="button"> with aria-pressed — keyboard operable and announced as a toggle.
Token pathPurpose
input-group.bgShared surface background.
input-group.fgText color.
input-group.borderSurface border.
input-group.focus-borderBorder color while focused.
input-group.radiusOuter corner radius.
input-group.addon-bg / addon-fgAddon background / text.
input-group.addon-padding-xAddon inline padding.
input-group.dividerHairline between an addon/button and the field.
Show the generated CSS variables
--hc-input-group-bg | -fg | -border | -focus-border | -radius
--hc-input-group-addon-bg | -addon-fg | -addon-padding-x | -divider
  • Input — the field placed inside.
  • Field — label + help text wrapper.
  • Button group — connect buttons (rather than an input with addons).