diff --git a/docs/components/content/examples/TextareaExampleSlotCounter.vue b/docs/components/content/examples/TextareaExampleSlotCounter.vue new file mode 100644 index 0000000000..c4dc152348 --- /dev/null +++ b/docs/components/content/examples/TextareaExampleSlotCounter.vue @@ -0,0 +1,24 @@ + + + diff --git a/docs/content/3.forms/2.textarea.md b/docs/content/3.forms/2.textarea.md index f84871e81a..b91fce6c9f 100644 --- a/docs/content/3.forms/2.textarea.md +++ b/docs/content/3.forms/2.textarea.md @@ -132,6 +132,31 @@ props: --- :: +### Counter + +Use the `counter` prop to enable the counter and to set a maximum value. The counter will show if you are focusing the textarea or when setting `persistent-counter`. This is only visual and not validating the input. + +::component-card +--- +baseProps: + modelValue: 'This is an example of the counter prop' +props: + counter: '540' + persistentCounter: false +excludedProps: + - counter + +--- +:: + +## Slots + +### `counter` + +You can use the `#counter` slot to show a custom counter. It receives `focused` `letterCount` and `maxValue` of the textarea. + +:component-example{component="textarea-example-slot-counter"} + ## Props :component-props diff --git a/src/runtime/components/forms/Textarea.vue b/src/runtime/components/forms/Textarea.vue index d3dff6a31e..b499b88bae 100644 --- a/src/runtime/components/forms/Textarea.vue +++ b/src/runtime/components/forms/Textarea.vue @@ -16,12 +16,17 @@ @blur="onBlur" @change="onChange" /> + + {{ maxValue ? `${letterCount} / ${maxValue}` : + String(letterCount) }} +