The ready-made fields already have the counter built in — turn on the
counterprop of CdsTextInput or CdsTextArea. A standaloneCdsCounteris needed when you build your own control.
Variations
Value and maximum
The value prop sets the current number, max sets the limit. Without max the counter shows a single number, with max it shows a fraction. As soon as value is greater than max, the text turns red.
Appearance
The counter is visible only with active — by default it is hidden. Showing and hiding are animated, and the animation is set by the transition prop.
Slot
The default slot replaces the text of the counter and receives value, max and the ready counter string.
Scenarios
Character limit of a field
The details slot of an input is the place for a counter next to the messages. Count the length of the value yourself and pass it into value: when the text outgrows the limit, the counter turns red.
API
Props
| Name | Type | Default | Description |
|---|---|---|---|
active | boolean | undefined | — | Active state |
disabled | boolean | null | undefined | null | Disabled state |
max | string | number | undefined | — | Maximum value |
transition | string | boolean | (TransitionProps & { component?: Component | undefined; }) | { component: Component; } | null | undefined | { component: slide-transition-y } | Transition animation |
value | string | number | undefined | 0 | Value of the counter |
Slots
| Name | Type | Description |
|---|---|---|
default | CdsCounterSlot | Your own look for the counter. The slot props carry the ready counter string, the current and the maximum number of characters |