Fix hotkey navigation?

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2022-05-17 15:09:53 +02:00
parent 1a1df69d0b
commit 721772b08f
6 changed files with 54 additions and 44 deletions

View File

@@ -42,6 +42,7 @@ interface IScrollableList extends VirtuosoProps<any, any> {
onRefresh?: () => Promise<any>,
className?: string,
itemClassName?: string,
id?: string,
}
/** Legacy ScrollableList with Virtuoso for backwards-compatibility */
@@ -58,6 +59,7 @@ const ScrollableList = React.forwardRef<VirtuosoHandle, IScrollableList>(({
onLoadMore,
className,
itemClassName,
id,
hasMore,
placeholderComponent: Placeholder,
placeholderCount = 0,
@@ -130,6 +132,7 @@ const ScrollableList = React.forwardRef<VirtuosoHandle, IScrollableList>(({
<Virtuoso
ref={ref}
useWindowScroll
id={id}
className={className}
data={data}
startReached={onScrollToTop}

View File

@@ -282,13 +282,11 @@ class Status extends ImmutablePureComponent<IStatus, IStatusState> {
}
handleHotkeyMoveUp = (e?: KeyboardEvent): void => {
// FIXME: what's going on here?
// this.props.onMoveUp(this.props.status.id, e?.target?.getAttribute('data-featured'));
this.props.onMoveUp(this.props.status.id, this.props.featured);
}
handleHotkeyMoveDown = (e?: KeyboardEvent): void => {
// FIXME: what's going on here?
// this.props.onMoveDown(this.props.status.id, e?.target?.getAttribute('data-featured'));
this.props.onMoveDown(this.props.status.id, this.props.featured);
}
handleHotkeyToggleHidden = (): void => {
@@ -601,7 +599,7 @@ class Status extends ImmutablePureComponent<IStatus, IStatusState> {
return (
<HotKeys handlers={handlers} data-testid='status'>
<div
className='status cursor-pointer'
className={classNames('status cursor-pointer', { focusable: this.props.focusable })}
tabIndex={this.props.focusable && !this.props.muted ? 0 : undefined}
data-featured={featured ? 'true' : null}
aria-label={textForScreenReader(intl, status, rebloggedByText)}

View File

@@ -77,18 +77,18 @@ export default class StatusList extends ImmutablePureComponent {
this.props.onLoadMore(loadMoreID);
}, 300, { leading: true })
_selectChild(index, align_top) {
const container = this.node.node;
const element = container.querySelector(`article:nth-of-type(${index + 1}) .focusable`);
_selectChild(index) {
this.node.scrollIntoView({
index,
behavior: 'smooth',
done: () => {
const element = document.querySelector(`#status-list [data-index="${index}"] .focusable`);
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);
}
element.focus();
}
if (element) {
element.focus();
}
},
});
}
handleDequeueTimeline = () => {
@@ -216,6 +216,7 @@ export default class StatusList extends ImmutablePureComponent {
message={messages.queue}
/>,
<ScrollableList
id='status-list'
key='scrollable-list'
isLoading={isLoading}
showLoading={isLoading && statusIds.size === 0}