All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
- New callback
onArrowRelease
- Enhanced native DOM focus behavior by adding and removing the data-focused attribute during focus transitions.
- New export for
SpatialNavigationcore service with types
- Some Prettier formatting issues
- New init config option
distanceCalculationMethodthat allows switching between edge-based, center-based and corner-based (default) distance calculations. - Support for a custom distance calculation function via the
customDistanceCalculationFunctionoption, enabling custom logic for determining distances between focusable components. This will override thegetSecondaryAxisDistancemethod. - Added
updateRTLmethod to update the RTL behavior dynamically. This method allows toggling the Right-to-Left layout at runtime, updating the spatial navigation behavior without requiring reinitialization.
- new
initconfig optiondomNodeFocusOptionsfor passing FocusOptions when usingshouldFocusDOMNode
- new
initconfig optionshouldUseNativeEventsthat enables the use of native events for triggering actions, such as clicks or key presses. - new
initconfig optionrtlthat changes focus behavior for layouts in right-to-left (RTL) languages such as Arabic and Hebrew.
- Console warning when passing an empty
reftouseFocusable - Support for string names for Key Events. Now you can configure the key map with numbers or event names like
ArrowRight.
- Restoring focus to the parent with
preferredChildFocusKeyset
- New property for
useFocusable-focusBoundaryDirections, array of directions to block whenisFocusBoundaryis enabled - New property
useFocusable-forceFocusto mark the component to be the target for auto-restore focus logic when focus is lost - New global method
doesFocusableExistto check if the focusable component exists before setting focus on it. Safety feature
- [BREAKING] Top level exports
setFocus, getCurrentFocusKey, navigateByDirection, pause, resume, updateAllLayoutsare now exported fromSpatialNavigationinstead ofuseFocusablehook.
- Context display name is now called
FocusContextin React Devtools - Updating
lastFocusedChildKeyfor newly added parent components
- Fixed the issue where component would have kept itself in the array of
parentsHavingFocusedChildarray after removal - Further improvements to
autoRestoreFocuslogic to trigger not only on Lead components, but also on Parents that had focused child when being removed. Edge case, normally children are removed first.
- Fixed a bug where parents were not updating their
hasFocusedChildwhen new child is created and focused right away - Fixed a bug where
lastFocusedChildwas updated only on blur, but not on manual focus, resulting in a wrong key being stored
- Renamed
useFocusedContextfile touseFocusContextto match the export name
- Extra debug logs, printing focusable components data in addition to DOM nodes.
- Extra call to set
focusedstate tofalseon unmount. This is to support "double-mount" in Strict mode in React 18.
- [Potentially Breaking] Auto restore focus when the item is removed is now happening with a slight debounced delay.
- Custom
useEffectOncehook that introduced issues with unmounted components being remained as focusable.
- new
initconfig optionshouldFocusDOMNodethat focuses the underlying accessible DOM node too.
- new
initconfig optionuseGetBoundingClientRectthat affects the measurements of sizes and coordinates.
- Add
setThrottleto dynamically change throttle time.
- Remove event listeners for
unbindEventHandlersregardless of throttle value
- Update
parentFocusKeywhenremoveFocusable - Fix issue with
destroy(addedbind)
Reflect.deletePropertywas replaced bydeleteto be es5 compliant.
- Param
focusDetailsinfocusSelfandsetFocusmethods.
- Output bundle is now targeting ES5.
- Support for React v18 StrictMode. Added
useEffectOnceto avoid multiple effect runs on mount that was breaking the generation of thefocusKeys.
- Few TS errors that somehow not being checked when the app is built and published ¯_(ツ)_/¯.
- Function (
getCurrentFocusKey) for retrieving the currently focused component's focus key - Support for passing multiple key codes per direction in
setKeyMap
- Added generic P type for the props passed to
useFocusablehook that is available in all callbacks that bounce props back.
- Changed all
lodashimports to cherry-picked ones to avoid the wholelodashlib to be bundled in the project.
- Eslint dependencies required by
eslint-config-airbnb
- Fixed issue in Node environment - Webpack global object is now
thisinstead ofself
- Added focusable component callbacks to the effect that updates them in
SpatialNavigationservice. Otherwise only the first closure is assigned to the service and is always called with the initial props.
- Changed
measureLayoutback to calculate coords based onoffsetTop/Left/Width/Heightinstead ofgetClientBoundRect. The reason is thatgetClientBoundRectis less performant and calculates coordinates AFTER all the CSS transformations, which is undesirable for scaled or transformed elements.
- Updated Github path in
package.json
- Migrated the old HOC library to Hooks.