Counter
Animated character-count badge that shows current/max values. Used internally by TextField, Textarea and similar inputs.
Structure
Anatomy
Visual breakdown of the component's internal structure with BEM class call-outs.
<origam-counter>. A single root element (① tag) wraps the default slot (②) which renders the computed "value / max" string. The --error modifier is applied when value > max.- 1.origam-counter
- Root element. Tag is controlled by the
tagprop (default:div). Wrapped in<origam-transition>for animated show/hide. Modifier--errorapplied whenvalue > max. - 2#default slot
- Counter content. Default renderer produces "
value / max" when max is set, or just "value" otherwise. Slot props:{ counter, max, value }.
API
Props
All props accepted by this component, with their type, default value and description.
- activeboolean
- Controls visibility via the slide-y transition. When false the counter collapses animated.
- disabledbooleanfalse
- Reduces opacity and suppresses the error colour when the field is disabled.
- maxstring | number
- Maximum character count. When value exceeds max the counter switches to the error colour.
- valuestring | number
- Current character count (or the value string, length is derived if needed).
- idstring
- classstring | Array<string> | object
- stylestring | Array<string> | object | StyleValue
- tagstring'div'
- HTML element rendered at the root. Defaults to div.
- paddingboolean | number | string
- paddingTopboolean | number | string
- paddingLeftboolean | number | string
- paddingBottomboolean | number | string
- paddingRightboolean | number | string
- paddingBlockboolean | number | string
- paddingInlineboolean | number | string
- Inline (left/right) padding of the counter badge.
- paddingInlineStartboolean | number | string
- paddingInlineEndboolean | number | string
- paddingBlockStartboolean | number | string
- paddingBlockEndboolean | number | string
- marginboolean | number | string
- marginTopboolean | number | string
- marginLeftboolean | number | string
- marginBottomboolean | number | string
- marginRightboolean | number | string
- marginBlockboolean | number | string
- marginInlineboolean | number | string
- marginInlineStartboolean | number | string
- marginInlineEndboolean | number | string
- marginBlockStartboolean | number | string
- marginBlockEndboolean | number | string
- borderboolean | number | string | TDirectionBoth | Array<TDirectionBoth>false
- Applies a border around the counter badge.
- borderTopboolean | number | string
- borderLeftboolean | number | string
- borderBottomboolean | number | string
- borderRightboolean | number | string
- borderBlockboolean | number | string
- borderInlineboolean | number | string
- borderInlineStartboolean | number | string
- borderInlineEndboolean | number | string
- borderBlockStartboolean | number | string
- borderBlockEndboolean | number | string
- borderColorstring
- borderStylestring
- borderTopColorTColor
- borderRightColorTColor
- borderBottomColorTColor
- borderLeftColorTColor
- borderInlineStartColorTColor
- borderInlineEndColorTColor
- borderBlockStartColorTColor
- borderBlockEndColorTColor
- Border-radius token applied to the counter badge.
- roundedTopRightboolean | number | string
- roundedTopLeftboolean | number | string
- roundedBottomLeftboolean | number | string
- roundedBottomRightboolean | number | string
- roundedStartStartboolean | number | string
- roundedStartEndboolean | number | string
- roundedEndStartboolean | number | string
- roundedEndEndboolean | number | string
- color
- Intent or custom colour for the counter text.
- bgColorTColor
- elevationTElevation
- Box-shadow elevation applied to the counter badge.
- Density adjustment passed through to the root element.
- transitionboolean | string | TTransitionProps'origam-slide-y-transition'
- Animation transition when the counter appears / disappears. Defaults to slide-y.
API
Slots
Content slots exposed by this component.
- #default
- Custom counter content. By default renders the computed "value / max" or "value" string.
API
Exposed members
Properties and methods accessible via template ref (defineExpose). Use them for programmatic control.
- <T extends object>(props: T, exclude?: string[]) => Partial<T>
- Utility to forward a filtered subset of props.
- Ref<string>
- Reactive CSS string for the injected style sheet.
- string
- Unique style-sheet ID for this instance.
- () => void
- Injects the style sheet into the document.
- () => void
- Removes the style sheet from the document.
- Ref<boolean>
- True once the style sheet has been injected.
Customisation
CSS variables
CSS custom properties exposed by this component. Override them to customise the component without losing theme compatibility.
- Default counter text colour.
- Counter text colour when the field is focused / active.
- Counter text colour when value exceeds max (--error modifier).
- Counter font size.
- Counter font weight.
- Default opacity. Set to 1 when active/focused.
- Transition duration for colour/opacity changes.
Inclusion
Accessibility
ARIA roles, keyboard navigation and focus management. Sourced from the real component template.
Notes
- OrigamCounter is a visual helper only. When embedded in a text field, the parent field should use aria-describedby pointing to the counter element so screen readers announce the character count.
- For dynamic character-count announcements, add aria-live="polite" to the counter element or its parent container.
Foundation
Design tokens
Excerpt from this component's token declarations — the --origam-<component>---<property> variables, declared in its hand-maintained token sheet with no build step.
- colorvar(--origam-color__text---secondary)
- Default text colour.
- colorvar(--origam-color__action--primary---bg)
- Text colour when field is active/focused.
- colorvar(--origam-color__feedback--danger---fgSubtle)
- Text colour when value exceeds max.
- dimensionvar(--origam-font__size---xs)
- Counter font size.
- numbervar(--origam-opacity---70)
- Default counter opacity.
Interactive
Playground
Edit props live and see the component update in real time. The generated code snippet updates as you change values.
Rendering the live preview…
Usage
Examples
Ready-to-paste code snippets for your templates.
Character counter
Over-limit state
Embedded in TextField