No Results Found
Wrap an input or textarea to keep count
<tk-character-counter
count-down="true"
input-size="medium"
max-length="200"
placement="bottom"
text="Updated model value"
warning-text="Try breaking down larger tasks and questions"
>
<label class="form__label form__label--stacked">
Task
<textarea
oninput="characterCountExampleChanged(event)"
class="form-input form-input--textarea"
></textarea>
</label>
</tk-character-counter>
<script>
const characterCounterElement = document.getElementsByTagName('tk-character-counter')[0];
const characterCountExampleChanged = (event) => {
characterCounterElement.setAttribute('text', event.srcElement.value)
}
</script>
Wrap any input or textarea that needs a way to count its characters with <tk-character-counter>
.
The input or textarea must provide a way to pass out the value being entered into the field so that the counter component can update the counts it checks against.
Property | Attribute | Description | Type | Default |
---|---|---|---|---|
countDown |
count-down |
Should the counter count down or up? | boolean |
false |
counterClass |
counter-class |
Extra classes to apply to the counter. | string |
'textarea__count' |
hideCounter |
hide-counter |
Controls the visibility of the counter. | boolean |
false |
inputSize |
input-size |
When using with TkInput , give the input a size of fullwidth to make it take up the whole container. |
"fullwidth" | "large" | "medium" | "small" | "xs" |
'fullwidth' |
maxLength |
max-length |
The maximum number of characters allowed. | number |
undefined |
placement |
placement |
Determines the placement of the counter output. | "bottom" | "top" |
'top' |
text |
text |
The value of the input that will be calculated based on the characters. | string |
undefined |
warningClass |
warning-class |
Classes to apply to warning text. | string |
'textarea__count--error' |
warningText |
warning-text |
Text displayed when approaching character limit. | string |
undefined |