feat(Input/Textarea): expose ref

This commit is contained in:
Benjamin Canac
2024-07-31 15:28:28 +02:00
parent c3ee509c65
commit 74a6bca2b3
6 changed files with 29 additions and 1 deletions

View File

@@ -24,7 +24,7 @@ links:
:component-events :component-events
### Exposed ### Expose
When accessing the component via a template ref, you can use the following: When accessing the component via a template ref, you can use the following:

View File

@@ -183,6 +183,14 @@ props:
:component-events :component-events
### Expose
When accessing the component via a template ref, you can use the following:
| Name | Type |
| ---- | ---- |
| `inputRef`{lang="ts-type"} | `Ref<HTMLInputElement \| null>`{lang="ts-type"} |
## Theme ## Theme
:component-theme :component-theme

View File

@@ -144,6 +144,14 @@ props:
:component-events :component-events
### Expose
When accessing the component via a template ref, you can use the following:
| Name | Type |
| ---- | ---- |
| `textareaRef`{lang="ts-type"} | `Ref<HTMLTextAreaElement \| null>`{lang="ts-type"} |
## Theme ## Theme
:component-theme :component-theme

View File

@@ -133,6 +133,10 @@ function onBlur(event: FocusEvent) {
emits('blur', event) emits('blur', event)
} }
defineExpose({
inputRef
})
onMounted(() => { onMounted(() => {
setTimeout(() => { setTimeout(() => {
autoFocus() autoFocus()

View File

@@ -228,6 +228,10 @@ function onUpdateOpen(value: boolean) {
emits('focus', event) emits('focus', event)
} }
} }
defineExpose({
inputRef
})
</script> </script>
<template> <template>

View File

@@ -151,6 +151,10 @@ watch(() => modelValue, () => {
nextTick(autoResize) nextTick(autoResize)
}) })
defineExpose({
textareaRef
})
onMounted(() => { onMounted(() => {
setTimeout(() => { setTimeout(() => {
autoResize() autoResize()