Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NickAkhmetov/CAT-435 disable scrolling full page when using arrow keys to explore Vitessce visualizations #3561

Merged
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG-cat-435.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Avoid page scrolling from using arrow keys on vitessce visualization.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export function useVitessceEventMetadata() {
return formatEventCategoryAndLabel('Unknown', location);
}

const arrowKeys = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'];

export function useVisualizationTracker() {
const { category, label } = useVitessceEventMetadata();
// Track when the visualization is first mounted
Expand Down Expand Up @@ -66,6 +68,11 @@ export function useVisualizationTracker() {
const trackKeyDown: React.KeyboardEventHandler<HTMLSpanElement> = useEventCallback((e) => {
const target = getNearestIdentifier(e.target as HTMLElement);
const key = e.key === ' ' ? 'Space' : e.key;
// Prevent default scrolling behavior of arrow keys
if (arrowKeys.includes(key)) {
trackVitessceAction(`${key} ${target}`);
e.preventDefault();
}
if (!target || modifierKeys.includes(key)) return;
if (typingTimeout.current) {
clearTimeout(typingTimeout.current);
Expand Down
Loading