From: Sean Spade Date: Sat, 10 Jun 2023 19:39:41 +0000 (-0400) Subject: feat: Adds Jump to main content functionality X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%22https:/nerdica.net/%7Bthis.props.imageSrc%7D?a=commitdiff_plain;h=d3e181222a4dfb4c2be80eda979bb95339a83f2a;p=lemmy-ui.git feat: Adds Jump to main content functionality feat: Adds media query for prefers reduced motion chore: remove from index.tsx chore: remove tranisiton for skip link chore: remove omitted error variable update translations chore: update translations chore: Covert 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 --- diff --git a/lemmy-translations b/lemmy-translations index f45ddff..c9a0788 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit f45ddff206adb52ab0ac7555bf14978edac5d2f2 +Subproject commit c9a07885f35cf334d3cf167cb57587a8177fc3fb diff --git a/src/assets/css/main.css b/src/assets/css/main.css index 82f8433..da5be8d 100644 --- a/src/assets/css/main.css +++ b/src/assets/css/main.css @@ -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; +} diff --git a/src/shared/components/app/app.tsx b/src/shared/components/app/app.tsx index 96857f3..d8d6f8b 100644 --- a/src/shared/components/app/app.tsx +++ b/src/shared/components/app/app.tsx @@ -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 { private isoData: IsoDataOptionalSite = setIsoData(this.context); + private readonly mainContentRef: RefObject; 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 { <>
+ + ${i18n.t("jump_to_content", "Jump to content")} + {siteView && ( )} @@ -39,14 +52,16 @@ export class App extends Component { exact component={routeProps => ( - {RouteComponent && - (isAuthPath(path ?? "") ? ( - +
+ {RouteComponent && + (isAuthPath(path ?? "") ? ( + + + + ) : ( - - ) : ( - - ))} + ))} +
)} /> diff --git a/src/shared/utils.ts b/src/shared/utils.ts index c9d3e91..4b8dd0a 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -330,7 +330,7 @@ export function validURL(str: string) { try { new URL(str); return true; - } catch (_) { + } catch { return false; } }