Improvements for keyboard navigation in feeds (#35853)

This commit is contained in:
diondiondion authored and GitHub committed 2025-08-22 09:57:39 +00:00
1 parent 511e10df34
commit 118c30fbc7
17 files changed
+196 -331

No files matched your search

+30 -12
View File
@@ -77,6 +77,7 @@ import {
AccountFeatured,
} from './util/async-components';
import { ColumnsContextProvider } from './util/columns_context';
import { focusColumn, getFocusedItemIndex, focusItemSibling } from './util/focusUtils';
import { WrappedSwitch, WrappedRoute } from './util/react_router_helpers';
// Dummy import, to make sure that <Status /> ends up in the application bundle.
@@ -446,20 +447,34 @@ class UI extends PureComponent {
};
handleHotkeyFocusColumn = e => {
const index = (e.key * 1) + 1; // First child is drawer, skip that
const column = this.node.querySelector(`.column:nth-child(${index})`);
if (!column) return;
const container = column.querySelector('.scrollable');
focusColumn({index: e.key * 1});
};
if (container) {
const status = container.querySelector('.focusable');
handleHotkeyLoadMore = () => {
document.querySelector('.load-more')?.focus();
};
if (status) {
if (container.scrollTop > status.offsetTop) {
status.scrollIntoView(true);
}
status.focus();
}
handleMoveUp = () => {
const currentItemIndex = getFocusedItemIndex();
if (currentItemIndex === -1) {
focusColumn({
index: 1,
focusItem: 'first-visible',
});
} else {
focusItemSibling(currentItemIndex, -1);
}
};
handleMoveDown = () => {
const currentItemIndex = getFocusedItemIndex();
if (currentItemIndex === -1) {
focusColumn({
index: 1,
focusItem: 'first-visible',
});
} else {
focusItemSibling(currentItemIndex, 1);
}
};
@@ -542,6 +557,9 @@ class UI extends PureComponent {
forceNew: this.handleHotkeyForceNew,
toggleComposeSpoilers: this.handleHotkeyToggleComposeSpoilers,
focusColumn: this.handleHotkeyFocusColumn,
focusLoadMore: this.handleHotkeyLoadMore,
moveDown: this.handleMoveDown,
moveUp: this.handleMoveUp,
back: this.handleHotkeyBack,
goToHome: this.handleHotkeyGoToHome,
goToNotifications: this.handleHotkeyGoToNotifications,