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

Commit 1248cea

Browse files
committed
fix: defineExpose focus and blur on Input items
1 parent 00842d2 commit 1248cea

File tree

9 files changed

+85
-12
lines changed

9 files changed

+85
-12
lines changed

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ const parentData = inject(checkboxGroupKey, null)
134134
135135
const input = ref<HTMLElement | null>(null)
136136
137-
useFocus(input, {
137+
const {focused} = useFocus(input, {
138138
initialValue: autofocusBoolean.value,
139139
})
140140
@@ -192,4 +192,13 @@ const classesObject = computed(() => ({
192192
const computedClasses = getClasses(classesObject)
193193
const inputClasses = getInputClasses(classesObject)
194194
const labelClasses = getLabelClasses(classesObject)
195+
196+
defineExpose({
197+
focus: () => {
198+
focused.value = true
199+
},
200+
blur: () => {
201+
focused.value = false
202+
},
203+
})
195204
</script>

packages/bootstrap-vue-next/src/components/BFormCheckbox/BFormCheckboxGroup.vue

+10-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ const validatedBoolean = useBooleanish(() => props.validated)
118118
119119
const element = ref<HTMLElement | null>(null)
120120
121-
useFocus(element, {
121+
const {focused} = useFocus(element, {
122122
initialValue: autofocusBoolean.value,
123123
})
124124
@@ -198,4 +198,13 @@ const classesObject = computed(() => ({
198198
}))
199199
const computedAttrs = getGroupAttr(classesObject)
200200
const computedClasses = getGroupClasses(classesObject)
201+
202+
defineExpose({
203+
focus: () => {
204+
focused.value = true
205+
},
206+
blur: () => {
207+
focused.value = false
208+
},
209+
})
201210
</script>

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const stateClass = useStateClass(stateBoolean)
112112
113113
const input = ref<HTMLInputElement | null>(null)
114114
115-
useFocus(input, {initialValue: autofocusBoolean.value})
115+
const {focused} = useFocus(input, {initialValue: autofocusBoolean.value})
116116
117117
const hasLabelSlot = computed(() => !isEmptySlot(slots['label']))
118118
const computedAccept = computed(() =>
@@ -143,4 +143,13 @@ const onDrop = (e: Event) => {
143143
e.preventDefault()
144144
}
145145
}
146+
147+
defineExpose({
148+
focus: () => {
149+
focused.value = true
150+
},
151+
blur: () => {
152+
focused.value = false
153+
},
154+
})
146155
</script>

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

+5
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ const computedClasses = computed(() => {
106106
]
107107
})
108108
109+
defineExpose({
110+
focus,
111+
blur,
112+
})
113+
109114
// const highlight = () => {
110115
// if (isHighlighted.value === true) return
111116
// isHighlighted.value = true

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const parentData = inject(radioGroupKey, null)
108108
109109
const input = ref<HTMLElement | null>(null)
110110
111-
useFocus(input, {
111+
const {focused} = useFocus(input, {
112112
initialValue: autofocusBoolean.value,
113113
})
114114
@@ -168,4 +168,13 @@ const classesObject = computed(() => ({
168168
const computedClasses = getClasses(classesObject)
169169
const inputClasses = getInputClasses(classesObject)
170170
const labelClasses = getLabelClasses(classesObject)
171+
172+
defineExpose({
173+
focus: () => {
174+
focused.value = true
175+
},
176+
blur: () => {
177+
focused.value = false
178+
},
179+
})
171180
</script>

packages/bootstrap-vue-next/src/components/BFormRadio/BFormRadioGroup.vue

+10-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const validatedBoolean = useBooleanish(() => props.validated)
104104
105105
const element = ref<HTMLElement | null>(null)
106106
107-
useFocus(element, {
107+
const {focused} = useFocus(element, {
108108
initialValue: autofocusBoolean.value,
109109
})
110110
@@ -165,4 +165,13 @@ const classesObject = computed(() => ({
165165
}))
166166
const computedAttrs = getGroupAttr(classesObject)
167167
const computedClasses = getGroupClasses(classesObject)
168+
169+
defineExpose({
170+
focus: () => {
171+
focused.value = true
172+
},
173+
blur: () => {
174+
focused.value = false
175+
},
176+
})
168177
</script>

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const stateClass = useStateClass(stateBoolean)
119119
120120
const input = ref<HTMLElement>()
121121
122-
useFocus(input, {
122+
const {focused} = useFocus(input, {
123123
initialValue: autofocusBoolean.value,
124124
})
125125
@@ -157,4 +157,13 @@ const localValue = computed({
157157
})
158158
},
159159
})
160+
161+
defineExpose({
162+
focus: () => {
163+
focused.value = true
164+
},
165+
blur: () => {
166+
focused.value = false
167+
},
168+
})
160169
</script>

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

+15-6
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
:id="`${computedId}selected_tags__`"
1313
class="visually-hidden"
1414
:for="_inputId"
15-
:aria-live="focus ? 'polite' : 'off'"
15+
:aria-live="focused ? 'polite' : 'off'"
1616
aria-atomic="true"
1717
aria-relevant="additions text"
1818
>{{ tags.join(', ') }}</output
1919
>
2020
<div
2121
:id="`${computedId}removed_tags__`"
2222
role="status"
23-
:aria-live="focus ? 'assertive' : 'off'"
23+
:aria-live="focused ? 'assertive' : 'off'"
2424
aria-atomic="true"
2525
class="visually-hidden"
2626
>
@@ -247,7 +247,6 @@ const _inputId = computed<string>(() => props.inputId || `${computedId.value}inp
247247
const tags = ref<string[]>(modelValue.value)
248248
const inputValue = ref<string>('')
249249
const shouldRemoveOnDelete = ref<boolean>(modelValue.value.length > 0)
250-
const focus = ref<boolean>(false)
251250
const lastRemovedTag = ref<string>('')
252251
const validTags = ref<string[]>([])
253252
const invalidTags = ref<string[]>([])
@@ -258,7 +257,7 @@ const computedClasses = computed(() => [
258257
{
259258
[`form-control-${props.size}`]: props.size !== 'md',
260259
disabled: disabledBoolean.value,
261-
focus: focus.value,
260+
focus: focused.value,
262261
},
263262
])
264263
@@ -334,12 +333,12 @@ const onFocus = (e: FocusEvent): void => {
334333
return
335334
}
336335
337-
focus.value = true
336+
focused.value = true
338337
emit('focus', e)
339338
}
340339
341340
const onBlur = (e: FocusEvent): void => {
342-
focus.value = false
341+
focused.value = false
343342
emit('blur', e)
344343
}
345344
@@ -447,4 +446,14 @@ const removeTag = (tag?: string): void => {
447446
lastRemovedTag.value = tags.value.splice(tagIndex, 1).toString()
448447
modelValue.value = tags.value
449448
}
449+
450+
// TODO these focus/blur events aren't quite in line with use useFormInput implementation. Perhaps we should bring them together?
451+
defineExpose({
452+
focus: () => {
453+
focused.value = true
454+
},
455+
blur: () => {
456+
focused.value = false
457+
},
458+
})
450459
</script>

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

+5
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,9 @@ const computedClasses = computed(() => [
9494
const computedStyles = computed<CSSProperties>(() => ({
9595
resize: noResizeBoolean.value ? 'none' : undefined,
9696
}))
97+
98+
defineExpose({
99+
focus,
100+
blur,
101+
})
97102
</script>

0 commit comments

Comments
 (0)