Skip to content

Commit 5bced15

Browse files
authored
Merge pull request #432 from ownego/fix/correct-use-of-watch-focus-manager
Fix: correct use of watch in useFocusManager.ts
2 parents a5ca931 + b8d2710 commit 5bced15

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/use/useFocusManager.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
inject,
55
ref,
66
computed,
7-
watchEffect,
7+
watch,
88
onUnmounted,
99
} from 'vue';
1010

@@ -33,13 +33,17 @@ export function useFocusManager({ trapping }: Options) {
3333

3434
const canSafelyFocus = computed(() => trapFocusList.value[0] === String(id));
3535

36-
watchEffect(() => {
37-
if (!trapping) {
38-
return;
39-
}
40-
41-
addFocusItem(String(id));
42-
});
36+
watch(
37+
() => [trapping, id],
38+
([newTrappingVal, newId]) => {
39+
if (!newTrappingVal) {
40+
return;
41+
}
42+
43+
addFocusItem(String(newId));
44+
},
45+
{ immediate: true }
46+
);
4347

4448
onUnmounted(() => {
4549
removeFocusItem(String(id));

0 commit comments

Comments
 (0)