Skip to content

Commit a795d6e

Browse files
authored
fix(useFocusZone): handle add/remove nodes that have focusable children (#1185)
1 parent f506dcf commit a795d6e

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/behaviors/focusZone.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {isFocusable, iterateFocusableElements} from '../utils/iterateFocusableElements'
1+
import {iterateFocusableElements} from '../utils/iterateFocusableElements'
22
import {polyfill as eventListenerSignalPolyfill} from '../polyfills/eventListenerSignal'
33
import {isMacOS} from '../utils/userAgent'
44
import {uniqueId} from '../utils/uniqueId'
@@ -442,12 +442,12 @@ export function focusZone(container: HTMLElement, settings?: FocusZoneSettings):
442442
const observer = new MutationObserver(mutations => {
443443
for (const mutation of mutations) {
444444
for (const addedNode of mutation.addedNodes) {
445-
if (addedNode instanceof HTMLElement && isFocusable(addedNode)) {
445+
if (addedNode instanceof HTMLElement) {
446446
beginFocusManagement(...iterateFocusableElements(addedNode))
447447
}
448448
}
449449
for (const removedNode of mutation.removedNodes) {
450-
if (removedNode instanceof HTMLElement && savedTabIndex.has(removedNode)) {
450+
if (removedNode instanceof HTMLElement) {
451451
endFocusManagement(...iterateFocusableElements(removedNode))
452452
}
453453
}

src/stories/useFocusZone.stories.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,11 @@ export const ChangingSubtree = () => {
408408

409409
const buttons: JSX.Element[] = []
410410
for (let i = 0; i < buttonCount; ++i) {
411-
buttons.push(<MarginButton key={`button${i}`}>{i + 1}</MarginButton>)
411+
buttons.push(
412+
<div>
413+
<MarginButton key={`button${i}`}>{i + 1}</MarginButton>
414+
</div>
415+
)
412416
}
413417

414418
return (

0 commit comments

Comments
 (0)