From 9e6d7e52d028c0fa64a9ba05a89f9558526e4e71 Mon Sep 17 00:00:00 2001 From: Saeid Zareie Date: Tue, 5 Mar 2024 13:36:05 +0330 Subject: [PATCH 1/2] fix: resolve #56 via checking for array type --- packages/Toaster.vue | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/Toaster.vue b/packages/Toaster.vue index 6518771..19d0240 100644 --- a/packages/Toaster.vue +++ b/packages/Toaster.vue @@ -211,7 +211,7 @@ const actualTheme = ref( ) const cnFunction = computed(() => props.cn || _cn) -const listRef = ref(null) +const listRef = ref(null) const lastFocusedElementRef = ref(null) const isFocusWithinRef = ref(false) @@ -358,16 +358,16 @@ watchEffect((onInvalidate) => { (key) => (event as any)[key] || event.code === key ) + const listRefItem = Array.isArray(listRef.value) ? listRef.value.at(0) : listRef.value + if (isHotkeyPressed) { expanded.value = true - listRef.value?.focus() + listRefItem?.focus() } - if ( - event.code === 'Escape' && - (document.activeElement === listRef.value || - listRef.value?.contains(document.activeElement)) - ) { + const isItemActive = document.activeElement === listRef.value || listRefItem.contains(document.activeElement) + + if (event.code === 'Escape' && isItemActive) { expanded.value = false } } From c03d9dc4f57402e8666001fd2c076353387a37aa Mon Sep 17 00:00:00 2001 From: Saeid Zareie Date: Wed, 6 Mar 2024 08:30:09 +0330 Subject: [PATCH 2/2] fix: changing index operator, adding '?' operator --- packages/Toaster.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/Toaster.vue b/packages/Toaster.vue index 19d0240..f9f38e6 100644 --- a/packages/Toaster.vue +++ b/packages/Toaster.vue @@ -358,14 +358,14 @@ watchEffect((onInvalidate) => { (key) => (event as any)[key] || event.code === key ) - const listRefItem = Array.isArray(listRef.value) ? listRef.value.at(0) : listRef.value + const listRefItem = Array.isArray(listRef.value) ? listRef.value[0] : listRef.value if (isHotkeyPressed) { expanded.value = true listRefItem?.focus() } - const isItemActive = document.activeElement === listRef.value || listRefItem.contains(document.activeElement) + const isItemActive = document.activeElement === listRef.value || listRefItem?.contains(document.activeElement) if (event.code === 'Escape' && isItemActive) { expanded.value = false