Add wraparound tidepool keyboard navigation
This commit is contained in:
parent
47ddc0417a
commit
c5b9d2ef20
12
src/tidepool.js
Normal file
12
src/tidepool.js
Normal file
@ -0,0 +1,12 @@
|
||||
export const zones = ['shore', 'rocks', 'pool'];
|
||||
|
||||
export function nextZone(currentIndex, direction) {
|
||||
const step = direction === 'previous' ? -1 : 1;
|
||||
return (currentIndex + step + zones.length) % zones.length;
|
||||
}
|
||||
|
||||
export function directionForKey(key) {
|
||||
if (key === 'ArrowLeft' || key === 'ArrowUp') return 'previous';
|
||||
if (key === 'ArrowRight' || key === 'ArrowDown') return 'next';
|
||||
return null;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user