bits-ui 2.8.0 → 2.8.2

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 (99) hide show
  1. package/dist/bits/accordion/accordion.svelte.d.ts +6 -1
  2. package/dist/bits/accordion/accordion.svelte.js +15 -5
  3. package/dist/bits/alert-dialog/components/alert-dialog-content.svelte +6 -9
  4. package/dist/bits/aspect-ratio/aspect-ratio.svelte.d.ts +2 -1
  5. package/dist/bits/aspect-ratio/aspect-ratio.svelte.js +3 -1
  6. package/dist/bits/avatar/avatar.svelte.d.ts +4 -1
  7. package/dist/bits/avatar/avatar.svelte.js +9 -3
  8. package/dist/bits/calendar/calendar.svelte.d.ts +15 -1
  9. package/dist/bits/calendar/calendar.svelte.js +42 -14
  10. package/dist/bits/calendar/components/calendar-next-button.svelte +3 -1
  11. package/dist/bits/calendar/components/calendar-prev-button.svelte +3 -1
  12. package/dist/bits/checkbox/checkbox.svelte.d.ts +4 -1
  13. package/dist/bits/checkbox/checkbox.svelte.js +9 -3
  14. package/dist/bits/collapsible/collapsible.svelte.d.ts +4 -1
  15. package/dist/bits/collapsible/collapsible.svelte.js +9 -3
  16. package/dist/bits/command/command.svelte.d.ts +13 -1
  17. package/dist/bits/command/command.svelte.js +36 -12
  18. package/dist/bits/context-menu/components/context-menu-content.svelte +1 -1
  19. package/dist/bits/date-field/date-field.svelte.d.ts +8 -2
  20. package/dist/bits/date-field/date-field.svelte.js +18 -6
  21. package/dist/bits/date-range-field/date-range-field.svelte.d.ts +3 -1
  22. package/dist/bits/date-range-field/date-range-field.svelte.js +6 -2
  23. package/dist/bits/dialog/components/dialog-content.svelte +5 -7
  24. package/dist/bits/dialog/dialog.svelte.d.ts +9 -1
  25. package/dist/bits/dialog/dialog.svelte.js +33 -18
  26. package/dist/bits/dropdown-menu/components/dropdown-menu-content.svelte +3 -2
  27. package/dist/bits/label/label.svelte.d.ts +2 -1
  28. package/dist/bits/label/label.svelte.js +3 -1
  29. package/dist/bits/link-preview/link-preview.svelte.d.ts +3 -1
  30. package/dist/bits/link-preview/link-preview.svelte.js +6 -2
  31. package/dist/bits/menu/menu.svelte.d.ts +12 -1
  32. package/dist/bits/menu/menu.svelte.js +38 -26
  33. package/dist/bits/menubar/components/menubar-trigger.svelte +4 -3
  34. package/dist/bits/menubar/menubar.svelte.d.ts +4 -3
  35. package/dist/bits/menubar/menubar.svelte.js +9 -6
  36. package/dist/bits/meter/meter.svelte.d.ts +2 -1
  37. package/dist/bits/meter/meter.svelte.js +3 -1
  38. package/dist/bits/navigation-menu/components/navigation-menu-link.svelte +2 -1
  39. package/dist/bits/navigation-menu/components/navigation-menu-trigger.svelte +2 -1
  40. package/dist/bits/navigation-menu/navigation-menu.svelte.d.ts +14 -3
  41. package/dist/bits/navigation-menu/navigation-menu.svelte.js +33 -13
  42. package/dist/bits/pagination/pagination.svelte.d.ts +4 -1
  43. package/dist/bits/pagination/pagination.svelte.js +9 -3
  44. package/dist/bits/pin-input/pin-input.svelte.d.ts +4 -1
  45. package/dist/bits/pin-input/pin-input.svelte.js +8 -3
  46. package/dist/bits/popover/popover.svelte.d.ts +4 -1
  47. package/dist/bits/popover/popover.svelte.js +9 -3
  48. package/dist/bits/progress/progress.svelte.d.ts +2 -1
  49. package/dist/bits/progress/progress.svelte.js +3 -1
  50. package/dist/bits/radio-group/radio-group.svelte.d.ts +3 -1
  51. package/dist/bits/radio-group/radio-group.svelte.js +6 -2
  52. package/dist/bits/range-calendar/range-calendar.svelte.d.ts +4 -1
  53. package/dist/bits/range-calendar/range-calendar.svelte.js +9 -3
  54. package/dist/bits/rating-group/rating-group.svelte.d.ts +3 -1
  55. package/dist/bits/rating-group/rating-group.svelte.js +6 -2
  56. package/dist/bits/scroll-area/scroll-area.svelte.d.ts +8 -1
  57. package/dist/bits/scroll-area/scroll-area.svelte.js +20 -7
  58. package/dist/bits/select/select.svelte.d.ts +10 -1
  59. package/dist/bits/select/select.svelte.js +27 -9
  60. package/dist/bits/separator/separator.svelte.d.ts +2 -1
  61. package/dist/bits/separator/separator.svelte.js +3 -1
  62. package/dist/bits/slider/slider.svelte.d.ts +7 -1
  63. package/dist/bits/slider/slider.svelte.js +18 -6
  64. package/dist/bits/switch/switch.svelte.d.ts +3 -1
  65. package/dist/bits/switch/switch.svelte.js +6 -2
  66. package/dist/bits/tabs/tabs.svelte.d.ts +5 -1
  67. package/dist/bits/tabs/tabs.svelte.js +12 -4
  68. package/dist/bits/time-field/time-field.svelte.d.ts +7 -1
  69. package/dist/bits/time-field/time-field.svelte.js +18 -6
  70. package/dist/bits/time-range-field/time-range-field.svelte.d.ts +3 -1
  71. package/dist/bits/time-range-field/time-range-field.svelte.js +6 -2
  72. package/dist/bits/toggle/toggle.svelte.d.ts +2 -1
  73. package/dist/bits/toggle/toggle.svelte.js +3 -1
  74. package/dist/bits/toggle-group/toggle-group.svelte.d.ts +3 -1
  75. package/dist/bits/toggle-group/toggle-group.svelte.js +6 -2
  76. package/dist/bits/toolbar/toolbar.svelte.d.ts +6 -1
  77. package/dist/bits/toolbar/toolbar.svelte.js +15 -5
  78. package/dist/bits/tooltip/tooltip.svelte.d.ts +3 -1
  79. package/dist/bits/tooltip/tooltip.svelte.js +6 -2
  80. package/dist/bits/utilities/floating-layer/use-floating-layer.svelte.d.ts +9 -0
  81. package/dist/bits/utilities/floating-layer/use-floating-layer.svelte.js +6 -3
  82. package/dist/bits/utilities/focus-scope/focus-scope-manager.d.ts +12 -0
  83. package/dist/bits/utilities/focus-scope/focus-scope-manager.js +40 -0
  84. package/dist/bits/utilities/focus-scope/focus-scope.svelte +6 -8
  85. package/dist/bits/utilities/focus-scope/focus-scope.svelte.d.ts +1 -0
  86. package/dist/bits/utilities/focus-scope/focus-scope.svelte.js +204 -0
  87. package/dist/bits/utilities/focus-scope/types.d.ts +2 -6
  88. package/dist/bits/utilities/popper-layer/popper-layer-inner.svelte +2 -2
  89. package/dist/internal/focus.js +1 -1
  90. package/dist/internal/should-enable-focus-trap.d.ts +5 -0
  91. package/dist/internal/should-enable-focus-trap.js +5 -0
  92. package/dist/internal/types.d.ts +2 -1
  93. package/package.json +2 -2
  94. package/dist/bits/utilities/focus-scope/focus-scope-stack.svelte.d.ts +0 -14
  95. package/dist/bits/utilities/focus-scope/focus-scope-stack.svelte.js +0 -50
  96. package/dist/bits/utilities/focus-scope/use-focus-scope.svelte.d.ts +0 -49
  97. package/dist/bits/utilities/focus-scope/use-focus-scope.svelte.js +0 -218
  98. package/dist/internal/should-trap-focus.d.ts +0 -6
  99. package/dist/internal/should-trap-focus.js +0 -5
@@ -52,6 +52,7 @@ export class CommandRootState {
52
52
  return CommandRootContext.set(new CommandRootState(opts));
53
53
  }
54
54
  opts;
55
+ attachment;
55
56
  #updateScheduled = false;
56
57
  #isInitialMount = true;
57
58
  sortAfterTick = false;
@@ -102,6 +103,7 @@ export class CommandRootState {
102
103
  }
103
104
  constructor(opts) {
104
105
  this.opts = opts;
106
+ this.attachment = attachRef(this.opts.ref);
105
107
  const defaults = { ...this._commandState, value: this.opts.value.current ?? "" };
106
108
  this._commandState = defaults;
107
109
  this.commandState = defaults;
@@ -925,7 +927,7 @@ export class CommandRootState {
925
927
  [commandAttrs.root]: "",
926
928
  tabindex: -1,
927
929
  onkeydown: this.onkeydown,
928
- ...attachRef(this.opts.ref),
930
+ ...this.attachment,
929
931
  }));
930
932
  }
931
933
  function itemIsDisabled(item) {
@@ -937,6 +939,7 @@ export class CommandEmptyState {
937
939
  }
938
940
  opts;
939
941
  root;
942
+ attachment;
940
943
  shouldRender = $derived.by(() => {
941
944
  return ((this.root._commandState.filtered.count === 0 && this.#isInitialRender === false) ||
942
945
  this.opts.forceMount.current);
@@ -945,6 +948,7 @@ export class CommandEmptyState {
945
948
  constructor(opts, root) {
946
949
  this.opts = opts;
947
950
  this.root = root;
951
+ this.attachment = attachRef(this.opts.ref);
948
952
  $effect.pre(() => {
949
953
  this.#isInitialRender = false;
950
954
  });
@@ -953,7 +957,7 @@ export class CommandEmptyState {
953
957
  id: this.opts.id.current,
954
958
  role: "presentation",
955
959
  [commandAttrs.empty]: "",
956
- ...attachRef(this.opts.ref),
960
+ ...this.attachment,
957
961
  }));
958
962
  }
959
963
  export class CommandGroupContainerState {
@@ -962,6 +966,7 @@ export class CommandGroupContainerState {
962
966
  }
963
967
  opts;
964
968
  root;
969
+ attachment;
965
970
  shouldRender = $derived.by(() => {
966
971
  if (this.opts.forceMount.current)
967
972
  return true;
@@ -976,6 +981,7 @@ export class CommandGroupContainerState {
976
981
  constructor(opts, root) {
977
982
  this.opts = opts;
978
983
  this.root = root;
984
+ this.attachment = attachRef(this.opts.ref);
979
985
  this.trueValue = opts.value.current ?? opts.id.current;
980
986
  watch(() => this.trueValue, () => {
981
987
  return this.root.registerGroup(this.trueValue);
@@ -1001,7 +1007,7 @@ export class CommandGroupContainerState {
1001
1007
  hidden: this.shouldRender ? undefined : true,
1002
1008
  "data-value": this.trueValue,
1003
1009
  [commandAttrs.group]: "",
1004
- ...attachRef(this.opts.ref),
1010
+ ...this.attachment,
1005
1011
  }));
1006
1012
  }
1007
1013
  export class CommandGroupHeadingState {
@@ -1010,14 +1016,16 @@ export class CommandGroupHeadingState {
1010
1016
  }
1011
1017
  opts;
1012
1018
  group;
1019
+ attachment;
1013
1020
  constructor(opts, group) {
1014
1021
  this.opts = opts;
1015
1022
  this.group = group;
1023
+ this.attachment = attachRef(this.opts.ref, (v) => (this.group.headingNode = v));
1016
1024
  }
1017
1025
  props = $derived.by(() => ({
1018
1026
  id: this.opts.id.current,
1019
1027
  [commandAttrs["group-heading"]]: "",
1020
- ...attachRef(this.opts.ref, (v) => (this.group.headingNode = v)),
1028
+ ...this.attachment,
1021
1029
  }));
1022
1030
  }
1023
1031
  export class CommandGroupItemsState {
@@ -1026,16 +1034,18 @@ export class CommandGroupItemsState {
1026
1034
  }
1027
1035
  opts;
1028
1036
  group;
1037
+ attachment;
1029
1038
  constructor(opts, group) {
1030
1039
  this.opts = opts;
1031
1040
  this.group = group;
1041
+ this.attachment = attachRef(this.opts.ref);
1032
1042
  }
1033
1043
  props = $derived.by(() => ({
1034
1044
  id: this.opts.id.current,
1035
1045
  role: "group",
1036
1046
  [commandAttrs["group-items"]]: "",
1037
1047
  "aria-labelledby": this.group.headingNode?.id ?? undefined,
1038
- ...attachRef(this.opts.ref),
1048
+ ...this.attachment,
1039
1049
  }));
1040
1050
  }
1041
1051
  export class CommandInputState {
@@ -1044,6 +1054,7 @@ export class CommandInputState {
1044
1054
  }
1045
1055
  opts;
1046
1056
  root;
1057
+ attachment;
1047
1058
  #selectedItemId = $derived.by(() => {
1048
1059
  const item = this.root.viewportNode?.querySelector(`${COMMAND_ITEM_SELECTOR}[${COMMAND_VALUE_ATTR}="${cssesc(this.root.opts.value.current)}"]`);
1049
1060
  if (item === undefined || item === null)
@@ -1053,6 +1064,7 @@ export class CommandInputState {
1053
1064
  constructor(opts, root) {
1054
1065
  this.opts = opts;
1055
1066
  this.root = root;
1067
+ this.attachment = attachRef(this.opts.ref, (v) => (this.root.inputNode = v));
1056
1068
  watch(() => this.opts.ref.current, () => {
1057
1069
  const node = this.opts.ref.current;
1058
1070
  if (node && this.opts.autofocus.current) {
@@ -1078,7 +1090,7 @@ export class CommandInputState {
1078
1090
  "aria-controls": this.root.viewportNode?.id ?? undefined,
1079
1091
  "aria-labelledby": this.root.labelNode?.id ?? undefined,
1080
1092
  "aria-activedescendant": this.#selectedItemId,
1081
- ...attachRef(this.opts.ref, (v) => (this.root.inputNode = v)),
1093
+ ...this.attachment,
1082
1094
  }));
1083
1095
  }
1084
1096
  export class CommandItemState {
@@ -1088,6 +1100,7 @@ export class CommandItemState {
1088
1100
  }
1089
1101
  opts;
1090
1102
  root;
1103
+ attachment;
1091
1104
  #group = null;
1092
1105
  #trueForceMount = $derived.by(() => {
1093
1106
  return this.opts.forceMount.current || this.#group?.opts.forceMount.current === true;
@@ -1111,6 +1124,7 @@ export class CommandItemState {
1111
1124
  this.root = root;
1112
1125
  this.#group = CommandGroupContainerContext.getOr(null);
1113
1126
  this.trueValue = opts.value.current;
1127
+ this.attachment = attachRef(this.opts.ref);
1114
1128
  watch([
1115
1129
  () => this.trueValue,
1116
1130
  () => this.#group?.trueValue,
@@ -1164,7 +1178,7 @@ export class CommandItemState {
1164
1178
  role: "option",
1165
1179
  onpointermove: this.onpointermove,
1166
1180
  onclick: this.onclick,
1167
- ...attachRef(this.opts.ref),
1181
+ ...this.attachment,
1168
1182
  }));
1169
1183
  }
1170
1184
  export class CommandLoadingState {
@@ -1172,8 +1186,10 @@ export class CommandLoadingState {
1172
1186
  return new CommandLoadingState(opts);
1173
1187
  }
1174
1188
  opts;
1189
+ attachment;
1175
1190
  constructor(opts) {
1176
1191
  this.opts = opts;
1192
+ this.attachment = attachRef(this.opts.ref);
1177
1193
  }
1178
1194
  props = $derived.by(() => ({
1179
1195
  id: this.opts.id.current,
@@ -1183,7 +1199,7 @@ export class CommandLoadingState {
1183
1199
  "aria-valuemax": 100,
1184
1200
  "aria-label": "Loading...",
1185
1201
  [commandAttrs.loading]: "",
1186
- ...attachRef(this.opts.ref),
1202
+ ...this.attachment,
1187
1203
  }));
1188
1204
  }
1189
1205
  export class CommandSeparatorState {
@@ -1192,17 +1208,19 @@ export class CommandSeparatorState {
1192
1208
  }
1193
1209
  opts;
1194
1210
  root;
1211
+ attachment;
1195
1212
  shouldRender = $derived.by(() => !this.root._commandState.search || this.opts.forceMount.current);
1196
1213
  constructor(opts, root) {
1197
1214
  this.opts = opts;
1198
1215
  this.root = root;
1216
+ this.attachment = attachRef(this.opts.ref);
1199
1217
  }
1200
1218
  props = $derived.by(() => ({
1201
1219
  id: this.opts.id.current,
1202
1220
  // role="separator" cannot belong to a role="listbox"
1203
1221
  "aria-hidden": "true",
1204
1222
  [commandAttrs.separator]: "",
1205
- ...attachRef(this.opts.ref),
1223
+ ...this.attachment,
1206
1224
  }));
1207
1225
  }
1208
1226
  export class CommandListState {
@@ -1211,16 +1229,18 @@ export class CommandListState {
1211
1229
  }
1212
1230
  opts;
1213
1231
  root;
1232
+ attachment;
1214
1233
  constructor(opts, root) {
1215
1234
  this.opts = opts;
1216
1235
  this.root = root;
1236
+ this.attachment = attachRef(this.opts.ref);
1217
1237
  }
1218
1238
  props = $derived.by(() => ({
1219
1239
  id: this.opts.id.current,
1220
1240
  role: "listbox",
1221
1241
  "aria-label": this.opts.ariaLabel.current,
1222
1242
  [commandAttrs.list]: "",
1223
- ...attachRef(this.opts.ref),
1243
+ ...this.attachment,
1224
1244
  }));
1225
1245
  }
1226
1246
  export class CommandLabelState {
@@ -1229,16 +1249,18 @@ export class CommandLabelState {
1229
1249
  }
1230
1250
  opts;
1231
1251
  root;
1252
+ attachment;
1232
1253
  constructor(opts, root) {
1233
1254
  this.opts = opts;
1234
1255
  this.root = root;
1256
+ this.attachment = attachRef(this.opts.ref, (v) => (this.root.labelNode = v));
1235
1257
  }
1236
1258
  props = $derived.by(() => ({
1237
1259
  id: this.opts.id.current,
1238
1260
  [commandAttrs["input-label"]]: "",
1239
1261
  for: this.opts.for?.current,
1240
1262
  style: srOnlyStyles,
1241
- ...attachRef(this.opts.ref, (v) => (this.root.labelNode = v)),
1263
+ ...this.attachment,
1242
1264
  }));
1243
1265
  }
1244
1266
  export class CommandViewportState {
@@ -1247,9 +1269,11 @@ export class CommandViewportState {
1247
1269
  }
1248
1270
  opts;
1249
1271
  list;
1272
+ attachment;
1250
1273
  constructor(opts, list) {
1251
1274
  this.opts = opts;
1252
1275
  this.list = list;
1276
+ this.attachment = attachRef(this.opts.ref, (v) => (this.list.root.viewportNode = v));
1253
1277
  watch([() => this.opts.ref.current, () => this.list.opts.ref.current], ([node, listNode]) => {
1254
1278
  if (node === null || listNode === null)
1255
1279
  return;
@@ -1270,6 +1294,6 @@ export class CommandViewportState {
1270
1294
  props = $derived.by(() => ({
1271
1295
  id: this.opts.id.current,
1272
1296
  [commandAttrs.viewport]: "",
1273
- ...attachRef(this.opts.ref, (v) => (this.list.root.viewportNode = v)),
1297
+ ...this.attachment,
1274
1298
  }));
1275
1299
  }
@@ -22,7 +22,7 @@
22
22
  // the default menu behavior of handling outside interactions on the trigger
23
23
  onEscapeKeydown = noop,
24
24
  forceMount = false,
25
- trapFocus = true,
25
+ trapFocus = false,
26
26
  ...restProps
27
27
  }: ContextMenuContentProps = $props();
28
28
 
@@ -2,7 +2,7 @@ import type { Updater } from "svelte/store";
2
2
  import type { DateValue } from "@internationalized/date";
3
3
  import { type WritableBox, DOMContext, type ReadableBoxedValues, type WritableBoxedValues } from "svelte-toolbelt";
4
4
  import type { DateRangeFieldRootState } from "../date-range-field/date-range-field.svelte.js";
5
- import type { BitsFocusEvent, BitsKeyboardEvent, BitsMouseEvent, WithRefOpts } from "../../internal/types.js";
5
+ import type { BitsFocusEvent, BitsKeyboardEvent, BitsMouseEvent, WithRefOpts, RefAttachment } from "../../internal/types.js";
6
6
  import type { DateAndTimeSegmentObj, DateOnInvalid, DateSegmentObj, DateSegmentPart, DateValidator, Granularity, HourCycle, SegmentPart, SegmentValueObj, TimeSegmentObj, EditableTimeSegmentPart } from "../../shared/date/types.js";
7
7
  import { type Formatter } from "../../internal/date-time/formatter.js";
8
8
  import { type Announcer } from "../../internal/date-time/announcer.js";
@@ -171,6 +171,7 @@ export declare class DateFieldInputState {
171
171
  readonly opts: DateFieldInputStateOpts;
172
172
  readonly root: DateFieldRootState;
173
173
  readonly domContext: DOMContext;
174
+ readonly attachment: RefAttachment;
174
175
  constructor(opts: DateFieldInputStateOpts, root: DateFieldRootState);
175
176
  readonly props: {
176
177
  readonly id: string;
@@ -200,6 +201,7 @@ export declare class DateFieldLabelState {
200
201
  static create(opts: DateFieldLabelStateOpts): DateFieldLabelState;
201
202
  readonly opts: DateFieldLabelStateOpts;
202
203
  readonly root: DateFieldRootState;
204
+ readonly attachment: RefAttachment;
203
205
  constructor(opts: DateFieldLabelStateOpts, root: DateFieldRootState);
204
206
  onclick(_: BitsMouseEvent): void;
205
207
  readonly props: {
@@ -216,6 +218,7 @@ declare abstract class BaseNumericSegmentState {
216
218
  readonly announcer: Announcer;
217
219
  readonly part: string;
218
220
  readonly config: SegmentConfig;
221
+ readonly attachment: RefAttachment;
219
222
  constructor(opts: WithRefOpts, root: DateFieldRootState, part: string, config: SegmentConfig);
220
223
  onkeydown(e: BitsKeyboardEvent): void;
221
224
  onfocusout(_: BitsFocusEvent): void;
@@ -226,7 +229,7 @@ declare abstract class BaseNumericSegmentState {
226
229
  "aria-valuenow": number;
227
230
  "aria-valuetext": string;
228
231
  };
229
- props: {
232
+ readonly props: {
230
233
  "aria-invalid": "true" | undefined;
231
234
  "aria-disabled": "true" | "false";
232
235
  "aria-readonly": "true" | "false";
@@ -313,6 +316,7 @@ export declare class DateFieldDayPeriodSegmentState {
313
316
  static create(opts: DateFieldDayPeriodSegmentStateOpts): DateFieldDayPeriodSegmentState;
314
317
  readonly opts: DateFieldDayPeriodSegmentStateOpts;
315
318
  readonly root: DateFieldRootState;
319
+ readonly attachment: RefAttachment;
316
320
  constructor(opts: DateFieldDayPeriodSegmentStateOpts, root: DateFieldRootState);
317
321
  onkeydown(e: BitsKeyboardEvent): void;
318
322
  readonly props: {
@@ -377,6 +381,7 @@ export declare class DateFieldLiteralSegmentState {
377
381
  static create(opts: DateFieldLiteralSegmentStateOpts): DateFieldLiteralSegmentState;
378
382
  readonly opts: DateFieldLiteralSegmentStateOpts;
379
383
  readonly root: DateFieldRootState;
384
+ readonly attachment: RefAttachment;
380
385
  constructor(opts: DateFieldLiteralSegmentStateOpts, root: DateFieldRootState);
381
386
  readonly props: {
382
387
  readonly "aria-invalid": "true" | undefined;
@@ -410,6 +415,7 @@ export declare class DateFieldTimeZoneSegmentState {
410
415
  static create(opts: DateFieldTimeZoneSegmentStateOpts): DateFieldTimeZoneSegmentState;
411
416
  readonly opts: DateFieldTimeZoneSegmentStateOpts;
412
417
  readonly root: DateFieldRootState;
418
+ readonly attachment: RefAttachment;
413
419
  constructor(opts: DateFieldTimeZoneSegmentStateOpts, root: DateFieldRootState);
414
420
  onkeydown(e: BitsKeyboardEvent): void;
415
421
  readonly props: {
@@ -574,11 +574,13 @@ export class DateFieldInputState {
574
574
  opts;
575
575
  root;
576
576
  domContext;
577
+ attachment;
577
578
  constructor(opts, root) {
578
579
  this.opts = opts;
579
580
  this.root = root;
580
581
  this.domContext = new DOMContext(opts.ref);
581
582
  this.root.domContext = this.domContext;
583
+ this.attachment = attachRef(opts.ref, (v) => this.root.setFieldNode(v));
582
584
  watch(() => this.opts.name.current, (v) => {
583
585
  this.root.setName(v);
584
586
  });
@@ -600,7 +602,7 @@ export class DateFieldInputState {
600
602
  "data-invalid": this.root.isInvalid ? "" : undefined,
601
603
  "data-disabled": getDataDisabled(this.root.disabled.current),
602
604
  [dateFieldAttrs.input]: "",
603
- ...attachRef(this.opts.ref, (v) => this.root.setFieldNode(v)),
605
+ ...this.attachment,
604
606
  }));
605
607
  }
606
608
  export class DateFieldHiddenInputState {
@@ -627,10 +629,12 @@ export class DateFieldLabelState {
627
629
  }
628
630
  opts;
629
631
  root;
632
+ attachment;
630
633
  constructor(opts, root) {
631
634
  this.opts = opts;
632
635
  this.root = root;
633
636
  this.onclick = this.onclick.bind(this);
637
+ this.attachment = attachRef(opts.ref, (v) => this.root.setLabelNode(v));
634
638
  }
635
639
  onclick(_) {
636
640
  if (this.root.disabled.current)
@@ -646,7 +650,7 @@ export class DateFieldLabelState {
646
650
  "data-disabled": getDataDisabled(this.root.disabled.current),
647
651
  [dateFieldAttrs.label]: "",
648
652
  onclick: this.onclick,
649
- ...attachRef(this.opts.ref, (v) => this.root.setLabelNode(v)),
653
+ ...this.attachment,
650
654
  }));
651
655
  }
652
656
  // Base class for numeric segments
@@ -656,6 +660,7 @@ class BaseNumericSegmentState {
656
660
  announcer;
657
661
  part;
658
662
  config;
663
+ attachment;
659
664
  constructor(opts, root, part, config) {
660
665
  this.opts = opts;
661
666
  this.root = root;
@@ -664,6 +669,7 @@ class BaseNumericSegmentState {
664
669
  this.announcer = root.announcer;
665
670
  this.onkeydown = this.onkeydown.bind(this);
666
671
  this.onfocusout = this.onfocusout.bind(this);
672
+ this.attachment = attachRef(opts.ref);
667
673
  }
668
674
  #getMax() {
669
675
  return typeof this.config.max === "function" ? this.config.max(this.root) : this.config.max;
@@ -908,7 +914,7 @@ class BaseNumericSegmentState {
908
914
  onfocusout: this.onfocusout,
909
915
  onclick: this.root.handleSegmentClick,
910
916
  ...this.root.getBaseSegmentAttrs(this.part, this.opts.id.current),
911
- ...attachRef(this.opts.ref),
917
+ ...this.attachment,
912
918
  };
913
919
  });
914
920
  }
@@ -1085,12 +1091,14 @@ export class DateFieldDayPeriodSegmentState {
1085
1091
  }
1086
1092
  opts;
1087
1093
  root;
1094
+ attachment;
1088
1095
  #announcer;
1089
1096
  constructor(opts, root) {
1090
1097
  this.opts = opts;
1091
1098
  this.root = root;
1092
1099
  this.#announcer = this.root.announcer;
1093
1100
  this.onkeydown = this.onkeydown.bind(this);
1101
+ this.attachment = attachRef(opts.ref, (v) => (this.root.dayPeriodNode = v));
1094
1102
  }
1095
1103
  onkeydown(e) {
1096
1104
  if (e.ctrlKey || e.metaKey || this.root.disabled.current)
@@ -1151,7 +1159,7 @@ export class DateFieldDayPeriodSegmentState {
1151
1159
  onkeydown: this.onkeydown,
1152
1160
  onclick: this.root.handleSegmentClick,
1153
1161
  ...this.root.getBaseSegmentAttrs("dayPeriod", this.opts.id.current),
1154
- ...attachRef(this.opts.ref, (v) => (this.root.dayPeriodNode = v)),
1162
+ ...this.attachment,
1155
1163
  };
1156
1164
  });
1157
1165
  }
@@ -1161,15 +1169,17 @@ export class DateFieldLiteralSegmentState {
1161
1169
  }
1162
1170
  opts;
1163
1171
  root;
1172
+ attachment;
1164
1173
  constructor(opts, root) {
1165
1174
  this.opts = opts;
1166
1175
  this.root = root;
1176
+ this.attachment = attachRef(opts.ref);
1167
1177
  }
1168
1178
  props = $derived.by(() => ({
1169
1179
  id: this.opts.id.current,
1170
1180
  "aria-hidden": getAriaHidden(true),
1171
1181
  ...this.root.getBaseSegmentAttrs("literal", this.opts.id.current),
1172
- ...attachRef(this.opts.ref),
1182
+ ...this.attachment,
1173
1183
  }));
1174
1184
  }
1175
1185
  export class DateFieldTimeZoneSegmentState {
@@ -1178,10 +1188,12 @@ export class DateFieldTimeZoneSegmentState {
1178
1188
  }
1179
1189
  opts;
1180
1190
  root;
1191
+ attachment;
1181
1192
  constructor(opts, root) {
1182
1193
  this.opts = opts;
1183
1194
  this.root = root;
1184
1195
  this.onkeydown = this.onkeydown.bind(this);
1196
+ this.attachment = attachRef(opts.ref);
1185
1197
  }
1186
1198
  onkeydown(e) {
1187
1199
  if (e.key !== kbd.TAB)
@@ -1202,7 +1214,7 @@ export class DateFieldTimeZoneSegmentState {
1202
1214
  onkeydown: this.onkeydown,
1203
1215
  ...this.root.getBaseSegmentAttrs("timeZoneName", this.opts.id.current),
1204
1216
  "data-readonly": getDataReadonly(true),
1205
- ...attachRef(this.opts.ref),
1217
+ ...this.attachment,
1206
1218
  }));
1207
1219
  }
1208
1220
  export class DateFieldSegmentState {
@@ -3,7 +3,7 @@ import { DOMContext, type ReadableBoxedValues, type WritableBoxedValues } from "
3
3
  import { Context } from "runed";
4
4
  import { DateFieldInputState, DateFieldRootState } from "../date-field/date-field.svelte.js";
5
5
  import type { DateOnInvalid, DateRange, DateRangeValidator, SegmentPart } from "../../shared/index.js";
6
- import type { WithRefOpts } from "../../internal/types.js";
6
+ import type { RefAttachment, WithRefOpts } from "../../internal/types.js";
7
7
  import type { Granularity } from "../../shared/date/types.js";
8
8
  import { type Formatter } from "../../internal/date-time/formatter.js";
9
9
  export declare const dateRangeFieldAttrs: import("../../internal/attrs.js").CreateBitsAttrsReturn<readonly ["root", "label"]>;
@@ -44,6 +44,7 @@ export declare class DateRangeFieldRootState {
44
44
  readonly endValueComplete: boolean;
45
45
  readonly rangeComplete: boolean;
46
46
  domContext: DOMContext;
47
+ readonly attachment: RefAttachment;
47
48
  constructor(opts: DateRangeFieldRootStateOpts);
48
49
  readonly validationStatus: false | {
49
50
  readonly reason: "custom";
@@ -69,6 +70,7 @@ export declare class DateRangeFieldLabelState {
69
70
  static create(opts: DateRangeFieldLabelStateOpts): DateRangeFieldLabelState;
70
71
  readonly opts: DateRangeFieldLabelStateOpts;
71
72
  readonly root: DateRangeFieldRootState;
73
+ readonly attachment: RefAttachment;
72
74
  constructor(opts: DateRangeFieldLabelStateOpts, root: DateRangeFieldRootState);
73
75
  readonly props: {
74
76
  readonly id: string;
@@ -28,6 +28,7 @@ export class DateRangeFieldRootState {
28
28
  endValueComplete = $derived.by(() => this.opts.endValue.current !== undefined);
29
29
  rangeComplete = $derived(this.startValueComplete && this.endValueComplete);
30
30
  domContext;
31
+ attachment;
31
32
  constructor(opts) {
32
33
  this.opts = opts;
33
34
  this.formatter = createFormatter({
@@ -36,6 +37,7 @@ export class DateRangeFieldRootState {
36
37
  yearFormat: box.with(() => "numeric"),
37
38
  });
38
39
  this.domContext = new DOMContext(this.opts.ref);
40
+ this.attachment = attachRef(this.opts.ref, (v) => (this.fieldNode = v));
39
41
  onDestroyEffect(() => {
40
42
  removeDescriptionElement(this.descriptionId, this.domContext.getDocument());
41
43
  });
@@ -142,7 +144,7 @@ export class DateRangeFieldRootState {
142
144
  role: "group",
143
145
  [dateRangeFieldAttrs.root]: "",
144
146
  "data-invalid": getDataInvalid(this.isInvalid),
145
- ...attachRef(this.opts.ref, (v) => (this.fieldNode = v)),
147
+ ...this.attachment,
146
148
  }));
147
149
  }
148
150
  export class DateRangeFieldLabelState {
@@ -151,9 +153,11 @@ export class DateRangeFieldLabelState {
151
153
  }
152
154
  opts;
153
155
  root;
156
+ attachment;
154
157
  constructor(opts, root) {
155
158
  this.opts = opts;
156
159
  this.root = root;
160
+ this.attachment = attachRef(this.opts.ref, (v) => (this.root.labelNode = v));
157
161
  }
158
162
  #onclick = () => {
159
163
  if (this.root.opts.disabled.current)
@@ -169,7 +173,7 @@ export class DateRangeFieldLabelState {
169
173
  "data-disabled": getDataDisabled(this.root.opts.disabled.current),
170
174
  [dateRangeFieldAttrs.label]: "",
171
175
  onclick: this.#onclick,
172
- ...attachRef(this.opts.ref, (v) => (this.root.labelNode = v)),
176
+ ...this.attachment,
173
177
  }));
174
178
  }
175
179
  export class DateRangeFieldInputState {
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { box, mergeProps } from "svelte-toolbelt";
2
+ import { afterSleep, box, mergeProps } from "svelte-toolbelt";
3
3
  import { DialogContentState } from "../dialog.svelte.js";
4
4
  import type { DialogContentProps } from "../types.js";
5
5
  import DismissibleLayer from "../../utilities/dismissible-layer/dismissible-layer.svelte";
@@ -10,8 +10,7 @@
10
10
  import { createId } from "../../../internal/create-id.js";
11
11
  import { noop } from "../../../internal/noop.js";
12
12
  import ScrollLock from "../../utilities/scroll-lock/scroll-lock.svelte";
13
- import { shouldTrapFocus } from "../../../internal/should-trap-focus.js";
14
-
13
+ import { shouldEnableFocusTrap } from "../../../internal/should-enable-focus-trap.js";
15
14
  const uid = $props.id();
16
15
 
17
16
  let {
@@ -51,18 +50,17 @@
51
50
  <FocusScope
52
51
  ref={contentState.opts.ref}
53
52
  loop
54
- trapFocus={shouldTrapFocus({
53
+ {trapFocus}
54
+ enabled={shouldEnableFocusTrap({
55
55
  forceMount,
56
56
  present: contentState.root.opts.open.current,
57
- trapFocus,
58
57
  open: contentState.root.opts.open.current,
59
58
  })}
60
59
  {onOpenAutoFocus}
61
- {id}
62
60
  onCloseAutoFocus={(e) => {
63
61
  onCloseAutoFocus(e);
64
62
  if (e.defaultPrevented) return;
65
- contentState.root.triggerNode?.focus();
63
+ afterSleep(1, () => contentState.root.triggerNode?.focus());
66
64
  }}
67
65
  >
68
66
  {#snippet focusScope({ props: focusScopeProps })}
@@ -1,5 +1,5 @@
1
1
  import { type ReadableBoxedValues, type WritableBoxedValues } from "svelte-toolbelt";
2
- import type { BitsKeyboardEvent, BitsMouseEvent, OnChangeFn, WithRefOpts } from "../../internal/types.js";
2
+ import type { BitsKeyboardEvent, BitsMouseEvent, OnChangeFn, RefAttachment, WithRefOpts } from "../../internal/types.js";
3
3
  type DialogVariant = "alert-dialog" | "dialog";
4
4
  declare const dialogAttrs: import("../../internal/attrs.js").CreateBitsAttrsReturn<readonly ["content", "trigger", "overlay", "title", "description", "close", "cancel", "action"]>;
5
5
  interface DialogRootStateOpts extends WritableBoxedValues<{
@@ -36,6 +36,7 @@ export declare class DialogTriggerState {
36
36
  static create(opts: DialogTriggerStateOpts): DialogTriggerState;
37
37
  readonly opts: DialogTriggerStateOpts;
38
38
  readonly root: DialogRootState;
39
+ readonly attachment: RefAttachment;
39
40
  constructor(opts: DialogTriggerStateOpts, root: DialogRootState);
40
41
  onclick(e: BitsMouseEvent): void;
41
42
  onkeydown(e: BitsKeyboardEvent): void;
@@ -59,6 +60,7 @@ export declare class DialogCloseState {
59
60
  static create(opts: DialogCloseStateOpts): DialogCloseState;
60
61
  readonly opts: DialogCloseStateOpts;
61
62
  readonly root: DialogRootState;
63
+ readonly attachment: RefAttachment;
62
64
  constructor(opts: DialogCloseStateOpts, root: DialogRootState);
63
65
  onclick(e: BitsMouseEvent): void;
64
66
  onkeydown(e: BitsKeyboardEvent): void;
@@ -77,6 +79,7 @@ export declare class DialogActionState {
77
79
  static create(opts: DialogActionStateOpts): DialogActionState;
78
80
  readonly opts: DialogActionStateOpts;
79
81
  readonly root: DialogRootState;
82
+ readonly attachment: RefAttachment;
80
83
  constructor(opts: DialogActionStateOpts, root: DialogRootState);
81
84
  readonly props: {
82
85
  readonly "data-state": "open" | "closed";
@@ -91,6 +94,7 @@ export declare class DialogTitleState {
91
94
  static create(opts: DialogTitleStateOpts): DialogTitleState;
92
95
  readonly opts: DialogTitleStateOpts;
93
96
  readonly root: DialogRootState;
97
+ readonly attachment: RefAttachment;
94
98
  constructor(opts: DialogTitleStateOpts, root: DialogRootState);
95
99
  readonly props: {
96
100
  readonly "data-state": "open" | "closed";
@@ -105,6 +109,7 @@ export declare class DialogDescriptionState {
105
109
  static create(opts: DialogDescriptionStateOpts): DialogDescriptionState;
106
110
  readonly opts: DialogDescriptionStateOpts;
107
111
  readonly root: DialogRootState;
112
+ readonly attachment: RefAttachment;
108
113
  constructor(opts: DialogDescriptionStateOpts, root: DialogRootState);
109
114
  readonly props: {
110
115
  readonly "data-state": "open" | "closed";
@@ -117,6 +122,7 @@ export declare class DialogContentState {
117
122
  static create(opts: DialogContentStateOpts): DialogContentState;
118
123
  readonly opts: DialogContentStateOpts;
119
124
  readonly root: DialogRootState;
125
+ readonly attachment: RefAttachment;
120
126
  constructor(opts: DialogContentStateOpts, root: DialogRootState);
121
127
  readonly snippetProps: {
122
128
  open: boolean;
@@ -141,6 +147,7 @@ export declare class DialogOverlayState {
141
147
  static create(opts: DialogOverlayStateOpts): DialogOverlayState;
142
148
  readonly opts: DialogOverlayStateOpts;
143
149
  readonly root: DialogRootState;
150
+ readonly attachment: RefAttachment;
144
151
  constructor(opts: DialogOverlayStateOpts, root: DialogRootState);
145
152
  readonly snippetProps: {
146
153
  open: boolean;
@@ -161,6 +168,7 @@ export declare class AlertDialogCancelState {
161
168
  static create(opts: AlertDialogCancelStateOpts): AlertDialogCancelState;
162
169
  readonly opts: AlertDialogCancelStateOpts;
163
170
  readonly root: DialogRootState;
171
+ readonly attachment: RefAttachment;
164
172
  constructor(opts: AlertDialogCancelStateOpts, root: DialogRootState);
165
173
  onclick(e: BitsMouseEvent): void;
166
174
  onkeydown(e: BitsKeyboardEvent): void;