mirror of
https://github.com/zammad/zammad
synced 2026-05-24 09:48:36 +00:00
18 lines
654 B
TypeScript
18 lines
654 B
TypeScript
// Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/
|
|
|
|
export const useDelegateFocus = (containerId: string, firstChildId: string) => {
|
|
const delegateFocus = (event: FocusEvent) => {
|
|
const containerElement: Maybe<HTMLElement> = document.querySelector(`#${containerId}`)
|
|
|
|
const firstChildElement: Maybe<HTMLElement> = document.querySelector(`#${firstChildId}`)
|
|
|
|
// Check if the element that just lost focus is another child element of the container.
|
|
if (event.relatedTarget && containerElement?.contains(event.relatedTarget as Node)) return
|
|
|
|
firstChildElement?.focus()
|
|
}
|
|
|
|
return {
|
|
delegateFocus,
|
|
}
|
|
}
|