Skip to content

feat: configurable focus-on-preset-key behavior + CLAUDE.md#236

Merged
asgvard merged 1 commit into
mainfrom
dmytro/autofocus-on-add-configurable
Jun 18, 2026
Merged

feat: configurable focus-on-preset-key behavior + CLAUDE.md#236
asgvard merged 1 commit into
mainfrom
dmytro/autofocus-on-add-configurable

Conversation

@asgvard

@asgvard asgvard commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

What

Two changes:

1. Make the "focus on preset key" behavior configurable

When a focusable is registered via addFocusable, if its focusKey already equals the current focus key (i.e. setFocus(key) was called before the component mounted — a "pre-set" focus key), the service immediately re-focuses it. Until now this was hardcoded.

This adds a new init() option focusOnPresetKey, defaulting to true so existing behavior is unchanged. Apps that don't want this implicit refocus can opt out with init({ focusOnPresetKey: false }).

The gate lives entirely in packages/coreuseFocusable (react) and the legacy package (a pure re-export) inherit it automatically.

2. Add CLAUDE.md

A quick-reference guide for AI agents working in the repo, derived from CONTRIBUTING.md (layout, commands, code style, testing, changesets, PR process).

Notes

  • The core Jest suite couldn't run in a clean checkout: lodash-es is ESM-only and Jest can't transform it out of node_modules. CI only runs eslint + prettier, so this went unnoticed. Added a test-only moduleNameMapper (lodash-eslodash, identical API) plus lodash as a devDependency. The rollup build still bundles lodash-es for the published packages — runtime output is unchanged.

Testing

  • Added two tests in packages/core/src/__tests__/SpatialNavigation.test.ts: default (enabled) auto-focuses a pre-set component on add; focusOnPresetKey: false does not.
  • npm run test → 14 passed (suite now runs at all).
  • npm run lint, npm run prettier, npm run build → all green.

Changeset

minor bump for all three packages (additive new option).

🤖 Generated with Claude Code

Add a `focusOnPresetKey` init option (default `true`) gating the implicit
refocus that fires in addFocusable when a component's focus key was already
set as the current focus key before it mounted. Enabled by default to
preserve backward compatibility.

Also add a CLAUDE.md derived from CONTRIBUTING.md, docs for the new option,
and a changeset. Map lodash-es -> lodash in the core jest config so the
previously-unrunnable test suite executes (build still bundles lodash-es).
@asgvard
asgvard requested a review from a team as a code owner June 18, 2026 12:04
@changeset-bot

changeset-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 62396c0

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

This PR includes changesets to release 3 packages
Name Type
@noriginmedia/norigin-spatial-navigation-core Minor
@noriginmedia/norigin-spatial-navigation-react Minor
@noriginmedia/norigin-spatial-navigation Minor

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

@predikament predikament added enhancement New feature or request documentation Improvements or additions to documentation AI AI skills, modifications, etc. labels Jun 18, 2026
@asgvard
asgvard merged commit a18ed66 into main Jun 18, 2026
1 check passed
@asgvard
asgvard deleted the dmytro/autofocus-on-add-configurable branch June 18, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI AI skills, modifications, etc. documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants