This commit is contained in:
YourAutisticLife 2024-05-10 20:06:53 +00:00 committed by GitHub
commit fb6cc00086
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 29 additions and 12 deletions

View File

@ -52,13 +52,11 @@ export default class StatusList extends ImmutablePureComponent {
}; };
handleMoveUp = (id, featured) => { handleMoveUp = (id, featured) => {
const elementIndex = this.getCurrentStatusIndex(id, featured) - 1; this._selectChild(id, featured, true);
this._selectChild(elementIndex, true);
}; };
handleMoveDown = (id, featured) => { handleMoveDown = (id, featured) => {
const elementIndex = this.getCurrentStatusIndex(id, featured) + 1; this._selectChild(id, featured, false);
this._selectChild(elementIndex, false);
}; };
handleLoadOlder = debounce(() => { handleLoadOlder = debounce(() => {
@ -66,18 +64,37 @@ export default class StatusList extends ImmutablePureComponent {
onLoadMore(lastId || (statusIds.size > 0 ? statusIds.last() : undefined)); onLoadMore(lastId || (statusIds.size > 0 ? statusIds.last() : undefined));
}, 300, { leading: true }); }, 300, { leading: true });
_selectChild (index, align_top) { _selectChild (id, featured, up) {
const align_top = up;
const container = this.node.node; 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) { let element = null;
if (align_top && container.scrollTop > element.offsetTop) { while (element === null) {
element.scrollIntoView(true); index += increment;
} else if (!align_top && container.scrollTop + container.clientHeight < element.offsetTop + element.offsetHeight) { const article = container.querySelector(`article:nth-of-type(${index + 1})`);
element.scrollIntoView(false); 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 => { setRef = c => {