From fe8cf85e2a4abb576ed65d87789789bae5aba911 Mon Sep 17 00:00:00 2001 From: Katja Lutz Date: Mon, 27 Jun 2022 11:20:23 +0200 Subject: [PATCH] feat: implement onClickFocus helper --- src/util.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/util.tsx b/src/util.tsx index 3c6e8b8..979064c 100644 --- a/src/util.tsx +++ b/src/util.tsx @@ -1,5 +1,6 @@ import Big from "big.js"; import { fromUnixTime, intlFormat } from "date-fns"; +import { JSX } from "solid-js"; export const sleep = (timeout: number) => new Promise((res) => setTimeout(res, timeout)); @@ -65,3 +66,20 @@ export const shuffle = (list: any[]) => { }; export const getHost = () => "https://rappli.ch"; + +export const onClickFocus: JSX.EventHandlerUnion< + HTMLAnchorElement, + MouseEvent +> = (evt) => { + const el = evt.currentTarget!; + const id = el.getAttribute("href"); + if (id == null) { + return; + } + const targetEl = document.querySelector(id); + if (targetEl == null) { + return; + } + + targetEl.focus(); +};