From 435db83027685e8970aca0db06332a1a588271e3 Mon Sep 17 00:00:00 2001 From: Rostislav Harlanov Date: Sat, 14 Feb 2026 11:04:55 +0100 Subject: [PATCH 1/2] docs: hash observer --- docs/src/routes/get-started/index.tsx | 124 +++++++++++++++++++++----- 1 file changed, 101 insertions(+), 23 deletions(-) diff --git a/docs/src/routes/get-started/index.tsx b/docs/src/routes/get-started/index.tsx index 745da70..d381c7a 100644 --- a/docs/src/routes/get-started/index.tsx +++ b/docs/src/routes/get-started/index.tsx @@ -1,4 +1,5 @@ import { Title } from "@solidjs/meta"; +import { createSignal, onCleanup, onMount } from "solid-js"; import { Link } from "solid-uix"; import { Code } from "~/components/code/code"; import { Container } from "~/components/container/container"; @@ -6,36 +7,113 @@ import { Footer } from "~/components/footer/footer"; import { Navigation } from "~/components/navigation/navigation"; const GetStarted = () => { + let isUserNavigation = false; + let timerId: number | undefined; + const [hash, setHash] = createSignal(""); + + const onNavigation = (event: MouseEvent) => { + const target = event.target as HTMLAnchorElement; + const href = target.href; + const hash = new URL(href).hash; + + isUserNavigation = true; + setHash(hash); + clearTimeout(timerId); + + timerId = setTimeout(() => { + isUserNavigation = false; + }, 1000); + }; + + onMount(() => { + const sections = document.querySelectorAll("section[id]"); + const options: IntersectionObserverInit = { + threshold: 0.5 + }; + + const observer = new IntersectionObserver((entries) => { + if (isUserNavigation) { + return; + } + + const visibleEntries = entries.filter((entry) => entry.isIntersecting); + + if (visibleEntries.length > 0) { + const visibleEntry = visibleEntries[0]; + const href = visibleEntry.target.getAttribute("id") as string; + + setHash(`#${href}`); + console.log("setHash", href); + history.replaceState(null, "", `get-started#${href}`); + } + }, options); + + sections.forEach((section) => { + observer.observe(section); + }); + + onCleanup(() => { + observer.disconnect(); + clearTimeout(timerId); + }); + }); + return (
Get started - + Install - + Register fields - + Apply validation - + Controlled Inputs - + Handle errors - + TypeScript + + {/* {getHash()} */}

Get started

-
+

Install @@ -43,9 +121,9 @@ const GetStarted = () => {

Install Solid Hook Form package.

npm install solid-hook-form -
+ -
+

Example @@ -74,11 +152,11 @@ export const ExampleForm = () => { ) }`} -

+ -
+

- + Register fields

@@ -116,11 +194,11 @@ export const ExampleForm = () => { ) }`} -
+ -
+

- + Apply validation

@@ -173,9 +251,9 @@ export const ExampleForm = () => { ) }`} -
+ -
+

Controlled Inputs @@ -274,11 +352,11 @@ export const ExampleForm = () => { ) }`} -

+ -
+

- + Handle errors

@@ -320,9 +398,9 @@ export const ExampleForm = () => { ) }`} -
+ -
+

TypeScript @@ -360,7 +438,7 @@ export const ExampleForm = () => { ) }`} -

+