Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/content/Components/CircularGallery/CircularGallery.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@
.circular-gallery:active {
cursor: grabbing;
}

.circular-gallery:focus-visible {
outline: 2px solid #fff;
outline-offset: 4px;
}
44 changes: 43 additions & 1 deletion src/content/Components/CircularGallery/CircularGallery.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,31 @@ class App {
this.scroll.target += (delta > 0 ? this.scrollSpeed : -this.scrollSpeed) * 0.2;
this.onCheckDebounce();
}
onKeyDown(e) {
switch (e.key) {
case 'ArrowRight':
e.preventDefault();
this.scroll.target += this.scrollSpeed * 5;
this.onCheckDebounce();
break;

case 'ArrowLeft':
e.preventDefault();
this.scroll.target -= this.scrollSpeed * 5;
this.onCheckDebounce();
break;

case 'Home':
e.preventDefault();
this.scroll.target = 0;
this.onCheckDebounce();
break;

default:
break;
}
}

onCheck() {
if (!this.medias || !this.medias[0]) return;
const width = this.medias[0].width;
Expand Down Expand Up @@ -528,6 +553,8 @@ class App {
this.boundOnTouchDown = this.onTouchDown.bind(this);
this.boundOnTouchMove = this.onTouchMove.bind(this);
this.boundOnTouchUp = this.onTouchUp.bind(this);
this.boundOnKeyDown = this.onKeyDown.bind(this);

window.addEventListener('resize', this.boundOnResize);
window.addEventListener('mousewheel', this.boundOnWheel);
window.addEventListener('wheel', this.boundOnWheel);
Expand All @@ -537,6 +564,8 @@ class App {
window.addEventListener('touchstart', this.boundOnTouchDown);
window.addEventListener('touchmove', this.boundOnTouchMove);
window.addEventListener('touchend', this.boundOnTouchUp);

this.container?.addEventListener('keydown', this.boundOnKeyDown);
}
destroy() {
window.cancelAnimationFrame(this.raf);
Expand All @@ -552,6 +581,10 @@ class App {
if (this.renderer && this.renderer.gl && this.renderer.gl.canvas.parentNode) {
this.renderer.gl.canvas.parentNode.removeChild(this.renderer.gl.canvas);
}

if (this.container) {
this.container.removeEventListener('keydown', this.boundOnKeyDown);
}
}
}

Expand Down Expand Up @@ -582,10 +615,19 @@ export default function CircularGallery({
scrollEase
});
});

return () => {
isMounted = false;
if (app) app.destroy();
};
}, [items, bend, textColor, borderRadius, font, fontUrl, scrollSpeed, scrollEase]);
return <div className="circular-gallery" ref={containerRef} />;
return (
<div
className="circular-gallery"
ref={containerRef}
tabIndex={0}
role="region"
aria-label="Circular image gallery. Use left and right arrow keys to navigate."
/>
);
}
33 changes: 32 additions & 1 deletion src/tailwind/Components/CircularGallery/CircularGallery.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,22 @@ class App {
this.scroll.target += (delta > 0 ? this.scrollSpeed : -this.scrollSpeed) * 0.2;
this.onCheckDebounce();
}
onKeyDown(e) {
switch (e.key) {
case 'ArrowRight':
e.preventDefault();
this.scroll.target += this.scrollSpeed * 5;
this.onCheckDebounce();
break;
case 'ArrowLeft':
e.preventDefault();
this.scroll.target -= this.scrollSpeed * 5;
this.onCheckDebounce();
break;
default:
break;
}
}
onCheck() {
if (!this.medias || !this.medias[0]) return;
const width = this.medias[0].width;
Expand Down Expand Up @@ -526,6 +542,7 @@ class App {
this.boundOnTouchDown = this.onTouchDown.bind(this);
this.boundOnTouchMove = this.onTouchMove.bind(this);
this.boundOnTouchUp = this.onTouchUp.bind(this);
this.boundOnKeyDown = this.onKeyDown.bind(this);
window.addEventListener('resize', this.boundOnResize);
window.addEventListener('mousewheel', this.boundOnWheel);
window.addEventListener('wheel', this.boundOnWheel);
Expand All @@ -535,6 +552,8 @@ class App {
window.addEventListener('touchstart', this.boundOnTouchDown);
window.addEventListener('touchmove', this.boundOnTouchMove);
window.addEventListener('touchend', this.boundOnTouchUp);

this.container?.addEventListener('keydown', this.boundOnKeyDown);
}
destroy() {
window.cancelAnimationFrame(this.raf);
Expand All @@ -550,6 +569,10 @@ class App {
if (this.renderer && this.renderer.gl && this.renderer.gl.canvas.parentNode) {
this.renderer.gl.canvas.parentNode.removeChild(this.renderer.gl.canvas);
}

if (this.container) {
this.container.removeEventListener('keydown', this.boundOnKeyDown);
}
}
}

Expand Down Expand Up @@ -585,5 +608,13 @@ export default function CircularGallery({
if (app) app.destroy();
};
}, [items, bend, textColor, borderRadius, font, fontUrl, scrollSpeed, scrollEase]);
return <div className="w-full h-full overflow-hidden cursor-grab active:cursor-grabbing" ref={containerRef} />;
return (
<div
className="w-full h-full overflow-hidden cursor-grab active:cursor-grabbing focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-4"
tabIndex={0}
role="region"
aria-label="Circular image gallery. Use Left and Right Arrow keys to navigate."
ref={containerRef}
/>
);
}
5 changes: 5 additions & 0 deletions src/ts-default/Components/CircularGallery/CircularGallery.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@
.circular-gallery:active {
cursor: grabbing;
}

.circular-gallery:focus-visible {
outline: 2px solid #fff;
outline-offset: 4px;
}
37 changes: 36 additions & 1 deletion src/ts-default/Components/CircularGallery/CircularGallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ class App {
boundOnTouchDown!: (e: MouseEvent | TouchEvent) => void;
boundOnTouchMove!: (e: MouseEvent | TouchEvent) => void;
boundOnTouchUp!: () => void;
boundOnKeyDown!: (e: KeyboardEvent) => void;

isDown: boolean = false;
start: number = 0;
Expand Down Expand Up @@ -669,6 +670,25 @@ class App {
this.onCheckDebounce();
}

onKeyDown(e: KeyboardEvent) {
switch (e.key) {
case 'ArrowRight':
e.preventDefault();
this.scroll.target += this.scrollSpeed * 5;
this.onCheckDebounce();
break;

case 'ArrowLeft':
e.preventDefault();
this.scroll.target -= this.scrollSpeed * 5;
this.onCheckDebounce();
break;

default:
break;
}
}

onCheck() {
if (!this.medias || !this.medias[0]) return;
const width = this.medias[0].width;
Expand Down Expand Up @@ -712,6 +732,8 @@ class App {
this.boundOnTouchDown = this.onTouchDown.bind(this);
this.boundOnTouchMove = this.onTouchMove.bind(this);
this.boundOnTouchUp = this.onTouchUp.bind(this);
this.boundOnKeyDown = this.onKeyDown.bind(this);

window.addEventListener('resize', this.boundOnResize);
window.addEventListener('mousewheel', this.boundOnWheel);
window.addEventListener('wheel', this.boundOnWheel);
Expand All @@ -721,6 +743,8 @@ class App {
window.addEventListener('touchstart', this.boundOnTouchDown);
window.addEventListener('touchmove', this.boundOnTouchMove);
window.addEventListener('touchend', this.boundOnTouchUp);

this.container?.addEventListener('keydown', this.boundOnKeyDown);
}

destroy() {
Expand All @@ -737,6 +761,9 @@ class App {
if (this.renderer && this.renderer.gl && this.renderer.gl.canvas.parentNode) {
this.renderer.gl.canvas.parentNode.removeChild(this.renderer.gl.canvas as HTMLCanvasElement);
}
if (this.container) {
this.container.removeEventListener('keydown', this.boundOnKeyDown);
}
}
}

Expand Down Expand Up @@ -783,5 +810,13 @@ export default function CircularGallery({
if (app) app.destroy();
};
}, [items, bend, textColor, borderRadius, font, fontUrl, scrollSpeed, scrollEase]);
return <div className="circular-gallery" ref={containerRef} />;
return (
<div
className="circular-gallery"
ref={containerRef}
tabIndex={0}
role="region"
aria-label="Circular image gallery. Use Left and Right Arrow keys to navigate."
/>
);
}
42 changes: 41 additions & 1 deletion src/ts-tailwind/Components/CircularGallery/CircularGallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ class App {
boundOnTouchDown!: (e: MouseEvent | TouchEvent) => void;
boundOnTouchMove!: (e: MouseEvent | TouchEvent) => void;
boundOnTouchUp!: () => void;
boundOnKeyDown!: (e: KeyboardEvent) => void;

isDown: boolean = false;
start: number = 0;
Expand Down Expand Up @@ -668,6 +669,22 @@ class App {
this.onCheckDebounce();
}

onKeyDown(e: KeyboardEvent) {
switch (e.key) {
case 'ArrowRight':
e.preventDefault();
this.scroll.target += this.scrollSpeed * 5;
this.onCheckDebounce();
break;

case 'ArrowLeft':
e.preventDefault();
this.scroll.target -= this.scrollSpeed * 5;
this.onCheckDebounce();
break;
}
}

onCheck() {
if (!this.medias || !this.medias[0]) return;
const width = this.medias[0].width;
Expand Down Expand Up @@ -711,6 +728,8 @@ class App {
this.boundOnTouchDown = this.onTouchDown.bind(this);
this.boundOnTouchMove = this.onTouchMove.bind(this);
this.boundOnTouchUp = this.onTouchUp.bind(this);
this.boundOnKeyDown = this.onKeyDown.bind(this);

window.addEventListener('resize', this.boundOnResize);
window.addEventListener('mousewheel', this.boundOnWheel);
window.addEventListener('wheel', this.boundOnWheel);
Expand All @@ -720,6 +739,12 @@ class App {
window.addEventListener('touchstart', this.boundOnTouchDown);
window.addEventListener('touchmove', this.boundOnTouchMove);
window.addEventListener('touchend', this.boundOnTouchUp);

this.container?.addEventListener(
'keydown',

this.boundOnKeyDown
);
}

destroy() {
Expand All @@ -736,6 +761,13 @@ class App {
if (this.renderer && this.renderer.gl && this.renderer.gl.canvas.parentNode) {
this.renderer.gl.canvas.parentNode.removeChild(this.renderer.gl.canvas as HTMLCanvasElement);
}
if (this.container) {
this.container.removeEventListener(
'keydown',

this.boundOnKeyDown
);
}
}
}

Expand Down Expand Up @@ -782,5 +814,13 @@ export default function CircularGallery({
if (app) app.destroy();
};
}, [items, bend, textColor, borderRadius, font, fontUrl, scrollSpeed, scrollEase]);
return <div className="w-full h-full overflow-hidden cursor-grab active:cursor-grabbing" ref={containerRef} />;
return (
<div
className="w-full h-full overflow-hidden cursor-grab active:cursor-grabbing"
ref={containerRef}
tabIndex={0}
role="region"
aria-label="Circular image gallery. Use Left and Right Arrow keys to navigate."
/>
);
}