clickworks
Works / Search

Telescope Search

Closed, it's a short pearl field that steps down through satin rings into a round eyepiece. Click it, or press / or ⌘K, and the long tube slides out first, then the collar rings knock into place one after the other with a quiet click. Type, and the results slide down from under the tube.

Free6 files0 dependencies8.9 kB gzippedRenders on the serverKeyboard and screen reader

Install

npx shadcn@latest add https://clickworks.dev/r/telescope-search.json

The files land in components/clickworks/telescope-search/. No other packages are added.

Usage

import { TelescopeSearch } from "@/components/clickworks/telescope-search/react/TelescopeSearch"

export function HeaderSearch() {
  return (
    <TelescopeSearch
      items={[
        { label: "Pricing", href: "/pricing", description: "Three fixed packages", keywords: "cost rates" },
        { label: "About", href: "/about", description: "Who builds your site" },
        { label: "Contact", href: "/contact", description: "Reply within a day" },
      ]}
    />
  )
}

Props

items
{ label, href?, description?, keywords?, target? }[]

The pages people can find. Keywords are matched but never shown.

label
string

Text on the closed field.

Default "Search"

placeholder
string

Placeholder once it's open.

Default "Search pages"

theme
"light" | "dark" | "auto"

A light or a graphite telescope. Auto follows the page, then the device. Your --ts-* properties still win.

hint
string

Key hint on the closed field. An empty string hides it.

Default "/"

shortcut
boolean

/ and ⌘K (Ctrl+K) open it.

Default true

side
"left" | "right"

Which way it pulls out. Left suits a field on the right of the nav.

Default "left"

length
number

Open length in px. Shortens itself on narrow screens.

Default 420

maxResults
number

Most results shown at once.

Default 5

countText
string

The count on the field: one, many and none.

Default "{n} page|{n} pages|none"

emptyText
string

Shown when nothing matches.

Default "No page matches “{q}”"

sound
boolean

A short click when a tube hits its stop.

Default true

haptics
boolean

A tiny vibration on phones when a tube hits its stop.

Default true

open
boolean

Controlled open state.

Events

onSelect
(detail: { index, label, href, description }, event) => void | boolean

A page was picked. Return false to stop navigation, for client-side routing.

onOpenChange
(open: boolean) => void

The search opened or closed.

onSearch
(detail: { query, results }) => void

The query changed.

Styling

Set these custom properties on the component or any parent. Every shade and shadow is mixed from them, so any palette still looks lit.

--ts-tube#FFFFFF
--ts-ring#DFE1E6
--ts-text#141415
--ts-muted#8E8E95
--ts-shade#3C3C50
--ts-shadow16 18 40
--ts-glossrgb(255 255 255 / .9)
--ts-hovera faint shade of --ts-shadow
--ts-fontinherit

Behaviour and accessibility

  • Matching ignores case and accents, and ranks titles that start with the query first.
  • The field is a combobox: arrows move the pick, Enter opens it, Escape closes it and returns focus.
  • The result count is announced to screen readers as you type.
  • With reduced motion it opens and closes without moving.

Files

react/TelescopeSearch.tsxReact component
element/index.tsCustom element
element/telescope-search-element.tsCustom element
core/engine.tsEngine
core/search.tsEngine
core/styles.tsEngine