Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit b23e51d

Browse files
committed
feat: defineExpose reset on BFormFile input
* Allows to reset the input on the BFormFile component through a template ref * Add documentation for previously added focus, blur exposed methods
1 parent 447bcec commit b23e51d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

apps/docs/src/docs/components/form-file.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@ You can use the `state` prop to provide visual feedback on the state of the inpu
220220

221221
With inputs that are of type `file`, the value is strictly `uni-directional`. Meaning that you cannot change the value of the input via JavaScript. You can change the value of the `v-model`, and this will work for an "outside view", however, the actual `input` element will not have its [FileList](https://developer.mozilla.org/en-US/docs/Web/API/FileList) changed. This is for security reasons as a malicious script could attempt to read and steal documents
222222

223+
## Exposed functions
224+
225+
The BFormFile exposes functions to control the component: `focus(), blur(), reset()`. These are accessed through the [template ref](https://vuejs.org/guide/essentials/template-refs.html#template-refs).
226+
227+
1. Focus: focuses the file input
228+
2. Blur: blurs the file input focus
229+
3. Reset: Resets the file selection so that no file is selected
230+
223231
<ComponentReference :data="data" />
224232

225233
<script setup lang="ts">

packages/bootstrap-vue-next/src/components/BFormFile/BFormFile.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,22 @@ const onDrop = (e: Event) => {
144144
}
145145
}
146146
147+
/**
148+
* Reset the form input
149+
*/
150+
const reset = () => {
151+
if (input.value !== null) {
152+
input.value.value = ''
153+
}
154+
}
155+
147156
defineExpose({
148157
focus: () => {
149158
focused.value = true
150159
},
151160
blur: () => {
152161
focused.value = false
153162
},
163+
reset,
154164
})
155165
</script>

0 commit comments

Comments
 (0)