about summary refs log tree commit diff
path: root/app/javascript/mastodon/components/status_list.js
diff options
context:
space:
mode:
authorSorin Davidoi <sorin.davidoi@gmail.com>2017-07-28 13:33:40 +0200
committerEugen Rochko <eugen@zeonfederated.com>2017-07-28 13:33:40 +0200
commit534da4f24fd6740a7f613b0fa836b45f5935a99b (patch)
tree458b94bfb1d7b4c9aaa872ad0da7114a75e02c08 /app/javascript/mastodon/components/status_list.js
parent62a9da62a6998dcf5df8e1282cdf03960d92312f (diff)
Improve accessibility (part 5) (#4417)
* fix(status): Add tabIndex=0

* fix(status_list): Make keyboard navigable
Diffstat (limited to 'app/javascript/mastodon/components/status_list.js')
-rw-r--r--app/javascript/mastodon/components/status_list.js28
1 files changed, 27 insertions, 1 deletions
diff --git a/app/javascript/mastodon/components/status_list.js b/app/javascript/mastodon/components/status_list.js
index 9406b5fb9..d87fe3ea1 100644
--- a/app/javascript/mastodon/components/status_list.js
+++ b/app/javascript/mastodon/components/status_list.js
@@ -104,6 +104,32 @@ export default class StatusList extends ImmutablePureComponent {
     this.props.onScrollToBottom();
   }
 
+  handleKeyDown = (e) => {
+    if (['PageDown', 'PageUp', 'End', 'Home'].includes(e.key)) {
+      const article = (() => {
+        switch (e.key) {
+        case 'PageDown':
+          return e.nativeEvent.path[0].nodeName === 'ARTICLE' && e.nativeEvent.path[0].nextElementSibling;
+        case 'PageUp':
+          return e.nativeEvent.path[0].nodeName === 'ARTICLE' && e.nativeEvent.path[0].previousElementSibling;
+        case 'End':
+          return this.node.querySelector('[role="feed"] > article:last-of-type');
+        case 'Home':
+          return this.node.querySelector('[role="feed"] > article:first-of-type');
+        default:
+          return null;
+        }
+      })();
+
+
+      if (article) {
+        e.preventDefault();
+        article.focus();
+        article.scrollIntoView();
+      }
+    }
+  }
+
   render () {
     const { statusIds, scrollKey, trackScroll, shouldUpdateScroll, isLoading, hasMore, prepend, emptyMessage } = this.props;
 
@@ -113,7 +139,7 @@ export default class StatusList extends ImmutablePureComponent {
     if (isLoading || statusIds.size > 0 || !emptyMessage) {
       scrollableArea = (
         <div className='scrollable' ref={this.setRef}>
-          <div role='feed' className='status-list'>
+          <div role='feed' className='status-list' onKeyDown={this.handleKeyDown}>
             {prepend}
 
             {statusIds.map((statusId, index) => {