Compare commits

...

3 Commits

Author SHA1 Message Date
YourAutisticLife
c5d5d838a5
Merge 60b19622c0 into 94bceb8683 2025-07-11 14:03:34 +00:00
Your Autistic Life
60b19622c0 fix: do not skip LoadGap elements 2024-01-15 04:49:17 -05:00
Your Autistic Life
3919319863 fix: skip empty articles
When using keyboard navigation, the current code will be stumped by HTML
article elements that are empty. We now skip over them.
2024-01-15 04:49:17 -05:00

View File

@ -53,13 +53,11 @@ export default class StatusList extends ImmutablePureComponent {
};
handleMoveUp = (id, featured) => {
const elementIndex = this.getCurrentStatusIndex(id, featured) - 1;
this._selectChild(elementIndex, true);
this._selectChild(id, featured, true);
};
handleMoveDown = (id, featured) => {
const elementIndex = this.getCurrentStatusIndex(id, featured) + 1;
this._selectChild(elementIndex, false);
this._selectChild(id, featured, false);
};
handleLoadOlder = debounce(() => {
@ -67,18 +65,37 @@ export default class StatusList extends ImmutablePureComponent {
onLoadMore(lastId || (statusIds.size > 0 ? statusIds.last() : undefined));
}, 300, { leading: true });
_selectChild (index, align_top) {
_selectChild (id, featured, up) {
const align_top = up;
const container = this.node.node;
const element = container.querySelector(`article:nth-of-type(${index + 1}) .focusable`);
const elementIndex = this.getCurrentStatusIndex(id, featured);
const increment = up ? -1 : 1
let index = elementIndex;
if (element) {
if (align_top && container.scrollTop > element.offsetTop) {
element.scrollIntoView(true);
} else if (!align_top && container.scrollTop + container.clientHeight < element.offsetTop + element.offsetHeight) {
element.scrollIntoView(false);
let element = null;
while (element === null) {
index += increment;
const article = container.querySelector(`article:nth-of-type(${index + 1})`);
if (article === null) {
return;
}
element = article.querySelector(".focusable");
// This happens when the article contains a LoadGap element. We just want
// to stop the navigation there so that the user does not erroneously skip
// over it.
if (element === null &&
article.querySelector(".load-more.load-gap") !== null) {
return;
}
element.focus();
}
if (align_top && container.scrollTop > element.offsetTop) {
element.scrollIntoView(true);
} else if (!align_top && container.scrollTop + container.clientHeight < element.offsetTop + element.offsetHeight) {
element.scrollIntoView(false);
}
element.focus();
}
setRef = c => {