Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve #56 via checking for array type #57

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/Toaster.vue
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ const actualTheme = ref(
)

const cnFunction = computed(() => props.cn || _cn)
const listRef = ref<HTMLOListElement | null>(null)
const listRef = ref<HTMLOListElement[] | HTMLOListElement | null>(null)
const lastFocusedElementRef = ref<HTMLElement | null>(null)
const isFocusWithinRef = ref(false)

Expand Down Expand Up @@ -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
Saeid-Za marked this conversation as resolved.
Show resolved Hide resolved

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
}
}
Expand Down