Skip to content

Isolate trap breaks compatibility with previous minor version on global trap stack #1729

@ShGKme

Description

@ShGKme

focus-trap supports having a global trap stack via trapStack option.

Although it is not promised in the documentation, it supported not only multiple focus-trap instances, but also multiple focus-trap packages. This is valuable for application platforms where multiple independent applications/libraries are running on the same page without module federations.

// Anywhere
window.TRAP_STACK ??= []

// UI library
import { createFocusTrap } from 'focus-trap' // v7.7.0
createFocusTrap(el, {
  trapStack: window.TRAP_STACK,
})

// App 1
import { createFocusTrap } from 'focus-trap' // v7.7.0
createFocusTrap(el, {
  trapStack: window.TRAP_STACK,
})

// App 2
import { createFocusTrap } from 'focus-trap' // v7.6.8
createFocusTrap(el, {
  trapStack: window.TRAP_STACK,
})

While it worked for a long time, starting v7.7 it results in preexistingTrap._setSubtreeIsolation is not a function.

Proposal: handle a case when a focus trap instance from the trap stack has no subtree isolation implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions