← Back to Pull requests

feat(bulma-ui): export useFocusTrap, counting the stops the browser's Tab visits #862

Open
unknown opened this pull request with 298 lines diff across 3 files
View on GitHub
unknown unknown commented on Oct 02, 2026 01:29 UTC
Author

Closes #772.

An app building its own overlay had to write a focus trap again, though the pickers already had one. useFocusTrap(ref, { active, initialFocusRef, restoreFocus }) moves from form/_pickerInternals to helpers/ and is exported. restoreFocus also takes a ref, such as the button that opened a panel.

Tab stops match the browser's Tab. The tabIndex property can't tell on its own: it reads -1 for an editable region and an <embed> that Tab visits, and 0 for a <video> without controls that it skips. So a valid tabindex attribute decides, and otherwise the element's kind does.

  • Counted: links and image-map areas with an href, form controls, <iframe>, <embed> and <object>, <audio> and <video> with controls, a <details> summary, and editable regions (once each).

  • Skipped: hidden, disabled (fieldsets too), inert and negative-tabindex elements, a closed <details>' content, and all but one radio of a group.

  • Open shadow roots are walked through the flattened tree, so slotted content counts where its slot is, and is hidden with it.
  • Behaviour.

  • It wraps by document position, so focus resting on the container can't Shift+Tab out.

  • It stands aside when a nested trap has already handled Tab.

  • If a Tab it let through still takes focus out (a browser can leave out a stop the page has), focus goes back to the other end. Pointer and script focus moves are left alone, and the docs say why.

  • It restores focus only while it still holds it, and it waits for hydration so it finds a container that appears then.
  • What changes for the pickers: the old selector counted DateInput's roving day cells, so Tab from the focused day left the popover, and Shift+Tab from the month button landed on a day from another month. Both now wrap, and a DateInput test holds it. TimeInput's first and last stops are unchanged.

    The helper page lists the stops and the limits (frames, native date inputs, closed shadow roots, scroll regions), and says a portal inside the trapped container escapes the trap. The matrix credits the Focus trap row, and the custom-component skill points at the hook.

    This is the last of three PRs split out of #851, alongside ClientOnly and Portal, and closes the issue. They share the index.ts export block, PUBLIC_EXPORTS, the comparison data and the generated files.

    pnpm all passes locally.

    Diff: 298 lines (+223 / -75) across 3 files Reviewer: claude[bot] Review duration: 24m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.40) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 298 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.341
    Real PR Conversation Timeline
    1 comments
    "Review active on #862"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40% (MEDIUM) · Higher = larger blast radius
    40%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.8% · Safe to merge
    22.8%