Skip to content
This repository was archived by the owner on May 5, 2023. It is now read-only.

Commit 5313c78

Browse files
authored
Merge pull request #67 from NoriginMedia/throttle-fast-clicking
Allow throttle for key pressing
2 parents f74bad2 + 296cd18 commit 5313c78

5 files changed

Lines changed: 47 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ 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.12.3]
8+
### Changed
9+
- added `throttleKeypresses` to prevent canceling of throttled events for individual key presses
10+
711
## [2.12.2]
812
### Changed
913
- update layouts at the beginning of smartNavigate instead of after setFocus

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ Enable to throttle the function fired by the event listener.
206206

207207
* **0 (default)**
208208

209+
##### `throttleKeypresses`: boolean
210+
Prevent canceling of throttled events for individual key presses. Works only in combination with `throttle`. Useful when there are issues with the performance of handling rapidly firing navigational events.
211+
212+
* **false (default)**
213+
209214
### `setKeyMap`: function
210215
Function to set custom key codes.
211216
```jsx

package-lock.json

Lines changed: 31 additions & 12 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/react-spatial-navigation",
3-
"version": "2.12.2",
3+
"version": "2.12.3",
44
"description": "HOC-based Spatial Navigation (key navigation) solution for React",
55
"main": "dist/index.js",
66
"files": [

src/spatialNavigation.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ class SpatialNavigation {
291291
this.enabled = false;
292292
this.nativeMode = false;
293293
this.throttle = 0;
294+
this.throttleKeypresses = false;
294295

295296
this.pressedKeys = {};
296297

@@ -322,11 +323,13 @@ class SpatialNavigation {
322323
debug: debug = false,
323324
visualDebug: visualDebug = false,
324325
nativeMode: nativeMode = false,
325-
throttle: throttle = 0
326+
throttle: throttle = 0,
327+
throttleKeypresses: throttleKeypresses = false
326328
} = {}) {
327329
if (!this.enabled) {
328330
this.enabled = true;
329331
this.nativeMode = nativeMode;
332+
this.throttleKeypresses = throttleKeypresses;
330333

331334
this.debug = debug;
332335

@@ -366,6 +369,7 @@ class SpatialNavigation {
366369
this.enabled = false;
367370
this.nativeMode = false;
368371
this.throttle = 0;
372+
this.throttleKeypresses = false;
369373
this.focusKey = null;
370374
this.parentsHavingFocusedChild = [];
371375
this.focusableComponents = {};
@@ -434,7 +438,7 @@ class SpatialNavigation {
434438

435439
Reflect.deleteProperty(this.pressedKeys, eventType);
436440

437-
if (this.throttle) {
441+
if (this.throttle && !this.throttleKeypresses) {
438442
this.keyDownEventListener.cancel();
439443
}
440444
};

0 commit comments

Comments
 (0)