Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
camertron committed Oct 17, 2024
1 parent 680bb31 commit bc887b6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import typescript from '@rollup/plugin-typescript'
import packageJson from './package.json' assert {type: 'json'}
import packageJson from './package.json' with {type: 'json'}

const dependencyTypes = ['peerDependencies', 'dependencies', 'devDependencies']
const dependencies = new Set(
Expand Down
54 changes: 35 additions & 19 deletions src/focus-zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,11 @@ export function focusZone(container: HTMLElement, settings?: FocusZoneSettings):

activeDescendantControl?.removeAttribute('aria-activedescendant')
container.removeAttribute(hasActiveDescendantAttribute)
previouslyActiveElement?.removeAttribute(isActiveDescendantAttribute)

for (const item of container.querySelectorAll(`[${isActiveDescendantAttribute}]`)) {
item?.removeAttribute(isActiveDescendantAttribute)
}

activeDescendantCallback?.(undefined, previouslyActiveElement, false)
}

Expand Down Expand Up @@ -580,13 +584,17 @@ export function focusZone(container: HTMLElement, settings?: FocusZoneSettings):
)

if (activeDescendantControl) {
container.addEventListener('focusin', event => {
if (event.target instanceof HTMLElement && focusableElements.includes(event.target)) {
// Move focus to the activeDescendantControl if one of the descendants is focused
activeDescendantControl.focus({preventScroll})
updateFocusedElement(event.target)
}
})
container.addEventListener(
'focusin',
event => {
if (event.target instanceof HTMLElement && focusableElements.includes(event.target)) {
// Move focus to the activeDescendantControl if one of the descendants is focused
activeDescendantControl.focus({preventScroll})
updateFocusedElement(event.target)
}
},
{signal},
)
container.addEventListener(
'mousemove',
({target}) => {
Expand All @@ -604,17 +612,25 @@ export function focusZone(container: HTMLElement, settings?: FocusZoneSettings):
)

// Listeners specifically on the controlling element
activeDescendantControl.addEventListener('focusin', () => {
// Focus moved into the active descendant input. Activate current or first descendant.
if (!currentFocusedElement) {
updateFocusedElement(getFirstFocusableElement())
} else {
setActiveDescendant(undefined, currentFocusedElement)
}
})
activeDescendantControl.addEventListener('focusout', () => {
clearActiveDescendant()
})
activeDescendantControl.addEventListener(
'focusin',
() => {
// Focus moved into the active descendant input. Activate current or first descendant.
if (!currentFocusedElement) {
updateFocusedElement(getFirstFocusableElement())
} else {
setActiveDescendant(undefined, currentFocusedElement)
}
},
{signal},
)
activeDescendantControl.addEventListener(
'focusout',
() => {
clearActiveDescendant()
},
{signal},
)
} else {
// This is called whenever focus enters an element in the container
container.addEventListener(
Expand Down

0 comments on commit bc887b6

Please sign in to comment.