Skip to content

Commit bd9dfaf

Browse files
authored
fix(Select): handle form autofill event (#2195)
1 parent 519e40c commit bd9dfaf

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

packages/core/src/Select/BubbleSelect.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import { ref, watch } from 'vue'
33
import { VisuallyHidden } from '@/VisuallyHidden'
4+
import { injectSelectRootContext } from './SelectRoot.vue'
45
56
interface BubbleSelectProps {
67
autocomplete?: string
@@ -16,6 +17,7 @@ interface BubbleSelectProps {
1617
1718
const props = defineProps<BubbleSelectProps>()
1819
const selectElement = ref<HTMLElement>()
20+
const rootContext = injectSelectRootContext()
1921
2022
// This would bubble "change" event to form, with the target as Select element.
2123
watch(() => props.value, (cur, prev) => {
@@ -32,6 +34,14 @@ watch(() => props.value, (cur, prev) => {
3234
}
3335
})
3436
37+
/**
38+
* Form autofill will trigger an `input` event on the `select` element.
39+
* We listen to that event and update our internal state to support it.
40+
*/
41+
function handleInput(event: Event) {
42+
rootContext.onValueChange((event.target as HTMLSelectElement).value)
43+
}
44+
3545
/**
3646
* We purposefully use a `select` here to support form autofill as much
3747
* as possible.
@@ -49,6 +59,7 @@ watch(() => props.value, (cur, prev) => {
4959
<select
5060
ref="selectElement"
5161
v-bind="props"
62+
@input="handleInput"
5263
>
5364
<slot />
5465
</select>

0 commit comments

Comments
 (0)