mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-23 05:11:53 +01:00
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.
This commit is contained in:
parent
cc3ff66246
commit
3919319863
1 changed files with 21 additions and 12 deletions
|
@ -50,13 +50,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(() => {
|
||||||
|
@ -64,11 +62,23 @@ 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;
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
if (element) {
|
|
||||||
if (align_top && container.scrollTop > element.offsetTop) {
|
if (align_top && container.scrollTop > element.offsetTop) {
|
||||||
element.scrollIntoView(true);
|
element.scrollIntoView(true);
|
||||||
} else if (!align_top && container.scrollTop + container.clientHeight < element.offsetTop + element.offsetHeight) {
|
} else if (!align_top && container.scrollTop + container.clientHeight < element.offsetTop + element.offsetHeight) {
|
||||||
|
@ -76,7 +86,6 @@ export default class StatusList extends ImmutablePureComponent {
|
||||||
}
|
}
|
||||||
element.focus();
|
element.focus();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
setRef = c => {
|
setRef = c => {
|
||||||
this.node = c;
|
this.node = c;
|
||||||
|
|
Loading…
Reference in a new issue