mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2025-01-11 04:25:50 +00:00
Merge pull request #1158 from skspade/1117-jump-to-main-content
1117 jump to main content
This commit is contained in:
commit
62e105f826
4 changed files with 45 additions and 10 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit f45ddff206adb52ab0ac7555bf14978edac5d2f2
|
Subproject commit c9a07885f35cf334d3cf167cb57587a8177fc3fb
|
|
@ -414,3 +414,18 @@ br.big {
|
||||||
.emoji-picker {
|
.emoji-picker {
|
||||||
width: 100%;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Component } from "inferno";
|
import { Component, createRef, linkEvent, RefObject } from "inferno";
|
||||||
import { Provider } from "inferno-i18next-dess";
|
import { Provider } from "inferno-i18next-dess";
|
||||||
import { Route, Switch } from "inferno-router";
|
import { Route, Switch } from "inferno-router";
|
||||||
import { i18n } from "../../i18next";
|
import { i18n } from "../../i18next";
|
||||||
|
@ -15,8 +15,15 @@ import { Theme } from "./theme";
|
||||||
|
|
||||||
export class App extends Component<any, any> {
|
export class App extends Component<any, any> {
|
||||||
private isoData: IsoDataOptionalSite = setIsoData(this.context);
|
private isoData: IsoDataOptionalSite = setIsoData(this.context);
|
||||||
|
private readonly mainContentRef: RefObject<HTMLElement>;
|
||||||
constructor(props: any, context: any) {
|
constructor(props: any, context: any) {
|
||||||
super(props, context);
|
super(props, context);
|
||||||
|
this.mainContentRef = createRef();
|
||||||
|
}
|
||||||
|
|
||||||
|
handleJumpToContent(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
this.mainContentRef.current?.focus();
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
const siteRes = this.isoData.site_res;
|
const siteRes = this.isoData.site_res;
|
||||||
|
@ -26,6 +33,12 @@ export class App extends Component<any, any> {
|
||||||
<>
|
<>
|
||||||
<Provider i18next={i18n}>
|
<Provider i18next={i18n}>
|
||||||
<div id="app" className="lemmy-site">
|
<div id="app" className="lemmy-site">
|
||||||
|
<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 && (
|
{siteView && (
|
||||||
<Theme defaultTheme={siteView.local_site.default_theme} />
|
<Theme defaultTheme={siteView.local_site.default_theme} />
|
||||||
)}
|
)}
|
||||||
|
@ -39,6 +52,7 @@ export class App extends Component<any, any> {
|
||||||
exact
|
exact
|
||||||
component={routeProps => (
|
component={routeProps => (
|
||||||
<ErrorGuard>
|
<ErrorGuard>
|
||||||
|
<main tabIndex={-1} ref={this.mainContentRef}>
|
||||||
{RouteComponent &&
|
{RouteComponent &&
|
||||||
(isAuthPath(path ?? "") ? (
|
(isAuthPath(path ?? "") ? (
|
||||||
<AuthGuard>
|
<AuthGuard>
|
||||||
|
@ -47,6 +61,7 @@ export class App extends Component<any, any> {
|
||||||
) : (
|
) : (
|
||||||
<RouteComponent {...routeProps} />
|
<RouteComponent {...routeProps} />
|
||||||
))}
|
))}
|
||||||
|
</main>
|
||||||
</ErrorGuard>
|
</ErrorGuard>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -327,7 +327,12 @@ export function isVideo(url: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validURL(str: string) {
|
export function validURL(str: string) {
|
||||||
return !!new URL(str);
|
try {
|
||||||
|
new URL(str);
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validInstanceTLD(str: string) {
|
export function validInstanceTLD(str: string) {
|
||||||
|
|
Loading…
Reference in a new issue