@opencode/ui 0.0.0-dev-44 → 0.0.0-dev-51
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.
- package/dist/forms/search-list/search-list.d.ts +26 -0
- package/package.json +2 -2
- package/src/components/rolling-number.css +4 -0
- package/src/components/rolling-number.tsx +20 -7
- package/src/forms/search-list/search-list.css +55 -2
- package/src/forms/search-list/search-list.tsx +145 -73
- package/src/forms/typeahead/controller.ts +3 -1
|
@@ -11,6 +11,18 @@ export type SearchListRow = {
|
|
|
11
11
|
onMouseDown: (event: MouseEvent) => void;
|
|
12
12
|
onClick: () => void;
|
|
13
13
|
};
|
|
14
|
+
/** Attributes for the input of a field passed as `field`: spread them onto it. */
|
|
15
|
+
export type SearchListField = {
|
|
16
|
+
role: "combobox";
|
|
17
|
+
"aria-expanded": boolean;
|
|
18
|
+
"aria-autocomplete": "list";
|
|
19
|
+
"aria-controls": string | undefined;
|
|
20
|
+
"aria-activedescendant": string | undefined;
|
|
21
|
+
onInput: (event: InputEvent & {
|
|
22
|
+
currentTarget: HTMLInputElement;
|
|
23
|
+
}) => void;
|
|
24
|
+
onKeyDown: (event: KeyboardEvent) => void;
|
|
25
|
+
};
|
|
14
26
|
export type SearchListHandle<T> = {
|
|
15
27
|
active: () => T | undefined;
|
|
16
28
|
setActive: (key: string | undefined) => void;
|
|
@@ -19,13 +31,22 @@ export type SearchListHandle<T> = {
|
|
|
19
31
|
* A search field over sectioned results. Rows that share a `section` key list together under one header, which sticks
|
|
20
32
|
* while its rows scroll beneath it until the next header pushes it away. The first row is active until the user picks
|
|
21
33
|
* another: ↑/↓ wrap, ⌘ or ⌥ with ↑/↓ jump between sections, Home/End go to the ends, Enter selects and Escape closes.
|
|
34
|
+
* A page can keep its own field through `field` and float the results beneath it with `popover`.
|
|
22
35
|
*/
|
|
23
36
|
export declare function SearchList<T>(props: {
|
|
24
37
|
query: string;
|
|
25
38
|
onQuery: (query: string) => void;
|
|
26
39
|
placeholder: string;
|
|
40
|
+
/** The results' accessible name; the placeholder by default. */
|
|
41
|
+
label?: string;
|
|
27
42
|
/** Controls after the field, such as icon buttons. */
|
|
28
43
|
trailing?: JSX.Element;
|
|
44
|
+
/** A search field of the page's own in place of the built-in one. */
|
|
45
|
+
field?: (field: SearchListField) => JSX.Element;
|
|
46
|
+
/** Whether the results show. Closed, only the field remains and the list leaves keys to the page. On by default. */
|
|
47
|
+
open?: boolean;
|
|
48
|
+
/** Float the results beneath the field on a raised surface, over what follows it. */
|
|
49
|
+
popover?: boolean;
|
|
29
50
|
items: T[];
|
|
30
51
|
key: (item: T) => string;
|
|
31
52
|
section?: (item: T) => string;
|
|
@@ -35,6 +56,11 @@ export declare function SearchList<T>(props: {
|
|
|
35
56
|
header?: (item: T) => JSX.Element;
|
|
36
57
|
/** Shown in place of the rows when there are none. */
|
|
37
58
|
empty: JSX.Element;
|
|
59
|
+
/** A note beneath the rows, such as a hint that more results are hidden. */
|
|
60
|
+
footer?: JSX.Element;
|
|
61
|
+
/** Where the results start scrolled each time they mount, such as a position kept from an earlier visit. */
|
|
62
|
+
scrollTop?: number;
|
|
63
|
+
onScroll?: (scrollTop: number) => void;
|
|
38
64
|
onSelect: (item: T) => void;
|
|
39
65
|
onActive?: (item: T | undefined) => void;
|
|
40
66
|
/** Runs before the list's own keys; call `preventDefault` to claim one. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opencode/ui",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-51",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -286,7 +286,7 @@
|
|
|
286
286
|
"dependencies": {
|
|
287
287
|
"@kitlangton/solid-motion": "0.2.2",
|
|
288
288
|
"@kobalte/core": "0.13.13",
|
|
289
|
-
"@opencode/util": "0.0.0-dev-
|
|
289
|
+
"@opencode/util": "0.0.0-dev-51",
|
|
290
290
|
"@pierre/diffs": "1.6.1",
|
|
291
291
|
"@pierre/highlights": "0.2.0",
|
|
292
292
|
"@solid-primitives/event-listener": "2.4.6",
|
|
@@ -46,12 +46,14 @@ function Digit(props: { digit: string; dir: number; spring: DurationOptions }) {
|
|
|
46
46
|
let from = 0
|
|
47
47
|
let to = 0
|
|
48
48
|
|
|
49
|
+
const progress = () => (spring ? Math.max(0, Math.min(1, spring.value)) : 1)
|
|
50
|
+
|
|
49
51
|
const paint = () => {
|
|
50
|
-
const p =
|
|
52
|
+
const p = progress()
|
|
51
53
|
roll(incoming, enter * (1 - p))
|
|
52
54
|
roll(outgoing, from + (to - from) * p)
|
|
53
55
|
|
|
54
|
-
if (!spring && outgoing) outgoing.
|
|
56
|
+
if (!spring && outgoing) outgoing.dataset.leaving = ""
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
const tick = (dt: number) => {
|
|
@@ -76,20 +78,30 @@ function Digit(props: { digit: string; dir: number; spring: DurationOptions }) {
|
|
|
76
78
|
last = next
|
|
77
79
|
|
|
78
80
|
if (!incoming || !outgoing || next === prev) return
|
|
79
|
-
incoming.textContent = next
|
|
80
81
|
|
|
81
82
|
if (prefersReducedMotion() || !incoming.isConnected) {
|
|
83
|
+
incoming.textContent = next
|
|
82
84
|
spring = undefined
|
|
83
85
|
paint()
|
|
84
86
|
|
|
85
87
|
return
|
|
86
88
|
}
|
|
87
89
|
|
|
88
|
-
// A change mid-roll
|
|
89
|
-
|
|
90
|
+
// A change mid-roll carries on from where both digits are, so together they never show less than one digit.
|
|
91
|
+
// Going back to the digit still leaving brings it back from where it is, and the arriving one leaves the way it
|
|
92
|
+
// came. Otherwise the digit nearer the middle leaves from there, and the new one comes in as far out as the
|
|
93
|
+
// other was, so a digit that had barely appeared never crosses the middle.
|
|
94
|
+
const p = progress()
|
|
95
|
+
const now = { in: enter * (1 - p), out: from + (to - from) * p }
|
|
96
|
+
const back = !!spring && next === outgoing.dataset.leaving
|
|
97
|
+
const near = back || Math.abs(now.in) <= Math.abs(now.out)
|
|
98
|
+
const far = !spring ? 1 : Math.min(1, Math.abs(near ? now.out : now.in))
|
|
99
|
+
|
|
100
|
+
if (near) outgoing.dataset.leaving = prev
|
|
101
|
+
from = near ? now.in : now.out
|
|
90
102
|
to = -props.dir
|
|
91
|
-
enter = props.dir
|
|
92
|
-
|
|
103
|
+
enter = back ? now.out : props.dir * far
|
|
104
|
+
incoming.textContent = next
|
|
93
105
|
spring = Spring.fromDuration(0, props.spring).set(1)
|
|
94
106
|
paint()
|
|
95
107
|
stop ??= frameLoop.add(tick)
|
|
@@ -109,6 +121,7 @@ function Digit(props: { digit: string; dir: number; spring: DurationOptions }) {
|
|
|
109
121
|
el.textContent = props.digit
|
|
110
122
|
}}
|
|
111
123
|
/>
|
|
124
|
+
{/* The leaving digit is drawn from its attribute, so the number's text is only ever the value it shows. */}
|
|
112
125
|
<span data-slot="rolling-number-glyph" data-leaving="" aria-hidden="true" ref={(el) => (outgoing = el)} />
|
|
113
126
|
</span>
|
|
114
127
|
)
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
[data-component="search-list"] {
|
|
2
|
+
/* Sticky headers and the top fade paint this, so rows scroll under an opaque band. */
|
|
3
|
+
--search-list-surface: var(--v2-background-bg-base);
|
|
4
|
+
|
|
2
5
|
display: flex;
|
|
3
6
|
min-height: 0;
|
|
4
7
|
flex: 1;
|
|
@@ -42,6 +45,17 @@
|
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
|
|
48
|
+
[data-slot="search-list-body"] {
|
|
49
|
+
display: flex;
|
|
50
|
+
min-height: 0;
|
|
51
|
+
flex: 1;
|
|
52
|
+
flex-direction: column;
|
|
53
|
+
|
|
54
|
+
&[hidden] {
|
|
55
|
+
display: none;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
45
59
|
/* Arrow keys scroll the active row clear of the sticky header. Rows fade out past the bottom edge while more follow. */
|
|
46
60
|
[data-slot="search-list-scroll"] {
|
|
47
61
|
min-height: 0;
|
|
@@ -69,7 +83,7 @@
|
|
|
69
83
|
position: absolute;
|
|
70
84
|
inset: var(--search-list-fade-offset, 0px) 0 auto;
|
|
71
85
|
height: 24px;
|
|
72
|
-
background: linear-gradient(var(--
|
|
86
|
+
background: linear-gradient(var(--search-list-surface), transparent);
|
|
73
87
|
content: "";
|
|
74
88
|
opacity: var(--search-list-fade-top, 0);
|
|
75
89
|
}
|
|
@@ -79,6 +93,11 @@
|
|
|
79
93
|
display: flex;
|
|
80
94
|
flex-direction: column;
|
|
81
95
|
padding: 6px 6px 8px;
|
|
96
|
+
|
|
97
|
+
/* Its padding would sit above the empty state and push it below the centre. */
|
|
98
|
+
&[hidden] {
|
|
99
|
+
display: none;
|
|
100
|
+
}
|
|
82
101
|
}
|
|
83
102
|
|
|
84
103
|
[data-slot="search-list-section"] {
|
|
@@ -104,7 +123,7 @@
|
|
|
104
123
|
height: 28px;
|
|
105
124
|
margin-inline: -6px;
|
|
106
125
|
padding-inline: 18px;
|
|
107
|
-
background: var(--
|
|
126
|
+
background: var(--search-list-surface);
|
|
108
127
|
color: var(--v2-text-text-muted);
|
|
109
128
|
font-size: 13px;
|
|
110
129
|
font-weight: 440;
|
|
@@ -160,6 +179,40 @@
|
|
|
160
179
|
line-height: var(--line-height-compact);
|
|
161
180
|
letter-spacing: -0.04px;
|
|
162
181
|
}
|
|
182
|
+
|
|
183
|
+
/* On the rows' text spine, under the bottom fade rather than inside it. */
|
|
184
|
+
[data-slot="search-list-footer"] {
|
|
185
|
+
flex-shrink: 0;
|
|
186
|
+
padding: 4px 18px 12px;
|
|
187
|
+
color: var(--v2-text-text-muted);
|
|
188
|
+
font-size: 13px;
|
|
189
|
+
font-weight: 440;
|
|
190
|
+
line-height: var(--line-height-compact);
|
|
191
|
+
letter-spacing: -0.04px;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
&[data-popover] {
|
|
195
|
+
--search-list-surface: var(--v2-background-bg-layer-01);
|
|
196
|
+
|
|
197
|
+
position: relative;
|
|
198
|
+
flex: none;
|
|
199
|
+
|
|
200
|
+
[data-slot="search-list-body"] {
|
|
201
|
+
position: absolute;
|
|
202
|
+
inset-block-start: calc(100% + 4px);
|
|
203
|
+
inset-inline: 0;
|
|
204
|
+
z-index: 12;
|
|
205
|
+
max-height: min(45vh, 480px);
|
|
206
|
+
overflow: hidden;
|
|
207
|
+
border-radius: 8px;
|
|
208
|
+
background: var(--search-list-surface);
|
|
209
|
+
box-shadow: var(--v2-elevation-floating);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
[data-slot="search-list-scroll"] {
|
|
213
|
+
flex: 0 1 auto;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
163
216
|
}
|
|
164
217
|
|
|
165
218
|
[data-color-scheme="dark"] [data-component="search-list"] [data-slot="search-list-row"][data-active] {
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
createEffect,
|
|
4
|
+
createMemo,
|
|
5
|
+
For,
|
|
6
|
+
type JSX,
|
|
7
|
+
on,
|
|
8
|
+
onCleanup,
|
|
9
|
+
onMount,
|
|
10
|
+
Show,
|
|
11
|
+
useContext,
|
|
12
|
+
} from "solid-js"
|
|
2
13
|
import { createResizeObserver } from "@solid-primitives/resize-observer"
|
|
3
14
|
import { Icon } from "@opencode/ui/icon"
|
|
4
15
|
import { TextInput } from "../text-input/text-input"
|
|
@@ -18,6 +29,17 @@ export type SearchListRow = {
|
|
|
18
29
|
onClick: () => void
|
|
19
30
|
}
|
|
20
31
|
|
|
32
|
+
/** Attributes for the input of a field passed as `field`: spread them onto it. */
|
|
33
|
+
export type SearchListField = {
|
|
34
|
+
role: "combobox"
|
|
35
|
+
"aria-expanded": boolean
|
|
36
|
+
"aria-autocomplete": "list"
|
|
37
|
+
"aria-controls": string | undefined
|
|
38
|
+
"aria-activedescendant": string | undefined
|
|
39
|
+
onInput: (event: InputEvent & { currentTarget: HTMLInputElement }) => void
|
|
40
|
+
onKeyDown: (event: KeyboardEvent) => void
|
|
41
|
+
}
|
|
42
|
+
|
|
21
43
|
export type SearchListHandle<T> = {
|
|
22
44
|
active: () => T | undefined
|
|
23
45
|
setActive: (key: string | undefined) => void
|
|
@@ -29,13 +51,22 @@ const QueryContext = createContext<() => string>(() => "")
|
|
|
29
51
|
* A search field over sectioned results. Rows that share a `section` key list together under one header, which sticks
|
|
30
52
|
* while its rows scroll beneath it until the next header pushes it away. The first row is active until the user picks
|
|
31
53
|
* another: ↑/↓ wrap, ⌘ or ⌥ with ↑/↓ jump between sections, Home/End go to the ends, Enter selects and Escape closes.
|
|
54
|
+
* A page can keep its own field through `field` and float the results beneath it with `popover`.
|
|
32
55
|
*/
|
|
33
56
|
export function SearchList<T>(props: {
|
|
34
57
|
query: string
|
|
35
58
|
onQuery: (query: string) => void
|
|
36
59
|
placeholder: string
|
|
60
|
+
/** The results' accessible name; the placeholder by default. */
|
|
61
|
+
label?: string
|
|
37
62
|
/** Controls after the field, such as icon buttons. */
|
|
38
63
|
trailing?: JSX.Element
|
|
64
|
+
/** A search field of the page's own in place of the built-in one. */
|
|
65
|
+
field?: (field: SearchListField) => JSX.Element
|
|
66
|
+
/** Whether the results show. Closed, only the field remains and the list leaves keys to the page. On by default. */
|
|
67
|
+
open?: boolean
|
|
68
|
+
/** Float the results beneath the field on a raised surface, over what follows it. */
|
|
69
|
+
popover?: boolean
|
|
39
70
|
items: T[]
|
|
40
71
|
key: (item: T) => string
|
|
41
72
|
section?: (item: T) => string
|
|
@@ -45,6 +76,11 @@ export function SearchList<T>(props: {
|
|
|
45
76
|
header?: (item: T) => JSX.Element
|
|
46
77
|
/** Shown in place of the rows when there are none. */
|
|
47
78
|
empty: JSX.Element
|
|
79
|
+
/** A note beneath the rows, such as a hint that more results are hidden. */
|
|
80
|
+
footer?: JSX.Element
|
|
81
|
+
/** Where the results start scrolled each time they mount, such as a position kept from an earlier visit. */
|
|
82
|
+
scrollTop?: number
|
|
83
|
+
onScroll?: (scrollTop: number) => void
|
|
48
84
|
onSelect: (item: T) => void
|
|
49
85
|
onActive?: (item: T | undefined) => void
|
|
50
86
|
/** Runs before the list's own keys; call `preventDefault` to claim one. */
|
|
@@ -59,6 +95,7 @@ export function SearchList<T>(props: {
|
|
|
59
95
|
let results: HTMLDivElement | undefined
|
|
60
96
|
|
|
61
97
|
const sectionOf = (item: T) => props.section?.(item) ?? ""
|
|
98
|
+
const open = () => props.open ?? true
|
|
62
99
|
|
|
63
100
|
// Sections in the order their first row arrives; rows then list section by section, which is also the arrow order.
|
|
64
101
|
const groups = createMemo(() => {
|
|
@@ -173,7 +210,7 @@ export function SearchList<T>(props: {
|
|
|
173
210
|
if (event.isComposing) return
|
|
174
211
|
props.onKeyDown?.(event, typeahead.activeItem())
|
|
175
212
|
|
|
176
|
-
if (event.defaultPrevented) return
|
|
213
|
+
if (event.defaultPrevented || !open()) return
|
|
177
214
|
const move = searchListMove(event)
|
|
178
215
|
|
|
179
216
|
if (!move) return typeahead.onKeyDown(event)
|
|
@@ -198,6 +235,30 @@ export function SearchList<T>(props: {
|
|
|
198
235
|
reveal()
|
|
199
236
|
}
|
|
200
237
|
|
|
238
|
+
onMount(() => {
|
|
239
|
+
if (viewport && props.scrollTop) viewport.scrollTop = props.scrollTop
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
const field: SearchListField = {
|
|
243
|
+
role: "combobox",
|
|
244
|
+
get "aria-expanded"() {
|
|
245
|
+
return open()
|
|
246
|
+
},
|
|
247
|
+
"aria-autocomplete": "list",
|
|
248
|
+
get "aria-controls"() {
|
|
249
|
+
return open() ? typeahead.listID : undefined
|
|
250
|
+
},
|
|
251
|
+
get "aria-activedescendant"() {
|
|
252
|
+
return open() ? typeahead.activeID() : undefined
|
|
253
|
+
},
|
|
254
|
+
onInput: (event) => {
|
|
255
|
+
// A new query starts again from its first row.
|
|
256
|
+
typeahead.setActive(undefined)
|
|
257
|
+
props.onQuery(event.currentTarget.value)
|
|
258
|
+
},
|
|
259
|
+
onKeyDown,
|
|
260
|
+
}
|
|
261
|
+
|
|
201
262
|
const row = (key: string, item: () => T): SearchListRow => ({
|
|
202
263
|
get id() {
|
|
203
264
|
return typeahead.optionID(item())
|
|
@@ -221,80 +282,91 @@ export function SearchList<T>(props: {
|
|
|
221
282
|
|
|
222
283
|
return (
|
|
223
284
|
<QueryContext.Provider value={() => props.query}>
|
|
224
|
-
<div data-component="search-list" class={props.class}>
|
|
225
|
-
<
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
/>
|
|
250
|
-
</div>
|
|
251
|
-
<div data-slot="search-list-scroll" data-scrollable ref={(element) => (viewport = element)} onScroll={edges}>
|
|
252
|
-
<div data-slot="search-list-fade" aria-hidden="true" />
|
|
285
|
+
<div data-component="search-list" data-popover={props.popover ? "" : undefined} class={props.class}>
|
|
286
|
+
<Show
|
|
287
|
+
when={props.field}
|
|
288
|
+
fallback={
|
|
289
|
+
<div data-slot="search-list-search">
|
|
290
|
+
<TextInput
|
|
291
|
+
{...field}
|
|
292
|
+
value={props.query}
|
|
293
|
+
autofocus
|
|
294
|
+
autocomplete="off"
|
|
295
|
+
autocorrect="off"
|
|
296
|
+
autocapitalize="off"
|
|
297
|
+
spellcheck={false}
|
|
298
|
+
appearance="large"
|
|
299
|
+
placeholder={props.placeholder}
|
|
300
|
+
aria-label={props.placeholder}
|
|
301
|
+
leadingIcon={<Icon name="magnifying-glass" />}
|
|
302
|
+
trailing={props.trailing}
|
|
303
|
+
/>
|
|
304
|
+
</div>
|
|
305
|
+
}
|
|
306
|
+
>
|
|
307
|
+
{(custom) => custom()(field)}
|
|
308
|
+
</Show>
|
|
309
|
+
<div data-slot="search-list-body" hidden={!open()}>
|
|
253
310
|
<div
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
311
|
+
data-slot="search-list-scroll"
|
|
312
|
+
data-scrollable
|
|
313
|
+
ref={(element) => (viewport = element)}
|
|
314
|
+
onScroll={(event) => {
|
|
315
|
+
edges()
|
|
316
|
+
props.onScroll?.(event.currentTarget.scrollTop)
|
|
317
|
+
}}
|
|
259
318
|
>
|
|
260
|
-
<
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
)
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
319
|
+
<div data-slot="search-list-fade" aria-hidden="true" />
|
|
320
|
+
<div
|
|
321
|
+
ref={results}
|
|
322
|
+
id={typeahead.listID}
|
|
323
|
+
data-slot="search-list-results"
|
|
324
|
+
role="listbox"
|
|
325
|
+
hidden={rows().length === 0}
|
|
326
|
+
aria-label={props.label ?? props.placeholder}
|
|
327
|
+
>
|
|
328
|
+
<For each={sectionKeys()}>
|
|
329
|
+
{(section) => {
|
|
330
|
+
const keys = createMemo<string[]>((previous) =>
|
|
331
|
+
stable(previous, (groups().get(section) ?? []).map(props.key)),
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
const first = () => byKey().get(keys()[0] ?? "")
|
|
335
|
+
|
|
336
|
+
const header = createMemo(() =>
|
|
337
|
+
props.header && first() !== undefined ? props.header(first()!) : undefined,
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
const id = `${typeahead.listID}-section-${encodeURIComponent(section)}`
|
|
341
|
+
|
|
342
|
+
return (
|
|
343
|
+
<div data-slot="search-list-section" role="group" aria-labelledby={header() ? id : undefined}>
|
|
344
|
+
<Show when={header()}>
|
|
345
|
+
{(content) => (
|
|
346
|
+
<div id={id} data-slot="search-list-header">
|
|
347
|
+
{content()}
|
|
348
|
+
</div>
|
|
349
|
+
)}
|
|
350
|
+
</Show>
|
|
351
|
+
<For each={keys()}>
|
|
352
|
+
{(key) => {
|
|
353
|
+
// A row that is leaving keeps its last item until it is removed.
|
|
354
|
+
const item = createMemo<T>((previous) => byKey().get(key) ?? previous, byKey().get(key)!)
|
|
355
|
+
|
|
356
|
+
return props.children(item, row(key, item))
|
|
357
|
+
}}
|
|
358
|
+
</For>
|
|
359
|
+
</div>
|
|
360
|
+
)
|
|
361
|
+
}}
|
|
362
|
+
</For>
|
|
363
|
+
</div>
|
|
364
|
+
<Show when={rows().length === 0}>
|
|
365
|
+
<div data-slot="search-list-empty">{props.empty}</div>
|
|
366
|
+
</Show>
|
|
295
367
|
</div>
|
|
296
|
-
<Show when={
|
|
297
|
-
<div data-slot="search-list-
|
|
368
|
+
<Show when={props.footer}>
|
|
369
|
+
<div data-slot="search-list-footer">{props.footer}</div>
|
|
298
370
|
</Show>
|
|
299
371
|
</div>
|
|
300
372
|
</div>
|
|
@@ -35,7 +35,9 @@ export function createTypeahead<T>(props: {
|
|
|
35
35
|
onKeyDown: (event: KeyboardEvent) => {
|
|
36
36
|
if (event.isComposing) return
|
|
37
37
|
const items = props.items()
|
|
38
|
-
|
|
38
|
+
// Modified arrows belong to the input: Shift selects text, Ctrl and the rest are the platform's.
|
|
39
|
+
const plain = !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey
|
|
40
|
+
const delta = !plain ? 0 : event.key === "ArrowDown" ? 1 : event.key === "ArrowUp" ? -1 : 0
|
|
39
41
|
|
|
40
42
|
if (delta !== 0 || event.key === "Enter" || (event.key === "Escape" && props.onClose)) {
|
|
41
43
|
event.preventDefault()
|