Skip to content

Commit

Permalink
Version bump, changelog, strict values for Direction
Browse files Browse the repository at this point in the history
  • Loading branch information
asgvard committed Sep 11, 2023
1 parent b00e31e commit dc0e10f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# [2.0.0]
## Added
- New property for `useFocusable` - `focusBoundaryDirections`, array of directions to block when `isFocusBoundary` is enabled
- New property `useFocusable` - `forceFocus` to mark the component to be the target for auto-restore focus logic when focus is lost
- New global method `doesFocusableExist` to check if the focusable component exists before setting focus on it. Safety feature

## Changed
- [BREAKING] Top level exports `setFocus, getCurrentFocusKey, navigateByDirection, pause, resume, updateAllLayouts` are now exported from `SpatialNavigation` instead of `useFocusable` hook.

## Fixed
- Context display name is now called `FocusContext` in React Devtools
- Updating `lastFocusedChildKey` for newly added parent components

# [1.3.3]
## Fixed
- Fixed the issue where component would have kept itself in the array of `parentsHavingFocusedChild` array after removal
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@noriginmedia/norigin-spatial-navigation",
"version": "1.3.3",
"version": "2.0.0",
"description": "React hooks based Spatial Navigation solution",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
6 changes: 4 additions & 2 deletions src/SpatialNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const DIRECTION_UP = 'up';
const DIRECTION_DOWN = 'down';
const KEY_ENTER = 'enter';

export type Direction = 'up' | 'down' | 'left' | 'right';

const DEFAULT_KEY_MAP = {
[DIRECTION_LEFT]: [37],
[DIRECTION_UP]: [38],
Expand Down Expand Up @@ -75,7 +77,7 @@ interface FocusableComponent {
preferredChildFocusKey?: string;
focusable: boolean;
isFocusBoundary: boolean;
focusBoundaryDirections?: string[];
focusBoundaryDirections?: Direction[];
autoRestoreFocus: boolean;
forceFocus: boolean;
lastFocusedChildKey?: string;
Expand All @@ -88,7 +90,7 @@ interface FocusableComponentUpdatePayload {
preferredChildFocusKey?: string;
focusable: boolean;
isFocusBoundary: boolean;
focusBoundaryDirections?: string[];
focusBoundaryDirections?: Direction[];
onEnterPress: (details?: KeyPressDetails) => void;
onEnterRelease: () => void;
onArrowPress: (direction: string, details: KeyPressDetails) => boolean;
Expand Down
5 changes: 3 additions & 2 deletions src/useFocusable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
SpatialNavigation,
FocusableComponentLayout,
FocusDetails,
KeyPressDetails
KeyPressDetails,
Direction
} from './SpatialNavigation';
import { useFocusContext } from './useFocusContext';

Expand Down Expand Up @@ -48,7 +49,7 @@ export interface UseFocusableConfig<P = object> {
autoRestoreFocus?: boolean;
forceFocus?: boolean;
isFocusBoundary?: boolean;
focusBoundaryDirections?: string[];
focusBoundaryDirections?: Direction[];
focusKey?: string;
preferredChildFocusKey?: string;
onEnterPress?: EnterPressHandler<P>;
Expand Down

0 comments on commit dc0e10f

Please sign in to comment.