Blocks

FAQ block

The site's FAQ: the section head, a lead and a quiet button on the left, held under the header while the questions scroll by on the right; one answer open at a time, the rows sliding to make room and the plus turning to a minus. layout="stack" puts the head over a narrow list. The rows also stand alone as FaqAccordion.

Install

React apps get the React files; every other stack gets the web component.

npx spyglass-ds add faq-block
<script type="module" src="/spyglass-ds/elements/faq-block.js"></script>
Questions about the plan

Frequently asked questions

Everything Acme's team asked before starting.

Contact us

$10 for your first month, then $20/month.

Head over a narrow list

Questions, answered

$10 for your first month, then $20/month.

The rows alone

Usage

The questions section of a home, pricing, product or contact page (place it in a section with the page's padding); FaqAccordion alone where the page sets its own head.

Never

  • Answers the product does not state
  • More than one answer open at once
  • Colored question marks or icons

Adds with it: button

Props

The web component takes the same as attributes or properties (<spyglass-faq-block>); title is heading there.

<FaqBlock>

PropTypeDefault
itemsFaqItem[]
titleReactNode'Questions.'
bodyReactNode

A line under the title.

action{ label: string; href?: string }

A quiet button under the title: { label: 'Read the docs', href }.

idstring

Names the heading (`<id>-heading`).

'faq'
layout'split' | 'stack'

split (head left, questions right) or stack (head over a narrow list).

'split'
defaultOpennumber

The question open at first; -1 for none.

0
classNamestring

<FaqAccordion>

PropTypeDefault
itemsFaqAccordionItem[]
defaultOpennumber

The row open at first; -1 for none.

0
edge'top' | 'bottom'

The hairline above the list (top, the default) or under it (bottom, the pricing page's).

'top'
narrowboolean

Centered and no wider than the measure plus 80px (the pricing page's list).

false
classNamestring

Examples

The same example in React and as web components; both render identically.

react/examples/faq-block/Questions.tsx
import { FaqBlock } from '@/react/components/blocks/FaqBlock'
// Questions answered only with what the plan and the assets say.

const items = [
  {
    q: "What does the Creator plan cost?",
    a: "$10 for your first month, then $20/month."
  },
  {
    q: "How many people can use it?",
    a: "Unlimited team seats come with the plan."
  },
  {
    q: "Which networks are in the index?",
    a: "Meta, TikTok, Instagram, and YouTube creatives in one index."
  },
  {
    q: "How long does it take to add a brand?",
    a: "Add any brand or creator in under a minute."
  }
]

export default function Questions() {
  return <FaqBlock title="Frequently asked questions" body="Everything Acme's team asked before starting." action={{ label: 'Contact us', href: '#contact' }} items={items} />
}
elements/examples/faq-block/Questions.html
<!-- Questions answered only with what the plan and the assets say. -->
<spyglass-faq-block heading="Frequently asked questions" body="Everything Acme's team asked before starting." action='{"label":"Contact us","href":"#contact"}' items='[{"q":"What does the Creator plan cost?","a":"$10 for your first month, then $20/month."},{"q":"How many people can use it?","a":"Unlimited team seats come with the plan."},{"q":"Which networks are in the index?","a":"Meta, TikTok, Instagram, and YouTube creatives in one index."},{"q":"How long does it take to add a brand?","a":"Add any brand or creator in under a minute."}]'></spyglass-faq-block>
react/examples/faq-block/Stack.tsx
import { FaqBlock } from '@/react/components/blocks/FaqBlock'
import { faqExample } from '@/lib/faq'
// The earlier site's arrangement: the head centered over a narrow list.

export default function Stack() {
  return <FaqBlock id="faq-stack" layout="stack" title="Questions, answered" items={faqExample} />
}
elements/examples/faq-block/Stack.html
<!-- The earlier site's arrangement: the head centered over a narrow list. -->
<spyglass-faq-block head-id="faq-stack" layout="stack" heading="Questions, answered" items='[{"q":"What does the Creator plan cost?","a":"$10 for your first month, then $20/month."},{"q":"How many people can use it?","a":"Unlimited team seats come with the plan, so everyone who makes or reviews creative can search."},{"q":"Which networks are in the index?","a":"Meta, TikTok, Instagram, and YouTube creatives in one index."},{"q":"How long does it take to add a brand?","a":"Add any brand or creator in under a minute."}]'></spyglass-faq-block>
react/examples/faq-block/Rows.tsx
import { FaqAccordion } from '@/react/components/blocks/FaqAccordion'
import { faqExample } from '@/lib/faq'
// The rows alone, all closed at first.

export default function Rows() {
  return <FaqAccordion items={faqExample} defaultOpen={-1} className="w-full max-w-180" />
}
elements/examples/faq-block/Rows.html
<!-- The rows alone, all closed at first. -->
<spyglass-faq-accordion default-open="-1" class="w-full max-w-180" items='[{"q":"What does the Creator plan cost?","a":"$10 for your first month, then $20/month."},{"q":"How many people can use it?","a":"Unlimited team seats come with the plan, so everyone who makes or reviews creative can search."},{"q":"Which networks are in the index?","a":"Meta, TikTok, Instagram, and YouTube creatives in one index."},{"q":"How long does it take to add a brand?","a":"Add any brand or creator in under a minute."}]'></spyglass-faq-accordion>

Source

react/components/blocks/FaqBlock.tsx
import type { ReactNode } from 'react'
import { FaqAccordion, type FaqAccordionItem } from '@/react/components/blocks/FaqAccordion'
import { Button } from '@/react/components/ui/Button'
import { cn } from '@/react/lib/cn'

// The site's FAQ (v3/V3Faq): from 1024 the head on the left (4 of 11 columns, 64px apart, held 32px under the header
// while the questions scroll by) and the questions on the right; one column below, the head centered on phones. The
// head is the section head, a lead in the soft gray 24px under it and a quiet button 32px further. `layout="stack"` is
// the earlier site's (v2/V2Faq): the head centered over a narrow list with its hairline at the foot. The rows are
// FaqAccordion. Place it in a page section; it brings no padding of its own. Answer only with what the product states.
export type FaqItem = FaqAccordionItem

export interface FaqBlockProps {
  items: FaqItem[]
  title?: ReactNode
  /** A line under the title. */
  body?: ReactNode
  /** A quiet button under the title: { label: 'Read the docs', href }. */
  action?: { label: string; href?: string }
  /** Names the heading (`<id>-heading`). */
  id?: string
  /** split (head left, questions right) or stack (head over a narrow list). */
  layout?: 'split' | 'stack'
  /** The question open at first; -1 for none. */
  defaultOpen?: number
  className?: string
}

export function FaqBlock({ items, title = 'Questions.', body, action, id = 'faq', layout = 'split', defaultOpen = 0, className }: FaqBlockProps) {
  const stack = layout === 'stack'
  return (
    <section data-ds="faq-block" aria-labelledby={`${id}-heading`} className={cn('grid grid-cols-[minmax(0,1fr)] text-fg', stack ? 'gap-y-16 lg:gap-y-20' : 'gap-y-12 lg:grid-cols-[minmax(0,4fr)_minmax(0,7fr)] lg:items-start lg:gap-x-16', className)}>
      <header className={cn('flex flex-col', stack ? 'items-center text-center' : 'items-start max-md:items-center max-md:text-center lg:sticky lg:top-[calc(var(--ds-size-header)+var(--ds-space-2xl))]')}>
        <h2 id={`${id}-heading`} className="type-section max-lg:[text-box:trim-start_cap_alphabetic]">{title}</h2>
        {body ? <p className="mt-6 max-w-measure type-body-lg text-pretty text-fg-soft">{body}</p> : null}
        {action ? <Button href={action.href} variant="secondary" className="mt-8 max-md:w-full">{action.label}</Button> : null}
      </header>
      <div className="min-w-0">
        <FaqAccordion items={items} defaultOpen={defaultOpen} edge={stack ? 'bottom' : 'top'} narrow={stack} />
      </div>
    </section>
  )
}

export default FaqBlock
react/components/blocks/FaqAccordion.tsx
'use client'
import { useId, useLayoutEffect, useRef, useState, type KeyboardEvent } from 'react'
import { faqShift, faqSlotHeight, slideFaqRows, type FaqMove } from '@/lib/faq'
import { cn } from '@/react/lib/cn'

// The site's FAQ rows (ui/FaqAccordion, V3Faq.module.css, V2Faq.module.css): questions in DM Sans 20/28 in the soft
// gray (White when open or under the pointer) under #363636 hairlines, 20px above and below (24 from 768), a 12px plus
// that turns to a minus. One answer is open at a time (the first, unless `defaultOpen` says otherwise); it fades in
// over 320ms, 640px wide at most, and every open slot is as tall as the longest answer, so the rows between the one
// closing and the one opening slide by that height (transform only), and the page scrolls with them when the opened
// row would leave the view. Arrows, Home and End move between questions.
// Reduced motion: no slide or fade.
export interface FaqAccordionItem {
  q: string
  a: string
  /** An anchor for the row. */
  id?: string
}

export interface FaqAccordionProps {
  items: FaqAccordionItem[]
  /** The row open at first; -1 for none. */
  defaultOpen?: number
  /** The hairline above the list (top, the default) or under it (bottom, the pricing page's). */
  edge?: 'top' | 'bottom'
  /** Centered and no wider than the measure plus 80px (the pricing page's list). */
  narrow?: boolean
  className?: string
}

const ROW = 'relative border-t border-edge bg-surface first:border-t-0'

export function FaqAccordion({ items, defaultOpen = 0, edge = 'top', narrow = false, className }: FaqAccordionProps) {
  const closed = items.length
  const [open, setOpen] = useState(defaultOpen < 0 ? closed : defaultOpen)
  const listRef = useRef<HTMLDivElement>(null)
  const move = useRef<FaqMove | null>(null)
  const uid = useId()

  const select = (clicked: number) => {
    const next = clicked === open ? closed : clicked
    const distance = faqSlotHeight(listRef.current)
    move.current = { from: open, to: next, distance, shift: faqShift(listRef.current, open, next, distance, closed) }
    setOpen(next)
  }

  useLayoutEffect(() => {
    const pending = move.current
    move.current = null
    if (listRef.current && pending) slideFaqRows(listRef.current, pending)
  }, [open])

  const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
    const triggers = [...(listRef.current?.querySelectorAll<HTMLButtonElement>('[data-trigger]') ?? [])]
    const at = triggers.indexOf(document.activeElement as HTMLButtonElement)
    if (at < 0) return
    const target = ({ ArrowDown: (at + 1) % triggers.length, ArrowUp: (at - 1 + triggers.length) % triggers.length, Home: 0, End: triggers.length - 1 } as Record<string, number>)[e.key]
    if (target === undefined) return
    e.preventDefault()
    triggers[target].focus()
  }

  const sizers = (skip: number) => items.map((other, j) => (j === skip ? null : <span key={`${j}-${other.q}`} aria-hidden="true" data-text={other.a} className="invisible block type-body text-pretty text-fg-soft [grid-area:1/1] before:content-[attr(data-text)]" />))

  return (
    <div ref={listRef} data-ds="faq-accordion" onKeyDown={onKeyDown} className={cn('ds-faq min-w-0 overflow-y-clip border-edge [overflow-anchor:none]', edge === 'top' ? 'border-t' : 'border-b', narrow && 'mx-auto max-w-[calc(var(--ds-layout-measure)+var(--ds-space-5xl))]', className)}>
      <style href="ds-faq-accordion" precedence="ds">{css}</style>
      {items.map((item, i) => {
        const isOpen = i === open
        return (
          <div key={`${i}-${item.q}`} id={item.id} data-open={isOpen} className={ROW}>
            <h3 className="[font:inherit]">
              <button
                type="button"
                id={`${uid}-q-${i}`}
                data-trigger=""
                aria-expanded={isOpen}
                aria-controls={`${uid}-a-${i}`}
                onClick={() => select(i)}
                className="group/faq -mx-2 flex min-h-control-lg w-[calc(100%+2*var(--ds-space-sm))] cursor-pointer items-start justify-between gap-6 rounded-ds-sm px-2 py-5 text-left text-fg-soft transition-[color] duration-160 ease-out outline-offset-[calc(-1*var(--ds-border-focus))] hover:text-fg active:text-fg aria-expanded:text-fg md:py-6"
              >
                <span className="min-w-0 type-body-lg text-balance">{item.q}</span>
                <span aria-hidden="true" className="ds-faq-icon relative h-7 w-3 flex-none" />
              </button>
            </h3>
            <div data-slot="" className={isOpen ? 'h-auto' : 'h-0'}>
              <div className="grid grid-cols-[minmax(0,var(--ds-layout-measure))] bg-surface pb-6 md:pb-8">
                <div id={`${uid}-a-${i}`} role="region" aria-labelledby={`${uid}-q-${i}`} className="ds-faq-panel [grid-area:1/1]">
                  <p className="block type-body text-pretty text-fg-soft">{item.a}</p>
                </div>
                {sizers(i)}
              </div>
            </div>
          </div>
        )
      })}
      <div data-open={open === closed} aria-hidden="true" className={ROW}>
        <div data-slot="" className={open === closed ? 'h-auto' : 'h-0'}>
          <div className="grid grid-cols-[minmax(0,var(--ds-layout-measure))] bg-surface pb-6 md:pb-8">{sizers(-1)}</div>
        </div>
      </div>
    </div>
  )
}

export default FaqAccordion

const css = `
.ds-faq { --faq-dur: var(--ds-duration-glide); --faq-ease: var(--ds-easing-out); }
.ds-faq-icon { transition: transform var(--ds-duration-press) var(--ds-easing-out); }
.ds-faq-icon::before, .ds-faq-icon::after { content: ""; position: absolute; inset: 0; width: var(--ds-space-md); height: var(--ds-stroke); margin: auto; background: currentColor; }
.ds-faq-icon::after { transform: rotate(90deg); transition: transform var(--ds-duration-glide) var(--ds-easing-out); }
[aria-expanded="true"] > .ds-faq-icon::after { transform: rotate(0deg); }
[aria-expanded="false"]:active > .ds-faq-icon { transform: scale(0.75); }
.ds-faq-panel { visibility: hidden; opacity: 0; transition: opacity var(--ds-duration-glide) var(--ds-easing-out), visibility var(--ds-duration-instant) linear var(--ds-duration-glide); }
[data-open="true"] .ds-faq-panel { visibility: visible; opacity: 1; transition: opacity var(--ds-duration-glide) var(--ds-easing-out); }
@media (prefers-reduced-motion: reduce) {
  .ds-faq-panel, [data-open="true"] .ds-faq-panel, .ds-faq-icon::after { transition: none; }
}
`
lib/faq.ts
// The site's FAQ rows (ui/FaqAccordion): when one answer closes and another opens, every answer slot has the height of
// the longest answer, so the rows between the two move by that height. They are drawn where they were and slid to
// their new place by transform only (added to any slide still running), over --faq-dur on the site's ease-out; when the
// row opened would slide out of view above, the page scrolls with it so it stays in view. Both flavors call it after
// the open row changes. With reduced motion nothing slides (the page just keeps the row in view).
export interface FaqMove { from: number; to: number; distance: number; /** How far the page scrolls up so the opened row stays in view. */ shift?: number }

// What a slide still owes the page's scroll, per list, so a second press during a slide measures from where the rows
// will land.
const owed = new WeakMap<HTMLElement, number>()

/** Opening a row below the open one moves it up by the closing answer's height; when that would take it above the
 * view (the page's scroll padding), the page scrolls back with the rows so the question stays where it was read. */
export function faqShift(list: HTMLElement | null, open: number, next: number, distance: number, closed: number): number {
	if (!list || next <= open || next === closed) return 0
	let rest = list.getBoundingClientRect().top - distance + (owed.get(list) ?? 0) + (list.children[next] as HTMLElement).clientTop
	for (let i = 0; i < next; i++) rest += list.children[i].getBoundingClientRect().height
	const inset = parseFloat(getComputedStyle(document.documentElement).scrollPaddingTop) || 0
	return Math.max(0, Math.round(inset - rest))
}

export function slideFaqRows(list: HTMLElement, move: FaqMove) {
	const shift = move.shift ?? 0
	if (!move.distance) return
	if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
		if (shift) window.scrollBy({ top: -shift, behavior: 'instant' })
		return
	}
	const css = getComputedStyle(list)
	const raw = css.getPropertyValue('--faq-dur').trim()
	const duration = raw.endsWith('ms') ? parseFloat(raw) : parseFloat(raw) * 1000
	const easing = css.getPropertyValue('--faq-ease').trim() || 'ease-out'
	const down = move.to > move.from
	const offset = down ? move.distance : -move.distance
	let clock: Animation | undefined
	for (let i = Math.min(move.from, move.to) + 1; i <= Math.max(move.from, move.to); i++) {
		const a = list.children[i]?.animate([{ transform: `translateY(${offset}px)` }, { transform: 'translateY(0)' }], { duration: duration || 320, easing, composite: 'add' })
		clock ??= a
	}
	if (!clock || !shift) return
	// The scroll follows the slide frame by frame, so the opened question holds still on screen.
	const rows = clock
	let paid = 0
	owed.set(list, (owed.get(list) ?? 0) + shift)
	const tick = () => {
		const running = rows.playState === 'running' && list.isConnected
		const progress = running ? (rows.effect?.getComputedTiming().progress ?? 1) : 1
		const before = window.scrollY
		window.scrollBy({ top: paid - shift * (progress as number), behavior: 'instant' })
		const step = before - window.scrollY
		paid += step
		owed.set(list, (owed.get(list) ?? 0) - step)
		if (running) requestAnimationFrame(tick)
		else owed.set(list, (owed.get(list) ?? 0) - (shift - paid))
	}
	requestAnimationFrame(tick)
}

/** The height every open answer slot has (the open slot's), measured before the change. */
export function faqSlotHeight(list: HTMLElement | null): number {
	return list?.querySelector<HTMLElement>('[data-open="true"] [data-slot]')?.getBoundingClientRect().height ?? 0
}

export const faqExample = [
	{ q: 'What does the Creator plan cost?', a: '$10 for your first month, then $20/month.' },
	{ q: 'How many people can use it?', a: 'Unlimited team seats come with the plan, so everyone who makes or reviews creative can search.' },
	{ q: 'Which networks are in the index?', a: 'Meta, TikTok, Instagram, and YouTube creatives in one index.' },
	{ q: 'How long does it take to add a brand?', a: 'Add any brand or creator in under a minute.' },
]
react/lib/cn.ts
// Joins class names, skipping falsy ones: cn('a', on && 'b', ['c', undefined]). It does not merge conflicting
// utilities (no tailwind-merge), as Vue's class binding does not: the library's classes are written not to compete,
// and a className from the caller is appended after them, as Vue appends a fallthrough class.
export type ClassValue = string | false | null | undefined | 0 | ClassValue[]

export function cn(...values: ClassValue[]): string {
	const out: string[] = []
	for (const v of values) {
		if (!v) continue
		if (Array.isArray(v)) {
			const s = cn(...v)
			if (s) out.push(s)
		}
		else out.push(v)
	}
	return out.join(' ')
}
elements/components/blocks/faq-block.ts
import { html, nothing } from 'lit'
import { ifDefined } from 'lit/directives/if-defined.js'
import { DsElement, define, HostLayoutController } from '@/elements/lib/element'
import '@/elements/components/blocks/faq-accordion'
import '@/elements/components/ui/button'
import styles from 'virtual:tw'

// FaqBlock.tsx as <spyglass-faq-block>: the site's FAQ, the head (`heading`, React's `title`; `body`; `action` as a quiet
// button) on the left from 1024, held under the header while the questions (`items`, { q, a }) scroll by on the right;
// `layout="stack"` puts the head over a narrow list. `head-id` names the heading; `default-open` the first open row.
export interface FaqItem { q: string; a: string; id?: string }

/**
 * @summary Questions and answers, as the site sets them.
 */
export class FaqBlock extends DsElement {
	static styles = [DsElement.styles, styles]
	protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="faq-block"]'))
	static properties = { items: { type: Array }, heading: {}, body: {}, action: { type: Object }, headId: { attribute: 'head-id' }, arrangement: { attribute: 'layout' }, defaultOpen: { type: Number, attribute: 'default-open' } }
	items: FaqItem[] = []
	/** The heading (React's `title`). */
	heading = 'Questions.'
	/** A line under the heading. */
	body?: string
	/** A quiet button under the heading. */
	action?: { label: string; href?: string }
	/** Names the heading (React's `id`). */
	headId = 'faq'
	/** split (head left, questions right) or stack (head over a narrow list); the `layout` attribute (React's `layout`). */
	arrangement: 'split' | 'stack' = 'split'
	defaultOpen = 0

	render() {
		const stack = this.arrangement === 'stack'
		return html`<section data-ds="faq-block" aria-labelledby=${`${this.headId}-heading`} class=${`grid grid-cols-[minmax(0,1fr)] text-fg ${stack ? 'gap-y-16 lg:gap-y-20' : 'gap-y-12 lg:grid-cols-[minmax(0,4fr)_minmax(0,7fr)] lg:items-start lg:gap-x-16'}`}><header class=${`flex flex-col ${stack ? 'items-center text-center' : 'items-start max-md:items-center max-md:text-center lg:sticky lg:top-[calc(var(--ds-size-header)+var(--ds-space-2xl))]'}`}><h2 id=${`${this.headId}-heading`} class="type-section max-lg:[text-box:trim-start_cap_alphabetic]">${this.heading}</h2>${this.body ? html`<p class="mt-6 max-w-measure type-body-lg text-pretty text-fg-soft">${this.body}</p>` : nothing}${this.action ? html`<spyglass-button href=${ifDefined(this.action.href)} variant="secondary" class="mt-8 max-md:w-full">${this.action.label}</spyglass-button>` : nothing}</header><div class="min-w-0"><spyglass-faq-accordion .items=${this.items ?? []} .defaultOpen=${this.defaultOpen} edge=${stack ? 'bottom' : 'top'} ?narrow=${stack}></spyglass-faq-accordion></div></section>`
	}
}

define('faq-block', FaqBlock)
elements/components/blocks/faq-accordion.ts
import { html, nothing } from 'lit'
import { ifDefined } from 'lit/directives/if-defined.js'
import { DsElement, define, HostLayoutController, uid } from '@/elements/lib/element'
import { faqShift, faqSlotHeight, slideFaqRows, type FaqMove } from '@/lib/faq'
import styles from 'virtual:tw'

// FaqAccordion.tsx as <spyglass-faq-accordion>: the site's FAQ rows, one answer open at a time, every open slot as tall
// as the longest answer so the rows between slide by that height (transform only); the plus turns to a minus. Arrows,
// Home and End move between questions. `items` (JSON: { q, a, id? }), `default-open` (-1 for none), `edge` (top or
// bottom), `narrow`.
export interface FaqAccordionItem { q: string; a: string; id?: string }

const ROW = 'relative border-t border-edge bg-surface first:border-t-0'

/** @summary Questions that open one at a time, the rows sliding to make room. */
export class FaqAccordion extends DsElement {
	static styles = [DsElement.styles, styles]
	protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="faq-accordion"]'))
	static properties = { items: { type: Array }, defaultOpen: { type: Number, attribute: 'default-open' }, edge: {}, narrow: { type: Boolean }, open: { state: true } }
	items: FaqAccordionItem[] = []
	/** The row open at first; -1 for none. */
	defaultOpen = 0
	/** The hairline above the list (top) or under it (bottom). */
	edge: 'top' | 'bottom' = 'top'
	/** Centered and no wider than the measure plus 80px. */
	narrow = false
	private open?: number
	private move: FaqMove | null = null
	private rowId = uid('faq')

	private get list() { return this.renderRoot.querySelector<HTMLElement>('[data-ds="faq-accordion"]') }

	private select(clicked: number, current: number, closed: number) {
		const next = clicked === current ? closed : clicked
		const distance = faqSlotHeight(this.list)
		this.move = { from: current, to: next, distance, shift: faqShift(this.list, current, next, distance, closed) }
		this.open = next
	}

	protected updated(changed: Map<string, unknown>) {
		super.updated(changed as never)
		const pending = this.move
		this.move = null
		if (pending && this.list) slideFaqRows(this.list, pending)
	}

	private onKeyDown(e: KeyboardEvent) {
		const triggers = [...this.renderRoot.querySelectorAll<HTMLButtonElement>('[data-trigger]')]
		const at = triggers.indexOf((this.renderRoot as ShadowRoot).activeElement as HTMLButtonElement)
		if (at < 0) return
		const target = ({ ArrowDown: (at + 1) % triggers.length, ArrowUp: (at - 1 + triggers.length) % triggers.length, Home: 0, End: triggers.length - 1 } as Record<string, number>)[e.key]
		if (target === undefined) return
		e.preventDefault()
		triggers[target].focus()
	}

	render() {
		const items = this.items ?? []
		const closed = items.length
		const open = this.open ?? (this.defaultOpen < 0 ? closed : this.defaultOpen)
		const id = this.rowId
		const sizers = (skip: number) => items.map((other, j) => (j === skip ? nothing : html`<span aria-hidden="true" data-text=${other.a} class="invisible block type-body text-pretty text-fg-soft [grid-area:1/1] before:content-[attr(data-text)]"></span>`))
		return html`<div data-ds="faq-accordion" @keydown=${this.onKeyDown} class=${['ds-faq min-w-0 overflow-y-clip border-edge [overflow-anchor:none]', this.edge === 'bottom' ? 'border-b' : 'border-t', this.narrow ? 'mx-auto max-w-[calc(var(--ds-layout-measure)+var(--ds-space-5xl))]' : ''].filter(Boolean).join(' ')}>${items.map((item, i) => {
			const isOpen = i === open
			return html`<div id=${ifDefined(item.id)} data-open=${String(isOpen)} class=${ROW}><h3 class="[font:inherit]"><button type="button" id=${`${id}-q-${i}`} data-trigger aria-expanded=${String(isOpen)} aria-controls=${`${id}-a-${i}`} @click=${() => this.select(i, open, closed)} class="group/faq -mx-2 flex min-h-control-lg w-[calc(100%+2*var(--ds-space-sm))] cursor-pointer items-start justify-between gap-6 rounded-ds-sm px-2 py-5 text-left text-fg-soft transition-[color] duration-160 ease-out outline-offset-[calc(-1*var(--ds-border-focus))] hover:text-fg active:text-fg aria-expanded:text-fg md:py-6"><span class="min-w-0 type-body-lg text-balance">${item.q}</span><span aria-hidden="true" class="ds-faq-icon relative h-7 w-3 flex-none"></span></button></h3><div data-slot class=${isOpen ? 'h-auto' : 'h-0'}><div class="grid grid-cols-[minmax(0,var(--ds-layout-measure))] bg-surface pb-6 md:pb-8"><div id=${`${id}-a-${i}`} role="region" aria-labelledby=${`${id}-q-${i}`} class="ds-faq-panel [grid-area:1/1]"><p class="block type-body text-pretty text-fg-soft">${item.a}</p></div>${sizers(i)}</div></div></div>`
		})}<div data-open=${String(open === closed)} aria-hidden="true" class=${ROW}><div data-slot class=${open === closed ? 'h-auto' : 'h-0'}><div class="grid grid-cols-[minmax(0,var(--ds-layout-measure))] bg-surface pb-6 md:pb-8">${sizers(-1)}</div></div></div></div>`
	}
}

define('faq-accordion', FaqAccordion)
elements/components/blocks/faq-accordion.css
.ds-faq { --faq-dur: var(--ds-duration-glide); --faq-ease: var(--ds-easing-out); }
.ds-faq-icon { transition: transform var(--ds-duration-press) var(--ds-easing-out); }
.ds-faq-icon::before, .ds-faq-icon::after { content: ""; position: absolute; inset: 0; width: var(--ds-space-md); height: var(--ds-stroke); margin: auto; background: currentColor; }
.ds-faq-icon::after { transform: rotate(90deg); transition: transform var(--ds-duration-glide) var(--ds-easing-out); }
[aria-expanded="true"] > .ds-faq-icon::after { transform: rotate(0deg); }
[aria-expanded="false"]:active > .ds-faq-icon { transform: scale(0.75); }
.ds-faq-panel { visibility: hidden; opacity: 0; transition: opacity var(--ds-duration-glide) var(--ds-easing-out), visibility var(--ds-duration-instant) linear var(--ds-duration-glide); }
[data-open="true"] .ds-faq-panel { visibility: visible; opacity: 1; transition: opacity var(--ds-duration-glide) var(--ds-easing-out); }
@media (prefers-reduced-motion: reduce) {
  .ds-faq-panel, [data-open="true"] .ds-faq-panel, .ds-faq-icon::after { transition: none; }
}

Reference: Site v3/V3Faq, ui/FaqAccordion and v2/V2Faq V2FaqList (V3Faq.module.css, V2Faq.module.css): 4fr and 7fr columns 64px apart from 1024, the head sticky at the header plus 32px, centered on phones; .t-lead 24px under the head, the quiet docs button 32px further; rows under --line hairlines, 20px (24 from 768) above and below a 20/28 --text-2 question, a 12px plus of 2px strokes; the answer 16/24 --text-2 at 640px, 24px (32 from 768) under; slots sized to the longest answer, rows sliding over --dur-move on --ease-out; the v2 list centered at 640 + 80px with its hairline at the foot.