Skip to content

upgrade: focus and active-element packages migration and adaptation upgrade for Solid 2.0#896

Open
davedbase wants to merge 14 commits into
solidjs-community:nextfrom
davedbase:update/v2/autofocus
Open

upgrade: focus and active-element packages migration and adaptation upgrade for Solid 2.0#896
davedbase wants to merge 14 commits into
solidjs-community:nextfrom
davedbase:update/v2/autofocus

Conversation

@davedbase
Copy link
Copy Markdown
Member

@davedbase davedbase commented May 13, 2026

Summary

  • Renames the autofocus package to @solid-primitives/focus — directory, npm name, all internal references, and the root README table row updated
  • Ports createFocusTrap from solid-focus-trap (corvu, by Jasmin Noetzli / GiyoMoon) into the focus package, fully adapted for Solid.js 2.0
  • Adds afterPaint (double-requestAnimationFrame helper) to @solid-primitives/utils, ported from @corvu/utils/dom
  • Splits autofocus / createAutofocus into their own src/autofocus.ts file, consistent with src/focusTrap.ts
  • Full attribution to Jasmin Noetzli in LICENSE, package.json contributors, and README.md

What createFocusTrap does

Traps keyboard focus inside a given DOM element, cycling through focusable children on Tab / Shift+Tab. Uses a MutationObserver to react to DOM changes and restores focus to the previously-focused element when deactivated.

const [ref, setRef] = createSignal<HTMLElement | null>(null);

createFocusTrap({
  element: ref,
  enabled: () => isOpen(),
});

<div ref={setRef}>...</div>

Solid 2.0 adaptations

  • createEffect uses the split compute/apply model; cleanup returned from apply instead of onCleanup
  • mergeProps removed — defaults handled inline with ?? true
  • createSignal for focusableElements uses INTERNAL_OPTIONS (ownedWrite: true) since it is written from within effect apply functions
  • access / MaybeAccessor sourced from @solid-primitives/utils instead of @corvu/utils/reactivity
  • afterPaint sourced from @solid-primitives/utils instead of @corvu/utils/dom

Breaking Changes

Peer dependencies: solid-js@^2.0.0-beta.12 and @solidjs/web@^2.0.0-beta.12 are now required.

  • makeFocusListener and createFocusSignal have moved to @solid-primitives/focus. Import them from there instead:
    // Before
    import { makeFocusListener, createFocusSignal } from "@solid-primitives/active-element";
    // After
    import { makeFocusListener, createFocusSignal } from "@solid-primitives/focus";
  • isServer is now sourced from @solidjs/web internally (no user-facing API change)

Summary by CodeRabbit

Release Notes

  • Breaking Changes

    • Updated to Solid.js v2.0 (beta.12) with new peer dependency requirements.
    • The use:autofocus directive has been removed; use ref={autofocus()} as a ref callback instead.
    • makeFocusListener and createFocusSignal have been moved to @solid-primitives/focus package.
  • New Features

    • Introduced createFocusTrap for keyboard focus management and trapping within containers.
    • Consolidated autofocus and focus utilities into unified @solid-primitives/focus package.

Review Change Stack

@davedbase davedbase added this to the Solid 2.0 Migration milestone May 13, 2026
@davedbase davedbase marked this pull request as ready for review May 13, 2026 14:23
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 13, 2026

🦋 Changeset detected

Latest commit: 92ed7f7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@solid-primitives/active-element Major
@solid-primitives/focus Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

# Conflicts:
#	pnpm-lock.yaml
@davedbase davedbase changed the title upgrade: focus package migration and adaptation upgrade for Solid 2.0 upgrade: focus and active-element packages migration and adaptation upgrade for Solid 2.0 May 13, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 23, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 10759d6a-b443-4d98-ac45-fa58af202f92

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@davedbase davedbase marked this pull request as draft May 23, 2026 15:46
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/focus/src/focusSignal.ts`:
- Around line 45-48: The initial focus-state initializer passed to
createHydratableSignal wrongly compares document.activeElement to the reactive
accessor itself when target may be an accessor; update that initializer in the
createHydratableSignal call (the arrow function creating isActive/setIsActive)
to resolve the accessor first (e.g., const el = typeof target === 'function' ?
target() : target) and then compare document.activeElement === el so the initial
isActive is correct for both element targets and accessor targets.

In `@README.md`:
- Line 26: Update the README row for the focus package to list all migrated APIs
by adding makeFocusListener, createFocusSignal, and createFocusTrap alongside
autofocus and createAutofocus; locate the table row containing the focus package
badges and links (the line referencing autofocus/createAutofocus) and append
links and labels for makeFocusListener, createFocusSignal, and createFocusTrap
so the package entry reflects the current exported primitives.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7abc55b6-f96d-48c5-8e67-f69ab368afd8

📥 Commits

Reviewing files that changed from the base of the PR and between 76d6f2e and 10bcfdb.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (24)
  • .changeset/active-element-solid2-migration.md
  • .changeset/autofocus-solid2-migration.md
  • .changeset/focus-solid2-migration.md
  • .changeset/pre.json
  • README.md
  • packages/active-element/package.json
  • packages/active-element/src/index.ts
  • packages/active-element/test/index.test.ts
  • packages/active-element/test/server.test.ts
  • packages/autofocus/README.md
  • packages/autofocus/test/index.test.tsx
  • packages/focus/CHANGELOG.md
  • packages/focus/LICENSE
  • packages/focus/README.md
  • packages/focus/dev/index.tsx
  • packages/focus/package.json
  • packages/focus/src/autofocus.ts
  • packages/focus/src/focusSignal.ts
  • packages/focus/src/focusTrap.ts
  • packages/focus/src/index.ts
  • packages/focus/test/index.test.tsx
  • packages/focus/test/server.test.ts
  • packages/focus/tsconfig.json
  • packages/utils/src/index.ts
💤 Files with no reviewable changes (3)
  • .changeset/autofocus-solid2-migration.md
  • packages/autofocus/README.md
  • packages/autofocus/test/index.test.tsx

Comment thread packages/focus/src/focusSignal.ts
Comment thread README.md Outdated
@davedbase davedbase marked this pull request as ready for review May 23, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant