]> Untitled Git - lemmy-ui.git/commitdiff
feat: Adds Jump to main content functionality
authorSean Spade <skspade@pm.me>
Sat, 10 Jun 2023 19:39:41 +0000 (15:39 -0400)
committerSean Spade <skspade@pm.me>
Fri, 16 Jun 2023 21:22:05 +0000 (17:22 -0400)
feat: Adds media query for prefers reduced motion

chore: remove <a/> from index.tsx

chore: remove tranisiton for skip link

chore: remove omitted error variable

update translations

chore: update translations

chore: Covert <a/> jump to content from html to Inferno JSX

chore: add translation

feat: add main as a parent to routes so jump to content always skips navigation on every page

chore: Use bootstrap classes

feat: Tidy Jump to content feature with some basic JS

feat: Jump to main content

lemmy-translations
src/assets/css/main.css
src/shared/components/app/app.tsx
src/shared/utils.ts

index f45ddff206adb52ab0ac7555bf14978edac5d2f2..c9a07885f35cf334d3cf167cb57587a8177fc3fb 160000 (submodule)
@@ -1 +1 @@
-Subproject commit f45ddff206adb52ab0ac7555bf14978edac5d2f2
+Subproject commit c9a07885f35cf334d3cf167cb57587a8177fc3fb
index 82f8433e89d063fd4c514dc9e5a09664fdbece4d..da5be8db1a77361d7caf5c6f96253f40480f99cc 100644 (file)
@@ -420,3 +420,18 @@ br.big {
 em-emoji-picker {
   width: 100%;
 }
+
+.skip-link {
+  top: -40px;
+  transition: top 0.3s ease;
+}
+
+@media (prefers-reduced-motion: reduce) {
+  .skip-link {
+    transition: none;
+  }
+}
+
+.skip-link:focus {
+  top: 0;
+}
index 96857f31339d6657fce4297a1770df1347a19bc2..d8d6f8bd5c0750bad6e15bbee6d22bb3c9e3a530 100644 (file)
@@ -1,4 +1,4 @@
-import { Component } from "inferno";
+import { Component, createRef, linkEvent, RefObject } from "inferno";
 import { Provider } from "inferno-i18next-dess";
 import { Route, Switch } from "inferno-router";
 import { i18n } from "../../i18next";
@@ -15,8 +15,15 @@ import { Theme } from "./theme";
 
 export class App extends Component<any, any> {
   private isoData: IsoDataOptionalSite = setIsoData(this.context);
+  private readonly mainContentRef: RefObject<HTMLElement>;
   constructor(props: any, context: any) {
     super(props, context);
+    this.mainContentRef = createRef();
+  }
+
+  handleJumpToContent(event) {
+    event.preventDefault();
+    this.mainContentRef.current?.focus();
   }
   render() {
     const siteRes = this.isoData.site_res;
@@ -26,6 +33,12 @@ export class App extends Component<any, any> {
       <>
         <Provider i18next={i18n}>
           <div id="app">
+            <a
+              className="skip-link bg-light text-dark p-2 text-decoration-none position-absolute start-0 z-3"
+              onClick={linkEvent(this, this.handleJumpToContent)}
+            >
+              ${i18n.t("jump_to_content", "Jump to content")}
+            </a>
             {siteView && (
               <Theme defaultTheme={siteView.local_site.default_theme} />
             )}
@@ -39,14 +52,16 @@ export class App extends Component<any, any> {
                     exact
                     component={routeProps => (
                       <ErrorGuard>
-                        {RouteComponent &&
-                          (isAuthPath(path ?? "") ? (
-                            <AuthGuard>
+                        <main tabIndex={-1} ref={this.mainContentRef}>
+                          {RouteComponent &&
+                            (isAuthPath(path ?? "") ? (
+                              <AuthGuard>
+                                <RouteComponent {...routeProps} />
+                              </AuthGuard>
+                            ) : (
                               <RouteComponent {...routeProps} />
-                            </AuthGuard>
-                          ) : (
-                            <RouteComponent {...routeProps} />
-                          ))}
+                            ))}
+                        </main>
                       </ErrorGuard>
                     )}
                   />
index c9d3e9190d9155190f19cacd00be39270fe22d21..4b8dd0ad2e06f170e81592d09abfdf0b4d39fd37 100644 (file)
@@ -330,7 +330,7 @@ export function validURL(str: string) {
   try {
     new URL(str);
     return true;
-  } catch (_) {
+  } catch {
     return false;
   }
 }