Skip to content

feat: add clearLastFocusedChild(focusKey) to core - #250

Merged
Braggiouy merged 3 commits into
mainfrom
bruno/clear-last-focused-child
Oct 23, 2026
Merged

Braggiouy merged 3 commits into
mainfrom
bruno/clear-last-focused-child

Conversation

@Braggiouy

@Braggiouy Braggiouy commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Overview

Adds a public clearLastFocusedChild(focusKey) to make a container forget its last focused child. The next time focus enters the container, it goes to preferredChildFocusKey (or the first child). Focus is not moved, and the container keeps remembering children as usual afterwards.

Why

There is currently no public way to clear a container's remembered child once. saveLastFocusedChild: false disables the memory permanently, and it can't be toggled at runtime because it is only read when the component registers.

Changes

  • SpatialNavigationService.clearLastFocusedChild(focusKey), bound and exported like the other public functions. No-op for unknown keys.
  • Tests: memory restored when not cleared; after clearing, entry falls back to the first child or to preferredChildFocusKey; focus is not moved; unknown keys don't throw.
  • API reference entry in docs/api-reference/SpatialNavigation.md.
  • Changeset: minor for -core and the legacy norigin-spatial-navigation package (it re-exports core).

Usage

import { clearLastFocusedChild, setFocus } from '@noriginmedia/norigin-spatial-navigation-core';

function onBackPressed() {
  setFocus('HEADER_BACK_BUTTON');
  // Pressing down from the header now enters CONTENT_LIST at its
  // preferredChildFocusKey (or first child), not where focus was before.
  clearLastFocusedChild('CONTENT_LIST');
}

@Braggiouy Braggiouy self-assigned this Oct 22, 2026
@Braggiouy Braggiouy added the enhancement New feature or request label Oct 22, 2026
@changeset-bot

changeset-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9563d89

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

This PR includes changesets to release 2 packages
Name Type
@noriginmedia/norigin-spatial-navigation-core 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

@Braggiouy
Braggiouy marked this pull request as ready for review October 22, 2026 08:06
@Braggiouy
Braggiouy requested a review from a team as a code owner October 22, 2026 08:06

@daosro daosro left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@Braggiouy
Braggiouy merged commit 9a6d9fc into main Oct 23, 2026
1 check passed
@Braggiouy
Braggiouy deleted the bruno/clear-last-focused-child branch October 23, 2026 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants