@ui-sdk/svelte 0.1.0-beta.1 → 0.1.0-beta.10

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 (68) hide show
  1. package/dist/autocomplete/autocomplete-item-text.svelte +31 -8
  2. package/dist/autocomplete/autocomplete.svelte +2 -2
  3. package/dist/autocomplete/autocomplete.svelte.d.ts +2 -2
  4. package/dist/autocomplete.d.ts +1 -1
  5. package/dist/combobox/combobox-item-text.svelte +31 -8
  6. package/dist/combobox/combobox.svelte +4 -2
  7. package/dist/combobox/combobox.svelte.d.ts +1 -1
  8. package/dist/command/command-item-text.svelte +31 -8
  9. package/dist/dialog/dialog-content.svelte +9 -3
  10. package/dist/dialog/dialog-content.svelte.d.ts +1 -0
  11. package/dist/drawer/drawer-content.svelte.d.ts +2 -6
  12. package/dist/field/field-description.svelte +2 -0
  13. package/dist/field/field-error.svelte +3 -6
  14. package/dist/listbox/listbox.svelte +7 -1
  15. package/dist/listbox/listbox.svelte.d.ts +2 -0
  16. package/dist/pagination/pagination.svelte +4 -0
  17. package/dist/pagination/pagination.svelte.d.ts +2 -0
  18. package/dist/popover/popover-content.svelte +4 -2
  19. package/dist/popover/popover-content.svelte.d.ts +1 -0
  20. package/dist/segmented-control.d.ts +1 -1
  21. package/dist/select/select-item-text.svelte +31 -8
  22. package/dist/select/select-trigger-binding.svelte +7 -8
  23. package/dist/select/select-trigger-binding.svelte.d.ts +2 -1
  24. package/dist/select/select-trigger.svelte +19 -11
  25. package/dist/select/select.svelte +7 -1
  26. package/dist/select/select.svelte.d.ts +2 -0
  27. package/dist/shortcuts.svelte.d.ts +2 -1
  28. package/dist/shortcuts.svelte.js +2 -1
  29. package/dist/use-primitive.svelte.js +20 -3
  30. package/docs/agents.md +83 -20
  31. package/docs/components/alert-dialog.md +2 -1
  32. package/docs/components/autocomplete.md +9 -2
  33. package/docs/components/calendar.md +2 -2
  34. package/docs/components/collapsible.md +1 -0
  35. package/docs/components/combobox.md +12 -3
  36. package/docs/components/command.md +1 -0
  37. package/docs/components/date-input.md +2 -0
  38. package/docs/components/date-picker.md +3 -1
  39. package/docs/components/dialog.md +50 -1
  40. package/docs/components/drawer.md +3 -1
  41. package/docs/components/file-input.md +3 -3
  42. package/docs/components/hover-card.md +6 -1
  43. package/docs/components/image-cropper.md +12 -12
  44. package/docs/components/listbox.md +55 -2
  45. package/docs/components/menu.md +10 -2
  46. package/docs/components/menubar.md +1 -0
  47. package/docs/components/navigation-menu.md +1 -0
  48. package/docs/components/number-input.md +1 -0
  49. package/docs/components/pagination.md +3 -2
  50. package/docs/components/popover.md +45 -2
  51. package/docs/components/resizable.md +6 -1
  52. package/docs/components/segmented-control.md +9 -0
  53. package/docs/components/select.md +18 -2
  54. package/docs/components/tabs.md +1 -1
  55. package/docs/components/time-input.md +2 -0
  56. package/docs/components/tooltip.md +6 -1
  57. package/docs/components/trigger-menu.md +3 -0
  58. package/docs/core.md +101 -23
  59. package/docs/forms.md +1 -1
  60. package/docs/installation.md +16 -1
  61. package/docs/introduction.md +2 -2
  62. package/docs/lists-and-menus.md +1 -1
  63. package/docs/llms.txt +33 -13
  64. package/docs/popups.md +1 -1
  65. package/docs/styling-and-animation.md +4 -0
  66. package/docs/utilities/async-options.md +6 -5
  67. package/docs/utilities/shortcuts.md +2 -2
  68. package/package.json +3 -3
@@ -9,7 +9,7 @@ Without text content, it shows the suggestion's label.
9
9
  autocomplete as autocompletePrimitive,
10
10
  type AutocompleteItemTextState,
11
11
  } from "@ui-sdk/core/autocomplete"
12
- import { getContext } from "svelte"
12
+ import { getContext, untrack } from "svelte"
13
13
  import { createAttachmentKey, type Attachment } from "svelte/attachments"
14
14
  import Part from "../part.svelte"
15
15
  import { useHandle } from "../instance.js"
@@ -30,20 +30,43 @@ Without text content, it shows the suggestion's label.
30
30
  // can't be read before it renders, as a Vue slot can. Until then, and on
31
31
  // the server, the content renders as it is. Content that holds elements
32
32
  // stays as it is, and the suggestion's label is what's marked.
33
- let text = $state<string>()
33
+ const key = $derived(item().key)
34
+ // A reused item takes a new key, maybe while a search shows the marked text
35
+ // in place of its content, so its text is read again.
36
+ let text = $derived.by<string | undefined>(() => {
37
+ void key
38
+ return undefined
39
+ })
34
40
  const part = useHandlePart(autocomplete, "item-text", () => ({
35
41
  id: item().key,
36
42
  text: text ?? item().label,
37
43
  }))
44
+ // A reused item or a count in its label changes the content without a new
45
+ // snippet, so only the page can tell.
46
+ const searching = $derived(
47
+ text !== undefined && part.state.segments.some((segment) => segment.match)
48
+ )
38
49
  const learn: Attachment<HTMLElement> = (el) => {
39
- if (!children || text !== undefined) {
50
+ if (!children) {
40
51
  return
41
52
  }
42
- const nodes = [...el.childNodes]
43
- if (nodes.some((node) => node.nodeType === Node.ELEMENT_NODE)) {
44
- return
53
+ const read = () => {
54
+ if (searching) {
55
+ return
56
+ }
57
+ const nodes = [...el.childNodes]
58
+ text = nodes.some((node) => node.nodeType === Node.ELEMENT_NODE)
59
+ ? undefined
60
+ : (el.textContent ?? "").replace(/\s+/g, " ").trim()
45
61
  }
46
- text = (el.textContent ?? "").replace(/\s+/g, " ").trim()
62
+ untrack(read)
63
+ const observer = new MutationObserver(read)
64
+ observer.observe(el, {
65
+ childList: true,
66
+ characterData: true,
67
+ subtree: true,
68
+ })
69
+ return () => observer.disconnect()
47
70
  }
48
71
  const learnKey = createAttachmentKey()
49
72
  </script>
@@ -59,7 +82,7 @@ Without text content, it shows the suggestion's label.
59
82
  {part}
60
83
  props={{
61
84
  ...rest,
62
- children: text === undefined && children ? children : marked,
85
+ children: children && !searching ? children : marked,
63
86
  [learnKey]: learn,
64
87
  }}
65
88
  />
@@ -12,7 +12,7 @@ A text field that suggests as you type. The text is the value. Renders no elemen
12
12
  type AutocompleteDismissReason,
13
13
  type AutocompleteOpenChangeReason,
14
14
  type AutocompleteSubmitDetails,
15
- type AutocompleteValueChangeReason,
15
+ type AutocompleteValueChangeDetails,
16
16
  type ListAnnouncement,
17
17
  type ListData,
18
18
  type ListHighlightDetails,
@@ -28,7 +28,7 @@ A text field that suggests as you type. The text is the value. Renders no elemen
28
28
  import { ContainerKey, OwnContentKey } from "./context.js"
29
29
  import AutocompleteContent from "./autocomplete-content.svelte"
30
30
 
31
- type ValueDetails = ChangeDetails<AutocompleteValueChangeReason>
31
+ type ValueDetails = AutocompleteValueChangeDetails
32
32
  type OpenDetails = ChangeDetails<AutocompleteOpenChangeReason>
33
33
 
34
34
  let {
@@ -1,9 +1,9 @@
1
1
  import type { ChangeDetails, DismissAttemptDetails } from "@ui-sdk/core";
2
2
  import type { AsyncOptionsStatus } from "@ui-sdk/core/async-options";
3
- import { type AutocompleteController, type AutocompleteDismissReason, type AutocompleteOpenChangeReason, type AutocompleteSubmitDetails, type AutocompleteValueChangeReason, type ListAnnouncement, type ListData, type ListHighlightDetails, type SearchFilter } from "@ui-sdk/core/autocomplete";
3
+ import { type AutocompleteController, type AutocompleteDismissReason, type AutocompleteOpenChangeReason, type AutocompleteSubmitDetails, type AutocompleteValueChangeDetails, type ListAnnouncement, type ListData, type ListHighlightDetails, type SearchFilter } from "@ui-sdk/core/autocomplete";
4
4
  import { type Snippet } from "svelte";
5
5
  import { type PopupContainer } from "../popup.svelte";
6
- type ValueDetails = ChangeDetails<AutocompleteValueChangeReason>;
6
+ type ValueDetails = AutocompleteValueChangeDetails;
7
7
  type OpenDetails = ChangeDetails<AutocompleteOpenChangeReason>;
8
8
  type $$ComponentProps = {
9
9
  /** The text. Bind it with `bind:value` to control it. */
@@ -16,4 +16,4 @@ export { default as AutocompleteSeparator } from "./autocomplete/autocomplete-se
16
16
  export { default as AutocompleteStatus } from "./autocomplete/autocomplete-status.svelte";
17
17
  export { default as AutocompleteTrigger } from "./autocomplete/autocomplete-trigger.svelte";
18
18
  export { createAutocompleteController } from "@ui-sdk/core/autocomplete";
19
- export type { AutocompleteApi, AutocompleteArrowState, AutocompleteChangeOptions, AutocompleteClearProps, AutocompleteClearState, AutocompleteContentProps, AutocompleteContentState, AutocompleteController, AutocompleteDismissReason, AutocompleteEmptyState, AutocompleteInputState, AutocompleteItemIconProps, AutocompleteItemIconState, AutocompleteItemProps, AutocompleteItemState, AutocompleteItemTextState, AutocompleteOpenChangeReason, AutocompleteOptions, AutocompletePrimitive, AutocompleteStatusState, AutocompleteSubmitDetails, AutocompleteTriggerState, AutocompleteValueChangeReason, ListAnnouncement, ListData, ListFilter, ListGroup, ListHighlightDetails, ListItem, ListSeparator, MatchSegment, SearchFilter, } from "@ui-sdk/core/autocomplete";
19
+ export type { AutocompleteApi, AutocompleteArrowState, AutocompleteChangeOptions, AutocompleteClearProps, AutocompleteClearState, AutocompleteContentProps, AutocompleteContentState, AutocompleteController, AutocompleteDismissReason, AutocompleteEmptyState, AutocompleteInputState, AutocompleteItemIconProps, AutocompleteItemIconState, AutocompleteItemProps, AutocompleteItemState, AutocompleteItemTextState, AutocompleteOpenChangeReason, AutocompleteOptions, AutocompletePrimitive, AutocompleteStatusState, AutocompleteSubmitDetails, AutocompleteTriggerState, AutocompleteValueChangeDetails, AutocompleteValueChangeReason, ListAnnouncement, ListData, ListFilter, ListGroup, ListHighlightDetails, ListItem, ListSeparator, MatchSegment, SearchFilter, } from "@ui-sdk/core/autocomplete";
@@ -9,7 +9,7 @@ Without text content, it shows the item's label.
9
9
  combobox as comboboxPrimitive,
10
10
  type ComboboxItemTextState,
11
11
  } from "@ui-sdk/core/combobox"
12
- import { getContext } from "svelte"
12
+ import { getContext, untrack } from "svelte"
13
13
  import { createAttachmentKey, type Attachment } from "svelte/attachments"
14
14
  import Part from "../part.svelte"
15
15
  import { useHandle } from "../instance.js"
@@ -27,20 +27,43 @@ Without text content, it shows the item's label.
27
27
  // can't be read before it renders, as a Vue slot can. Until then, and on
28
28
  // the server, the content renders as it is. Content that holds elements
29
29
  // stays as it is, and the item's label is what's marked.
30
- let text = $state<string>()
30
+ const key = $derived(item().key)
31
+ // A reused item takes a new key, maybe while a search shows the marked text
32
+ // in place of its content, so its text is read again.
33
+ let text = $derived.by<string | undefined>(() => {
34
+ void key
35
+ return undefined
36
+ })
31
37
  const part = useHandlePart(combobox, "item-text", () => ({
32
38
  id: item().key,
33
39
  text: text ?? item().label ?? "",
34
40
  }))
41
+ // A reused item or a count in its label changes the content without a new
42
+ // snippet, so only the page can tell.
43
+ const searching = $derived(
44
+ text !== undefined && part.state.segments.some((segment) => segment.match)
45
+ )
35
46
  const learn: Attachment<HTMLElement> = (el) => {
36
- if (!children || text !== undefined) {
47
+ if (!children) {
37
48
  return
38
49
  }
39
- const nodes = [...el.childNodes]
40
- if (nodes.some((node) => node.nodeType === Node.ELEMENT_NODE)) {
41
- return
50
+ const read = () => {
51
+ if (searching) {
52
+ return
53
+ }
54
+ const nodes = [...el.childNodes]
55
+ text = nodes.some((node) => node.nodeType === Node.ELEMENT_NODE)
56
+ ? undefined
57
+ : (el.textContent ?? "").replace(/\s+/g, " ").trim()
42
58
  }
43
- text = (el.textContent ?? "").replace(/\s+/g, " ").trim()
59
+ untrack(read)
60
+ const observer = new MutationObserver(read)
61
+ observer.observe(el, {
62
+ childList: true,
63
+ characterData: true,
64
+ subtree: true,
65
+ })
66
+ return () => observer.disconnect()
44
67
  }
45
68
  const learnKey = createAttachmentKey()
46
69
  </script>
@@ -56,7 +79,7 @@ Without text content, it shows the item's label.
56
79
  {part}
57
80
  props={{
58
81
  ...rest,
59
- children: text === undefined && children ? children : marked,
82
+ children: children && !searching ? children : marked,
60
83
  [learnKey]: learn,
61
84
  }}
62
85
  />
@@ -144,7 +144,7 @@ list are its parts.
144
144
  /** Whether an item's value is the selected value, for object values that aren't the same object. */
145
145
  isItemEqualToValue?: (itemValue: T, value: T) => boolean
146
146
  /** Whether the first matching item is highlighted while typing, so Enter chooses it. `"always"` also highlights the selected item, or the first, when the list opens. */
147
- autoHighlight?: boolean | "always"
147
+ autoHighlight?: boolean | "always" | "selected"
148
148
  /** With `multiple`, whether the input keeps its text after an item is chosen. */
149
149
  keepQuery?: boolean
150
150
  /** What screen readers hear once the Create part's action has been pending for a second. An empty string says nothing. */
@@ -269,6 +269,8 @@ list are its parts.
269
269
  // more per value with `multiple`. The input's attributes change with the
270
270
  // value, so reading them keeps the list of values current.
271
271
  const formInput = useHandlePart(combobox, "form-input")
272
+ // A textarea's value is its text, which the server renders too.
273
+ const { value: formValue, ...formAttrs } = $derived(formInput.slot())
272
274
  const values = $derived(
273
275
  (formInput.attrs,
274
276
  combobox.state.multiple ? combobox.api.internal.serialized() : [])
@@ -279,7 +281,7 @@ list are its parts.
279
281
  {#if items && !own()}
280
282
  <ComboboxContent fromRoot />
281
283
  {/if}
282
- <input {...formInput.slot()} />
284
+ <textarea {...formAttrs}>{formValue}</textarea>
283
285
  {#each values as key (key)}
284
286
  <ValueInput owner={combobox} value={key} />
285
287
  {/each}
@@ -30,7 +30,7 @@ declare function $$render<T = string, Multiple extends boolean | undefined = fal
30
30
  /** Whether an item's value is the selected value, for object values that aren't the same object. */
31
31
  isItemEqualToValue?: (itemValue: T, value: T) => boolean;
32
32
  /** Whether the first matching item is highlighted while typing, so Enter chooses it. `"always"` also highlights the selected item, or the first, when the list opens. */
33
- autoHighlight?: boolean | "always";
33
+ autoHighlight?: boolean | "always" | "selected";
34
34
  /** With `multiple`, whether the input keeps its text after an item is chosen. */
35
35
  keepQuery?: boolean;
36
36
  /** What screen readers hear once the Create part's action has been pending for a second. An empty string says nothing. */
@@ -9,7 +9,7 @@ Without text content, it shows the command's label.
9
9
  command as commandPrimitive,
10
10
  type CommandItemTextState,
11
11
  } from "@ui-sdk/core/command"
12
- import { getContext } from "svelte"
12
+ import { getContext, untrack } from "svelte"
13
13
  import { createAttachmentKey, type Attachment } from "svelte/attachments"
14
14
  import Part from "../part.svelte"
15
15
  import { useHandle } from "../instance.js"
@@ -27,20 +27,43 @@ Without text content, it shows the command's label.
27
27
  // can't be read before it renders, as a Vue slot can. Until then, and on
28
28
  // the server, the content renders as it is. Content that holds elements
29
29
  // stays as it is, and the command's label is what's marked.
30
- let text = $state<string>()
30
+ const key = $derived(item().key)
31
+ // A reused item takes a new key, maybe while a search shows the marked text
32
+ // in place of its content, so its text is read again.
33
+ let text = $derived.by<string | undefined>(() => {
34
+ void key
35
+ return undefined
36
+ })
31
37
  const part = useHandlePart(command, "item-text", () => ({
32
38
  id: item().key,
33
39
  text: text ?? item().label ?? "",
34
40
  }))
41
+ // A reused item or a count in its label changes the content without a new
42
+ // snippet, so only the page can tell.
43
+ const searching = $derived(
44
+ text !== undefined && part.state.segments.some((segment) => segment.match)
45
+ )
35
46
  const learn: Attachment<HTMLElement> = (el) => {
36
- if (!children || text !== undefined) {
47
+ if (!children) {
37
48
  return
38
49
  }
39
- const nodes = [...el.childNodes]
40
- if (nodes.some((node) => node.nodeType === Node.ELEMENT_NODE)) {
41
- return
50
+ const read = () => {
51
+ if (searching) {
52
+ return
53
+ }
54
+ const nodes = [...el.childNodes]
55
+ text = nodes.some((node) => node.nodeType === Node.ELEMENT_NODE)
56
+ ? undefined
57
+ : (el.textContent ?? "").replace(/\s+/g, " ").trim()
42
58
  }
43
- text = (el.textContent ?? "").replace(/\s+/g, " ").trim()
59
+ untrack(read)
60
+ const observer = new MutationObserver(read)
61
+ observer.observe(el, {
62
+ childList: true,
63
+ characterData: true,
64
+ subtree: true,
65
+ })
66
+ return () => observer.disconnect()
44
67
  }
45
68
  const learnKey = createAttachmentKey()
46
69
  </script>
@@ -56,7 +79,7 @@ Without text content, it shows the command's label.
56
79
  {part}
57
80
  props={{
58
81
  ...rest,
59
- children: text === undefined && children ? children : marked,
82
+ children: children && !searching ? children : marked,
60
83
  [learnKey]: learn,
61
84
  }}
62
85
  />
@@ -22,6 +22,7 @@ The dialog itself, named by its title and described by its description.
22
22
  initialFocus,
23
23
  finalFocus,
24
24
  keepMounted,
25
+ inline,
25
26
  container,
26
27
  ...rest
27
28
  }: PartProps<"div", DialogContentState<Payload>> &
@@ -37,13 +38,18 @@ The dialog itself, named by its title and described by its description.
37
38
  // what moves into the container and the top layer. An alert dialog never
38
39
  // presents as a sheet, so it has no viewport to bind.
39
40
  const viewport = dialog.sheet
40
- ? useHandlePart(dialog.handle, "viewport", () => ({}), portalTo(target))
41
+ ? useHandlePart(
42
+ dialog.handle,
43
+ "viewport",
44
+ () => ({}),
45
+ portalTo(() => (inline ? false : target()))
46
+ )
41
47
  : undefined
42
48
  const content = useHandlePart(
43
49
  dialog.handle,
44
50
  "content",
45
- () => ({ initialFocus, finalFocus, keepMounted }),
46
- portalTo(() => (viewport?.present ? false : target()))
51
+ () => ({ initialFocus, finalFocus, keepMounted, inline }),
52
+ portalTo(() => (inline || viewport?.present ? false : target()))
47
53
  )
48
54
  </script>
49
55
 
@@ -14,6 +14,7 @@ declare function $$render<Payload = unknown>(): {
14
14
  initialFocus?: import("@ui-sdk/core/dialog").DialogInitialFocus;
15
15
  finalFocus?: import("@ui-sdk/core/dialog").DialogFinalFocus;
16
16
  keepMounted?: boolean;
17
+ inline?: boolean;
17
18
  } & {
18
19
  /** Renders the popup into this element instead of in place. */
19
20
  container?: PopupContainer;
@@ -1,4 +1,4 @@
1
- import type { DrawerContentState } from "@ui-sdk/core/drawer";
1
+ import type { DrawerContentProps, DrawerContentState } from "@ui-sdk/core/drawer";
2
2
  import { type PopupContainer } from "../popup.svelte";
3
3
  declare function $$render<Payload = unknown>(): {
4
4
  props: Omit<import("svelte/elements").HTMLAttributes<HTMLDivElement>, "children"> & {
@@ -10,11 +10,7 @@ declare function $$render<Payload = unknown>(): {
10
10
  children?: import("svelte").Snippet<[DrawerContentState<Payload>]> | undefined;
11
11
  }]> | undefined;
12
12
  children?: import("svelte").Snippet<[DrawerContentState<Payload>]> | undefined;
13
- } & import("@ui-sdk/core").PortalProps & {
14
- initialFocus?: import("@ui-sdk/core/dialog").DialogInitialFocus;
15
- finalFocus?: import("@ui-sdk/core/dialog").DialogFinalFocus;
16
- keepMounted?: boolean;
17
- } & {
13
+ } & DrawerContentProps & {
18
14
  /** Renders the drawer into this element instead of in place. */
19
15
  container?: PopupContainer;
20
16
  };
@@ -21,11 +21,13 @@ describes the group, so screen readers say it as focus enters the group.
21
21
  const described = getContext<FieldContext | FieldSetContext | undefined>(
22
22
  DescribedKey
23
23
  )
24
+ const uid = $props.id()
24
25
  // A field set's description slot takes the same props, and its state is the
25
26
  // `disabled` that FieldDescriptionState always has.
26
27
  const description = described
27
28
  ? useHandlePart(described as FieldContext, "description", () => ({
28
29
  id: rest.id,
30
+ value: uid,
29
31
  }))
30
32
  : outsidePart("description")
31
33
  </script>
@@ -19,13 +19,10 @@ browser's message for the current problem.
19
19
 
20
20
  const field = useField()
21
21
  const uid = $props.id()
22
- // Only an error with `match` needs an id of its own. One without takes the
23
- // field's, which the control points at before the field binds.
22
+ // Each error is its own part, keyed by a made value. Core gives the first one
23
+ // that shows the id the control points at before the field binds.
24
24
  const error = field
25
- ? useHandlePart(field, "error", () => ({
26
- id: rest.id ?? (match === undefined ? undefined : `ui-sdk-${uid}`),
27
- match,
28
- }))
25
+ ? useHandlePart(field, "error", () => ({ id: rest.id, value: uid, match }))
29
26
  : undefined
30
27
  const shown = $derived(
31
28
  error ? error.present : fieldOutsideErrorShown({ match })
@@ -36,6 +36,7 @@ An always-visible list to choose one option from, or several with `multiple`.
36
36
  deselectable,
37
37
  orientation,
38
38
  loop,
39
+ virtualFocus,
39
40
  keepInView,
40
41
  items,
41
42
  itemToValue,
@@ -66,6 +67,8 @@ An always-visible list to choose one option from, or several with `multiple`.
66
67
  orientation?: "horizontal" | "vertical"
67
68
  /** Whether arrow keys wrap from the last item to the first. */
68
69
  loop?: boolean
70
+ /** Keeps focus on the list, which points at the highlighted option with `aria-activedescendant`. */
71
+ virtualFocus?: boolean
69
72
  /** Whether the list scrolls the option keys move to into view, and the selected option when it first shows. */
70
73
  keepInView?: boolean
71
74
  /** The items as data. Renders them for you. */
@@ -107,6 +110,7 @@ An always-visible list to choose one option from, or several with `multiple`.
107
110
  deselectable,
108
111
  orientation,
109
112
  loop,
113
+ virtualFocus,
110
114
  keepInView,
111
115
  items,
112
116
  itemToValue,
@@ -137,6 +141,8 @@ An always-visible list to choose one option from, or several with `multiple`.
137
141
  // more per value with `multiple`. The input's attributes change with the
138
142
  // value, so reading them keeps the list of values current.
139
143
  const formInput = useHandlePart(listbox, "form-input")
144
+ // A textarea's value is its text, which the server renders too.
145
+ const { value: formValue, ...formAttrs } = $derived(formInput.slot())
140
146
  const values = $derived(
141
147
  (formInput.attrs,
142
148
  listbox.state.multiple ? listbox.api.internal.serialized() : [])
@@ -153,7 +159,7 @@ An always-visible list to choose one option from, or several with `multiple`.
153
159
  part={wrapPart(root, control)}
154
160
  props={{ ...rest, children: children ?? data }}
155
161
  />
156
- <input {...formInput.slot()} />
162
+ <textarea {...formAttrs}>{formValue}</textarea>
157
163
  {#each values as key (key)}
158
164
  <ValueInput owner={listbox} value={key} />
159
165
  {/each}
@@ -17,6 +17,8 @@ type $$ComponentProps = PartProps<"div", ListboxState> & {
17
17
  orientation?: "horizontal" | "vertical";
18
18
  /** Whether arrow keys wrap from the last item to the first. */
19
19
  loop?: boolean;
20
+ /** Keeps focus on the list, which points at the highlighted option with `aria-activedescendant`. */
21
+ virtualFocus?: boolean;
20
22
  /** Whether the list scrolls the option keys move to into view, and the selected option when it first shows. */
21
23
  keepInView?: boolean;
22
24
  /** The items as data. Renders them for you. */
@@ -31,6 +31,7 @@ A navigation landmark around the page links. Name it with `aria-label`.
31
31
  siblings,
32
32
  boundaries,
33
33
  getHref,
34
+ disabled,
34
35
  controller,
35
36
  debug,
36
37
  onPageChange,
@@ -52,6 +53,8 @@ A navigation landmark around the page links. Name it with `aria-label`.
52
53
  boundaries?: number
53
54
  /** The URL of a page. With it, parts are links that work before JavaScript loads. Without it, they're buttons. */
54
55
  getHref?: (page: number) => string
56
+ /** Whether every page and step does nothing, like a step at its end. A controller still pages it. */
57
+ disabled?: boolean
55
58
  /** Pages it from anywhere. Create one with `createPaginationController()`. */
56
59
  controller?: PaginationController
57
60
  /** Logs every change with its reason. */
@@ -73,6 +76,7 @@ A navigation landmark around the page links. Name it with `aria-label`.
73
76
  siblings,
74
77
  boundaries,
75
78
  getHref,
79
+ disabled,
76
80
  controller,
77
81
  debug,
78
82
  onPageChange: (next: number, details: Details) => {
@@ -19,6 +19,8 @@ type $$ComponentProps = PartProps<"nav", PaginationState> & {
19
19
  boundaries?: number;
20
20
  /** The URL of a page. With it, parts are links that work before JavaScript loads. Without it, they're buttons. */
21
21
  getHref?: (page: number) => string;
22
+ /** Whether every page and step does nothing, like a step at its end. A controller still pages it. */
23
+ disabled?: boolean;
22
24
  /** Pages it from anywhere. Create one with `createPaginationController()`. */
23
25
  controller?: PaginationController;
24
26
  /** Logs every change with its reason. */
@@ -32,6 +32,7 @@ The panel itself, positioned against its trigger, named by its title and describ
32
32
  initialFocus,
33
33
  finalFocus,
34
34
  keepMounted,
35
+ inline,
35
36
  container,
36
37
  ...rest
37
38
  }: PartProps<"div", PopoverContentState<Payload>> &
@@ -50,7 +51,7 @@ The panel itself, positioned against its trigger, named by its title and describ
50
51
  popover,
51
52
  "viewport",
52
53
  () => ({}),
53
- portalTo(target)
54
+ portalTo(() => (inline ? false : target()))
54
55
  )
55
56
  const content = useHandlePart(
56
57
  popover,
@@ -66,8 +67,9 @@ The panel itself, positioned against its trigger, named by its title and describ
66
67
  initialFocus,
67
68
  finalFocus,
68
69
  keepMounted,
70
+ inline,
69
71
  }),
70
- portalTo(() => (viewport.present ? false : target()))
72
+ portalTo(() => (inline || viewport.present ? false : target()))
71
73
  )
72
74
  </script>
73
75
 
@@ -18,6 +18,7 @@ declare function $$render<Payload = unknown>(): {
18
18
  initialFocus?: import("@ui-sdk/core/popover").PopoverInitialFocus;
19
19
  finalFocus?: import("@ui-sdk/core/popover").PopoverFinalFocus;
20
20
  keepMounted?: boolean;
21
+ inline?: boolean;
21
22
  } & {
22
23
  /** Renders the popup into this element instead of in place. */
23
24
  container?: PopupContainer;
@@ -2,4 +2,4 @@ export { default as SegmentedControl } from "./segmented-control/segmented-contr
2
2
  export { default as SegmentedControlIndicator } from "./segmented-control/segmented-control-indicator.svelte";
3
3
  export { default as SegmentedControlItem } from "./segmented-control/segmented-control-item.svelte";
4
4
  export { createSegmentedControlController } from "@ui-sdk/core/segmented-control";
5
- export type { SegmentedControlApi, SegmentedControlChangeOptions, SegmentedControlController, SegmentedControlIndicatorState, SegmentedControlItemProps, SegmentedControlItemState, SegmentedControlOptions, SegmentedControlOrientation, SegmentedControlPrimitive, SegmentedControlState, SegmentedControlValueChangeReason, } from "@ui-sdk/core/segmented-control";
5
+ export type { SegmentedControlApi, SegmentedControlChangeOptions, SegmentedControlController, SegmentedControlDirection, SegmentedControlIndicatorState, SegmentedControlItemProps, SegmentedControlItemState, SegmentedControlOptions, SegmentedControlOrientation, SegmentedControlPrimitive, SegmentedControlState, SegmentedControlValueChangeReason, } from "@ui-sdk/core/segmented-control";
@@ -9,7 +9,7 @@ text content, it shows the item's label.
9
9
  select as selectPrimitive,
10
10
  type SelectItemTextState,
11
11
  } from "@ui-sdk/core/select"
12
- import { getContext } from "svelte"
12
+ import { getContext, untrack } from "svelte"
13
13
  import { createAttachmentKey, type Attachment } from "svelte/attachments"
14
14
  import Part from "../part.svelte"
15
15
  import { useHandle } from "../instance.js"
@@ -27,20 +27,43 @@ text content, it shows the item's label.
27
27
  // can't be read before it renders, as a Vue slot can. Until then, and on
28
28
  // the server, the content renders as it is. Content that holds elements
29
29
  // stays as it is, and the item's label is what's marked.
30
- let text = $state<string>()
30
+ const key = $derived(item().key)
31
+ // A reused item takes a new key, maybe while a search shows the marked text
32
+ // in place of its content, so its text is read again.
33
+ let text = $derived.by<string | undefined>(() => {
34
+ void key
35
+ return undefined
36
+ })
31
37
  const part = useHandlePart(select, "item-text", () => ({
32
38
  id: item().key,
33
39
  text: text ?? item().label ?? "",
34
40
  }))
41
+ // A reused item or a count in its label changes the content without a new
42
+ // snippet, so only the page can tell.
43
+ const searching = $derived(
44
+ text !== undefined && part.state.segments.some((segment) => segment.match)
45
+ )
35
46
  const learn: Attachment<HTMLElement> = (el) => {
36
- if (!children || text !== undefined) {
47
+ if (!children) {
37
48
  return
38
49
  }
39
- const nodes = [...el.childNodes]
40
- if (nodes.some((node) => node.nodeType === Node.ELEMENT_NODE)) {
41
- return
50
+ const read = () => {
51
+ if (searching) {
52
+ return
53
+ }
54
+ const nodes = [...el.childNodes]
55
+ text = nodes.some((node) => node.nodeType === Node.ELEMENT_NODE)
56
+ ? undefined
57
+ : (el.textContent ?? "").replace(/\s+/g, " ").trim()
42
58
  }
43
- text = (el.textContent ?? "").replace(/\s+/g, " ").trim()
59
+ untrack(read)
60
+ const observer = new MutationObserver(read)
61
+ observer.observe(el, {
62
+ childList: true,
63
+ characterData: true,
64
+ subtree: true,
65
+ })
66
+ return () => observer.disconnect()
44
67
  }
45
68
  const learnKey = createAttachmentKey()
46
69
  </script>
@@ -56,7 +79,7 @@ text content, it shows the item's label.
56
79
  {part}
57
80
  props={{
58
81
  ...rest,
59
- children: text === undefined && children ? children : marked,
82
+ children: children && !searching ? children : marked,
60
83
  [learnKey]: learn,
61
84
  }}
62
85
  />
@@ -4,13 +4,13 @@
4
4
  type SelectTriggerProps,
5
5
  type SelectTriggerState,
6
6
  } from "@ui-sdk/core/select"
7
- import { useFieldControl } from "../field/context.js"
8
7
  import Part from "../part.svelte"
9
8
  import { provideInstance } from "../instance.js"
10
9
  import {
11
10
  useHandlePart,
12
11
  wrapPart,
13
12
  type PartProps,
13
+ type SlotAttributes,
14
14
  } from "../use-primitive.svelte.js"
15
15
  import type { SelectContext } from "./context.js"
16
16
  import SelectValue from "./select-value.svelte"
@@ -19,11 +19,15 @@
19
19
  // a trigger given another controller keeps its element and focus.
20
20
  let {
21
21
  owner,
22
+ control,
22
23
  disabled,
23
24
  children,
24
25
  ...rest
25
26
  }: PartProps<"button", SelectTriggerState> &
26
- SelectTriggerProps & { owner: SelectContext } = $props()
27
+ SelectTriggerProps & {
28
+ owner: SelectContext
29
+ control?: (attributes: SlotAttributes) => SlotAttributes
30
+ } = $props()
27
31
 
28
32
  // A trigger outside the select brings the select to the value inside it.
29
33
  // Context is set once, so the handle it gets reads the current one.
@@ -39,15 +43,10 @@
39
43
  },
40
44
  controls: (key) => owner.controls(key),
41
45
  })
42
- const field = useFieldControl()
43
46
  const trigger = useHandlePart(
44
47
  () => owner,
45
48
  "trigger",
46
- () => ({ disabled, named: !!field || rest["aria-labelledby"] != null })
47
- )
48
- const control = field?.control(
49
- () => rest.id as string | undefined,
50
- () => rest["aria-describedby"]
49
+ () => ({ disabled, named: !!control || rest["aria-labelledby"] != null })
51
50
  )
52
51
  </script>
53
52
 
@@ -1,8 +1,9 @@
1
1
  import { type SelectTriggerProps, type SelectTriggerState } from "@ui-sdk/core/select";
2
- import { type PartProps } from "../use-primitive.svelte";
2
+ import { type PartProps, type SlotAttributes } from "../use-primitive.svelte";
3
3
  import type { SelectContext } from "./context";
4
4
  type $$ComponentProps = PartProps<"button", SelectTriggerState> & SelectTriggerProps & {
5
5
  owner: SelectContext;
6
+ control?: (attributes: SlotAttributes) => SlotAttributes;
6
7
  };
7
8
  declare const SelectTriggerBinding: import("svelte").Component<$$ComponentProps, {}, "">;
8
9
  type SelectTriggerBinding = ReturnType<typeof SelectTriggerBinding>;