Skip to content

Commit dc0e10f

Browse files
committed
Version bump, changelog, strict values for Direction
1 parent b00e31e commit dc0e10f

5 files changed

Lines changed: 23 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
# [2.0.0]
8+
## Added
9+
- New property for `useFocusable` - `focusBoundaryDirections`, array of directions to block when `isFocusBoundary` is enabled
10+
- New property `useFocusable` - `forceFocus` to mark the component to be the target for auto-restore focus logic when focus is lost
11+
- New global method `doesFocusableExist` to check if the focusable component exists before setting focus on it. Safety feature
12+
13+
## Changed
14+
- [BREAKING] Top level exports `setFocus, getCurrentFocusKey, navigateByDirection, pause, resume, updateAllLayouts` are now exported from `SpatialNavigation` instead of `useFocusable` hook.
15+
16+
## Fixed
17+
- Context display name is now called `FocusContext` in React Devtools
18+
- Updating `lastFocusedChildKey` for newly added parent components
19+
720
# [1.3.3]
821
## Fixed
922
- Fixed the issue where component would have kept itself in the array of `parentsHavingFocusedChild` array after removal

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@noriginmedia/norigin-spatial-navigation",
3-
"version": "1.3.3",
3+
"version": "2.0.0",
44
"description": "React hooks based Spatial Navigation solution",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/SpatialNavigation.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const DIRECTION_UP = 'up';
1717
const DIRECTION_DOWN = 'down';
1818
const KEY_ENTER = 'enter';
1919

20+
export type Direction = 'up' | 'down' | 'left' | 'right';
21+
2022
const DEFAULT_KEY_MAP = {
2123
[DIRECTION_LEFT]: [37],
2224
[DIRECTION_UP]: [38],
@@ -75,7 +77,7 @@ interface FocusableComponent {
7577
preferredChildFocusKey?: string;
7678
focusable: boolean;
7779
isFocusBoundary: boolean;
78-
focusBoundaryDirections?: string[];
80+
focusBoundaryDirections?: Direction[];
7981
autoRestoreFocus: boolean;
8082
forceFocus: boolean;
8183
lastFocusedChildKey?: string;
@@ -88,7 +90,7 @@ interface FocusableComponentUpdatePayload {
8890
preferredChildFocusKey?: string;
8991
focusable: boolean;
9092
isFocusBoundary: boolean;
91-
focusBoundaryDirections?: string[];
93+
focusBoundaryDirections?: Direction[];
9294
onEnterPress: (details?: KeyPressDetails) => void;
9395
onEnterRelease: () => void;
9496
onArrowPress: (direction: string, details: KeyPressDetails) => boolean;

src/useFocusable.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
SpatialNavigation,
1313
FocusableComponentLayout,
1414
FocusDetails,
15-
KeyPressDetails
15+
KeyPressDetails,
16+
Direction
1617
} from './SpatialNavigation';
1718
import { useFocusContext } from './useFocusContext';
1819

@@ -48,7 +49,7 @@ export interface UseFocusableConfig<P = object> {
4849
autoRestoreFocus?: boolean;
4950
forceFocus?: boolean;
5051
isFocusBoundary?: boolean;
51-
focusBoundaryDirections?: string[];
52+
focusBoundaryDirections?: Direction[];
5253
focusKey?: string;
5354
preferredChildFocusKey?: string;
5455
onEnterPress?: EnterPressHandler<P>;

0 commit comments

Comments
 (0)