@clarusjs/ui-primitives 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/package.json +6 -6
  2. package/src/accordion-item.tscl +9 -3
  3. package/src/autocomplete.tscl +115 -0
  4. package/src/checkbox-group-key.ts +5 -0
  5. package/src/checkbox-group.tscl +96 -0
  6. package/src/checkbox-item.tscl +18 -0
  7. package/src/checkbox.tscl +15 -7
  8. package/src/chip-input.tscl +24 -15
  9. package/src/combobox.tscl +44 -35
  10. package/src/context-menu.tscl +100 -0
  11. package/src/date-field.tscl +140 -0
  12. package/src/date-segments.ts +55 -0
  13. package/src/dialog-close.tscl +7 -2
  14. package/src/dialog-trigger.tscl +7 -2
  15. package/src/dialog.tscl +10 -4
  16. package/src/{dismiss.js → dismiss.ts} +15 -18
  17. package/src/drag-drop.ts +116 -0
  18. package/src/field.tscl +42 -27
  19. package/src/fieldset.tscl +37 -0
  20. package/src/{focus-return.js → focus-return.ts} +2 -4
  21. package/src/form-errors.tscl +40 -0
  22. package/src/{index.js → index.ts} +8 -8
  23. package/src/menu-item.tscl +9 -3
  24. package/src/menu-list.tscl +1 -1
  25. package/src/menu.tscl +8 -5
  26. package/src/menubar.tscl +69 -0
  27. package/src/nav-menu-key.ts +5 -0
  28. package/src/nav-menu-panel.tscl +11 -0
  29. package/src/nav-menu-trigger.tscl +9 -0
  30. package/src/nav-menu.tscl +78 -0
  31. package/src/number-field.tscl +139 -0
  32. package/src/popover-trigger.tscl +7 -2
  33. package/src/popover.tscl +21 -14
  34. package/src/{position.js → position.ts} +21 -17
  35. package/src/preview-card-trigger.tscl +48 -0
  36. package/src/preview-card.tscl +27 -0
  37. package/src/radio-group.tscl +12 -7
  38. package/src/radio.tscl +13 -6
  39. package/src/{resize-column.js → resize-column.ts} +12 -16
  40. package/src/{roving-focus.js → roving-focus.ts} +19 -20
  41. package/src/select.tscl +27 -17
  42. package/src/sidebar-trigger.tscl +9 -6
  43. package/src/{sidebar.js → sidebar.ts} +5 -3
  44. package/src/sidebar.tscl +11 -4
  45. package/src/sortable-list.tscl +50 -0
  46. package/src/swipe.ts +79 -0
  47. package/src/switch.tscl +15 -7
  48. package/src/tab-panel.tscl +9 -4
  49. package/src/tab.tscl +11 -6
  50. package/src/tabs.tscl +12 -7
  51. package/src/time-field.tscl +139 -0
  52. package/src/toast-region.tscl +10 -4
  53. package/src/toast.ts +61 -0
  54. package/src/toggle-group.tscl +15 -9
  55. package/src/toggle-item.tscl +13 -7
  56. package/src/toggle.tscl +4 -1
  57. package/src/toolbar-separator.tscl +9 -0
  58. package/src/toolbar.tscl +30 -0
  59. package/src/tooltip-trigger.tscl +10 -6
  60. package/src/tooltip.tscl +11 -5
  61. package/src/{transition.js → transition.ts} +3 -6
  62. package/src/{typeahead.js → typeahead.ts} +20 -20
  63. package/src/virtual-grid.ts +100 -0
  64. package/src/virtual-keyboard.ts +36 -0
  65. package/src/virtual-list.ts +82 -0
  66. package/src/dismiss.d.ts +0 -27
  67. package/src/focus-return.d.ts +0 -10
  68. package/src/index.d.ts +0 -8
  69. package/src/position.d.ts +0 -36
  70. package/src/resize-column.d.ts +0 -18
  71. package/src/roving-focus.d.ts +0 -39
  72. package/src/sidebar.d.ts +0 -8
  73. package/src/toast.d.ts +0 -48
  74. package/src/toast.js +0 -56
  75. package/src/transition.d.ts +0 -18
  76. package/src/typeahead.d.ts +0 -35
@@ -0,0 +1,36 @@
1
+ // Virtual keyboard (#690): the on-screen keyboard on phones. Where the browser resizes the page for it (Chrome on
2
+ // Android with <meta name="viewport" content="…, interactive-widget=resizes-content">) fixed and 100dvh things
3
+ // already move up; Safari on iOS only shrinks the visual viewport, and the keyboard covers what's fixed at the bottom.
4
+ // This measures that, the same everywhere. Not in the package's index: import
5
+ // '@clarusjs/ui-primitives/virtual-keyboard.js'.
6
+
7
+ /**
8
+ * Follows the on-screen keyboard: <html> gets --ui-keyboard-inset (the px it covers at the bottom; 0 when it's closed)
9
+ * and data-keyboard while it's open, for styles to lift sheets, toasts and dialogs above it; a focused field it would
10
+ * cover is scrolled into view. Pinch zoom, which also shrinks the visual viewport, isn't taken for a keyboard. Call it
11
+ * once (a layout's island, or [use] on any element).
12
+ * @returns Stops it.
13
+ */
14
+ export function keyboardInset(): () => void {
15
+ const vv = window.visualViewport
16
+ if (!vv) return () => {}
17
+ const root = document.documentElement
18
+ const update = () => {
19
+ const inset = vv.scale > 1.01 ? 0 : Math.max(0, Math.round(window.innerHeight - vv.height - vv.offsetTop))
20
+ root.style.setProperty('--ui-keyboard-inset', `${inset}px`)
21
+ root.toggleAttribute('data-keyboard', inset > 0)
22
+ const field = document.activeElement as HTMLElement | null
23
+ if (!inset || !field?.matches('input, textarea, select, [contenteditable]')) return
24
+ const r = field.getBoundingClientRect()
25
+ if (r.bottom > vv.offsetTop + vv.height || r.top < vv.offsetTop) field.scrollIntoView({ block: 'center' })
26
+ }
27
+ update()
28
+ vv.addEventListener('resize', update)
29
+ vv.addEventListener('scroll', update)
30
+ return () => {
31
+ vv.removeEventListener('resize', update)
32
+ vv.removeEventListener('scroll', update)
33
+ root.style.removeProperty('--ui-keyboard-inset')
34
+ root.removeAttribute('data-keyboard')
35
+ }
36
+ }
@@ -0,0 +1,82 @@
1
+ // Virtual list (#687): a long list renders only the rows in view. This works out which rows those are; the app renders
2
+ // that slice with @for and pads the list by the space before and after it. Not in the package's index: import
3
+ // '@clarusjs/ui-primitives/virtual-list.js'.
4
+ import { effect } from 'clarusjs/runtime'
5
+
6
+ /** The rows to render: from start to end (exclusive), and the px before and after them. */
7
+ export type Range = { start: number; end: number; before: number; after: number }
8
+
9
+ /** The list's length, row size, and what virtualList() calls as the visible range changes. */
10
+ export interface VirtualListOptions {
11
+ /** How many rows (read in an effect: a signal read here updates the range). */
12
+ count: () => number
13
+ /** The rows to render, start to end (exclusive), and the px before and after. */
14
+ onRange: (range: Range) => void
15
+ /** A row's height until it's measured, in px. Default 40. */
16
+ size?: number
17
+ /** Rows rendered past each edge. Default 4. */
18
+ overscan?: number
19
+ }
20
+
21
+ /**
22
+ * `viewport` scrolls; inside it, rows carry data-index (their index in the whole list) and are measured as they render,
23
+ * so rows of different heights work. ↑ ↓ PageUp PageDown Home End move focus by row (rows need tabindex="-1"),
24
+ * scrolling the next one into view; a focused row scrolled out of the range hands focus to the viewport.
25
+ * @returns Stops it.
26
+ */
27
+ export function virtualList(viewport: HTMLElement, options: VirtualListOptions): () => void {
28
+ const { count, onRange, size = 40, overscan = 4 } = options
29
+ const sizes = new Map<number, number>()
30
+ const at = (i: number) => sizes.get(i) ?? size
31
+ // ponytail: sums rows from the top on each update (O(n)); a prefix-sum tree if lists reach hundreds of thousands
32
+ const sum = (a: number, b: number) => { let y = 0; for (let i = a; i < b; i++) y += at(i); return y }
33
+ let n = 0, key = '', focused = -1
34
+ const update = () => {
35
+ const top = viewport.scrollTop, bottom = top + viewport.clientHeight
36
+ let first = 0, y = 0
37
+ while (first < n && y + at(first) <= top) y += at(first++)
38
+ let last = first
39
+ while (last < n && y < bottom) y += at(last++)
40
+ const start = Math.max(0, first - overscan), end = Math.min(n, last + overscan)
41
+ const range = { start, end, before: sum(0, start), after: sum(end, n) }
42
+ const now = Object.values(range).join()
43
+ if (now === key) return
44
+ key = now
45
+ if (focused >= 0 && (focused < start || focused >= end) && viewport.contains(document.activeElement)) viewport.focus({ preventScroll: true })
46
+ onRange(range)
47
+ // The rows it renders, measured once they're in
48
+ requestAnimationFrame(() => { for (const row of viewport.querySelectorAll('[data-index]')) measure.observe(row) })
49
+ }
50
+ const measure = new ResizeObserver((entries) => {
51
+ for (const e of entries) { const row = e.target as HTMLElement; if (row.offsetHeight) sizes.set(Number(row.dataset.index), row.offsetHeight) }
52
+ update()
53
+ })
54
+ const stop = effect(() => { n = count(); update() })
55
+ const STEP = {
56
+ ArrowDown: (i) => i + 1, ArrowUp: (i) => i - 1, PageDown: (i, p) => i + p, PageUp: (i, p) => i - p, Home: () => 0, End: () => n - 1,
57
+ } as Record<string, (i: number, page: number) => number>
58
+
59
+ const key_ = (event: KeyboardEvent) => {
60
+ const step = STEP[event.key]
61
+ if (!step || !n) return
62
+ event.preventDefault()
63
+ const row = (event.target as Element).closest('[data-index]') as HTMLElement | null
64
+ const i = Math.max(0, Math.min(n - 1, step(row ? Number(row.dataset.index) : focused, Math.max(1, Math.floor(viewport.clientHeight / size)))))
65
+ const y = sum(0, i)
66
+ if (y < viewport.scrollTop) viewport.scrollTop = y
67
+ else if (y + at(i) > viewport.scrollTop + viewport.clientHeight) viewport.scrollTop = y + at(i) - viewport.clientHeight
68
+ focused = i
69
+ update()
70
+ requestAnimationFrame(() => (viewport.querySelector(`[data-index="${i}"]`) as HTMLElement | null)?.focus())
71
+ }
72
+ const focusin = (event: FocusEvent) => {
73
+ const row = (event.target as Element).closest('[data-index]') as HTMLElement | null
74
+ if (row) focused = Number(row.dataset.index)
75
+ }
76
+ const on: [string, (event: any) => void][] = [['scroll', update], ['keydown', key_], ['focusin', focusin]]
77
+ for (const [type, fn] of on) viewport.addEventListener(type, fn)
78
+ return () => {
79
+ stop(); measure.disconnect()
80
+ for (const [type, fn] of on) viewport.removeEventListener(type, fn)
81
+ }
82
+ }
package/src/dismiss.d.ts DELETED
@@ -1,27 +0,0 @@
1
- export type DismissOptions = {
2
- /**
3
- * Close it.
4
- */
5
- onDismiss: (reason: 'escape-key' | 'outside-press', event: Event) => void;
6
- /**
7
- * Elements whose presses aren't outside (its trigger).
8
- */
9
- exclude?: () => (Element | null | undefined)[];
10
- };
11
- /**
12
- * @typedef {object} DismissOptions
13
- * @property {(reason: 'escape-key' | 'outside-press', event: Event) => void} onDismiss Close it.
14
- * @property {() => (Element | null | undefined)[]} [exclude] Elements whose presses aren't outside (its trigger).
15
- */
16
- /**
17
- * Calls `onDismiss` when Escape is pressed while `el` is the topmost layer, or when a pointer goes down outside it
18
- * (and outside the layers opened after it, and `exclude()`). Before that, `el` gets a cancelable `cl:dismiss`
19
- * event (`detail.reason`); preventDefault() keeps it open.
20
- * @param {HTMLElement} el
21
- * @param {DismissOptions} options
22
- * @returns {() => void} Stops it (when the layer closes).
23
- * @example
24
- * @if (open) { <div [use]="(el) => dismiss(el, { onDismiss: () => (open = false) })">…</div> }
25
- * @see https://clarusjs.com/guide/ui-primitives#dismiss
26
- */
27
- export declare function dismiss(el: HTMLElement, options: DismissOptions): () => void;
@@ -1,10 +0,0 @@
1
- /**
2
- * Remember what has focus now; the returned function puts focus back there, if it's still on the page and focus is in
3
- * `el` or nowhere (a click elsewhere keeps its own focus).
4
- * @param {HTMLElement} el
5
- * @returns {() => void}
6
- * @example
7
- * @if (open) { <div [use]="focusReturn">…</div> }
8
- * @see https://clarusjs.com/guide/ui-primitives#focusreturn
9
- */
10
- export declare function focusReturn(el: HTMLElement): () => void;
package/src/index.d.ts DELETED
@@ -1,8 +0,0 @@
1
- export { rovingFocus } from './roving-focus.js';
2
- export { typeahead } from './typeahead.js';
3
- export { dismiss } from './dismiss.js';
4
- export { enter, exit } from './transition.js';
5
- export { focusReturn } from './focus-return.js';
6
- export { position } from './position.js';
7
- export { toast, dismissToast, toasts, subscribeToasts, clearToasts } from './toast.js';
8
- export { SIDEBAR_KEY, SIDEBAR_SCRIPT, toggleSidebar } from './sidebar.js';
package/src/position.d.ts DELETED
@@ -1,36 +0,0 @@
1
- export type PositionOptions = {
2
- /**
3
- * Which side of the anchor. Default 'bottom'.
4
- */
5
- side?: 'top' | 'bottom' | 'left' | 'right';
6
- /**
7
- * Along that side. Default 'center'.
8
- */
9
- align?: 'start' | 'center' | 'end';
10
- /**
11
- * Gap from the anchor, in px. Default 4.
12
- */
13
- offset?: number;
14
- /**
15
- * The other side when there's no room on this one. Default true.
16
- */
17
- flip?: boolean;
18
- };
19
- /**
20
- * @typedef {object} PositionOptions
21
- * @property {'top' | 'bottom' | 'left' | 'right'} [side] Which side of the anchor. Default 'bottom'.
22
- * @property {'start' | 'center' | 'end'} [align] Along that side. Default 'center'.
23
- * @property {number} [offset] Gap from the anchor, in px. Default 4.
24
- * @property {boolean} [flip] The other side when there's no room on this one. Default true.
25
- */
26
- /**
27
- * Position `floating` (fixed) by `anchor`, now and on scroll and resize.
28
- * @param {HTMLElement} floating
29
- * @param {Element} anchor
30
- * @param {PositionOptions} [options]
31
- * @returns {() => void} Stops following.
32
- * @example
33
- * @if (open) { <div [use]="(el) => position(el, trigger)">…</div> }
34
- * @see https://clarusjs.com/guide/ui-primitives#position
35
- */
36
- export declare function position(floating: HTMLElement, anchor: Element, options?: PositionOptions): () => void;
@@ -1,18 +0,0 @@
1
- /**
2
- * Make `handle` (inside a `<th>`) a vertical separator that resizes its column: drag it, or focus it and use the
3
- * arrow keys (by `step`), Home and End (to `min` and `max`). Right to left, the arrows and the drag follow the line.
4
- * @param {HTMLElement} handle
5
- * @param {{ min?: number, max?: number, step?: number, target?: HTMLElement, onResize?: (width: number) => void }} [options]
6
- * `target`: the element to size (the handle's `<th>` unless you say).
7
- * @returns {() => void}
8
- * @example
9
- * <th>Name <span [use]="(el) => resizeColumn(el, { onResize: (w) => save('name', w) })" aria-label="Resize Name"></span></th>
10
- * @see https://clarusjs.com/guide/ui-primitives#resizecolumn
11
- */
12
- export declare function resizeColumn(handle: HTMLElement, { min, max, step, target, onResize }?: {
13
- min?: number;
14
- max?: number;
15
- step?: number;
16
- target?: HTMLElement;
17
- onResize?: (width: number) => void;
18
- }): () => void;
@@ -1,39 +0,0 @@
1
- /** Items that can't take focus: disabled, or aria-disabled. */
2
- export declare const disabled: (/** @type {Element} */ el: Element) => boolean;
3
- export type RovingFocusOptions = {
4
- /**
5
- * Which descendants are the items (a selector). Default: tabs, menu items, options, buttons.
6
- */
7
- items?: string;
8
- /**
9
- * Which arrows move. Default 'horizontal'.
10
- */
11
- orientation?: 'horizontal' | 'vertical' | 'both';
12
- /**
13
- * From the last item on to the first, and back. Default true.
14
- */
15
- loop?: boolean;
16
- /**
17
- * Called with the item an arrow key moved to (after focusing it).
18
- */
19
- onMove?: (item: HTMLElement) => void;
20
- };
21
- /**
22
- * @typedef {object} RovingFocusOptions
23
- * @property {string} [items] Which descendants are the items (a selector). Default: tabs, menu items, options, buttons.
24
- * @property {'horizontal' | 'vertical' | 'both'} [orientation] Which arrows move. Default 'horizontal'.
25
- * @property {boolean} [loop] From the last item on to the first, and back. Default true.
26
- * @property {(item: HTMLElement) => void} [onMove] Called with the item an arrow key moved to (after focusing it).
27
- */
28
- /**
29
- * One Tab stop for the group `el`: its current item has tabindex 0, the others -1; arrow keys (by orientation, flipped
30
- * in right-to-left text), Home and End move focus between the enabled items. The current item is the one focused last,
31
- * else one marked aria-selected, aria-checked, aria-pressed, aria-current or data-highlighted, else the first enabled one.
32
- * @param {HTMLElement} el
33
- * @param {RovingFocusOptions} [options]
34
- * @returns {() => void} Stops it.
35
- * @example
36
- * <div role="toolbar" [use]="(el) => rovingFocus(el)">…</div>
37
- * @see https://clarusjs.com/guide/ui-primitives#rovingfocus
38
- */
39
- export declare function rovingFocus(el: HTMLElement, options?: RovingFocusOptions): () => void;
package/src/sidebar.d.ts DELETED
@@ -1,8 +0,0 @@
1
- export declare const SIDEBAR_KEY = "ui-sidebar";
2
- export declare const SIDEBAR_SCRIPT: string;
3
- /**
4
- * Collapse or reopen the sidebar on a wide screen, and remember it.
5
- * @param {HTMLElement | null} nav the sidebar (its data-state follows)
6
- * @returns {'open' | 'collapsed'} the new state
7
- */
8
- export declare function toggleSidebar(nav: HTMLElement | null): 'open' | 'collapsed';
package/src/toast.d.ts DELETED
@@ -1,48 +0,0 @@
1
- export type ToastAction = {
2
- /**
3
- * The button's text.
4
- */
5
- label: string;
6
- /**
7
- * Runs when it's pressed; the toast is dismissed after.
8
- */
9
- onClick: () => void;
10
- };
11
- export type Toast = {
12
- id: number;
13
- message: string;
14
- action?: ToastAction;
15
- /**
16
- * Milliseconds shown (paused while hovered or focused); Infinity: until dismissed.
17
- */
18
- duration: number;
19
- /**
20
- * Its kind: styled by data-type, with an icon and the kind in words.
21
- */
22
- type?: 'success' | 'error' | 'info' | 'warning';
23
- /**
24
- * false: no icon.
25
- */
26
- icon?: boolean;
27
- };
28
- /**
29
- * Show a message for `duration` ms (5000 by default; a toast with an action stays until dismissed, so there's time
30
- * to reach it), with at most one action. Polite: it never takes focus.
31
- * @param {string} message
32
- * @param {{ action?: ToastAction, duration?: number, type?: 'success' | 'error' | 'info' | 'warning', icon?: boolean }} [options]
33
- * @returns {number} its id, for dismissToast()
34
- */
35
- export declare function toast(message: string, options?: {
36
- action?: ToastAction;
37
- duration?: number;
38
- type?: 'success' | 'error' | 'info' | 'warning';
39
- icon?: boolean;
40
- }): number;
41
- /** @param {number} id */
42
- export declare function dismissToast(id: number): void;
43
- /** Every toast, oldest first. @returns {Toast[]} */
44
- export declare const toasts: () => Toast[];
45
- /** Calls `listener` now and on every change; returns how to stop. @param {() => void} listener */
46
- export declare function subscribeToasts(listener: () => void): () => void;
47
- /** Removes every toast (tests, or a page that resets). */
48
- export declare function clearToasts(): void;
package/src/toast.js DELETED
@@ -1,56 +0,0 @@
1
- // Toasts: short messages any island can send with toast('Saved'); <toast-region> (once, in the layout) shows them.
2
- // The list lives on globalThis, so every island's copy of this module shares it however the bundle is split.
3
-
4
- /**
5
- * @typedef {object} ToastAction
6
- * @property {string} label The button's text.
7
- * @property {() => void} onClick Runs when it's pressed; the toast is dismissed after.
8
- */
9
- /**
10
- * @typedef {object} Toast
11
- * @property {number} id
12
- * @property {string} message
13
- * @property {ToastAction} [action]
14
- * @property {number} duration Milliseconds shown (paused while hovered or focused); Infinity: until dismissed.
15
- * @property {'success' | 'error' | 'info' | 'warning'} [type] Its kind: styled by data-type, with an icon and the kind in words.
16
- * @property {boolean} [icon] false: no icon.
17
- */
18
- /** @type {{ items: Toast[], listeners: Set<() => void>, next: number }} */
19
- const store = /** @type {any} */ (globalThis).__clToasts ??= { items: [], listeners: new Set(), next: 1 }
20
- const notify = () => { for (const listener of store.listeners) listener() }
21
-
22
- /**
23
- * Show a message for `duration` ms (5000 by default; a toast with an action stays until dismissed, so there's time
24
- * to reach it), with at most one action. Polite: it never takes focus.
25
- * @param {string} message
26
- * @param {{ action?: ToastAction, duration?: number, type?: 'success' | 'error' | 'info' | 'warning', icon?: boolean }} [options]
27
- * @returns {number} its id, for dismissToast()
28
- */
29
- export function toast(message, options = {}) {
30
- const id = store.next++
31
- store.items = [...store.items, { id, message, action: options.action, type: options.type, icon: options.icon, duration: options.duration ?? (options.action ? Infinity : 5000) }]
32
- notify()
33
- return id
34
- }
35
-
36
- /** @param {number} id */
37
- export function dismissToast(id) {
38
- store.items = store.items.filter((t) => t.id !== id)
39
- notify()
40
- }
41
-
42
- /** Every toast, oldest first. @returns {Toast[]} */
43
- export const toasts = () => store.items
44
-
45
- /** Calls `listener` now and on every change; returns how to stop. @param {() => void} listener */
46
- export function subscribeToasts(listener) {
47
- store.listeners.add(listener)
48
- listener()
49
- return () => { store.listeners.delete(listener) }
50
- }
51
-
52
- /** Removes every toast (tests, or a page that resets). */
53
- export function clearToasts() {
54
- store.items = []
55
- notify()
56
- }
@@ -1,18 +0,0 @@
1
- /**
2
- * Mark `el` open, with data-starting-style for its first frame so CSS transitions run from there. An element rendered
3
- * open on the server doesn't need it (nothing to animate in).
4
- * @param {HTMLElement} el
5
- * @returns {Promise<void>} When the starting style is gone.
6
- * @example
7
- * @if (open) { <div class="popup" [use]="enter">…</div> }
8
- * @see https://clarusjs.com/guide/ui-primitives#enter-and-exit
9
- */
10
- export declare function enter(el: HTMLElement): Promise<void>;
11
- /**
12
- * Mark `el` closing: data-closed and data-ending-style, until its animations and transitions finish. Remove or hide
13
- * it after: `await exit(el)`.
14
- * @param {HTMLElement} el
15
- * @returns {Promise<void>}
16
- * @see https://clarusjs.com/guide/ui-primitives#enter-and-exit
17
- */
18
- export declare function exit(el: HTMLElement): Promise<void>;
@@ -1,35 +0,0 @@
1
- export type TypeaheadOptions = {
2
- /**
3
- * Which descendants are the items (a selector). Default: menu items and options.
4
- */
5
- items?: string;
6
- /**
7
- * What to do with the match. Default: focus it.
8
- */
9
- onMatch?: (item: HTMLElement) => void;
10
- /**
11
- * An item's text to match. Default: its textContent.
12
- */
13
- text?: (item: HTMLElement) => string;
14
- /**
15
- * How long a pause ends the search, in ms. Default 500.
16
- */
17
- timeout?: number;
18
- };
19
- /**
20
- * @typedef {object} TypeaheadOptions
21
- * @property {string} [items] Which descendants are the items (a selector). Default: menu items and options.
22
- * @property {(item: HTMLElement) => void} [onMatch] What to do with the match. Default: focus it.
23
- * @property {(item: HTMLElement) => string} [text] An item's text to match. Default: its textContent.
24
- * @property {number} [timeout] How long a pause ends the search, in ms. Default 500.
25
- */
26
- /**
27
- * Typing a character in `el` moves to the next item whose text starts with what was typed since the last pause.
28
- * @param {HTMLElement} el
29
- * @param {TypeaheadOptions} [options]
30
- * @returns {() => void} Stops it.
31
- * @example
32
- * <ul role="listbox" [use]="[(el) => rovingFocus(el, { orientation: 'vertical' }), (el) => typeahead(el)]">…</ul>
33
- * @see https://clarusjs.com/guide/ui-primitives#typeahead
34
- */
35
- export declare function typeahead(el: HTMLElement, options?: TypeaheadOptions): () => void;