@tamagui/select 1.0.1-beta.104 → 1.0.1-beta.105
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/cjs/Select.js +185 -81
- package/dist/cjs/Select.js.map +2 -2
- package/dist/esm/Select.js +174 -70
- package/dist/esm/Select.js.map +2 -2
- package/dist/jsx/Select.js +137 -62
- package/dist/jsx/Select.js.map +2 -2
- package/package.json +12 -11
- package/src/Select.tsx +717 -585
- package/types/Select.d.ts +89 -20
- package/types/Select.d.ts.map +1 -1
package/dist/cjs/Select.js
CHANGED
|
@@ -55,6 +55,7 @@ __export(Select_exports, {
|
|
|
55
55
|
SelectItem: () => SelectItem,
|
|
56
56
|
SelectItemTextFrame: () => SelectItemTextFrame,
|
|
57
57
|
SelectSeparator: () => SelectSeparator,
|
|
58
|
+
SelectSheetContents: () => SelectSheetContents,
|
|
58
59
|
SelectTrigger: () => SelectTrigger,
|
|
59
60
|
SelectViewport: () => SelectViewport,
|
|
60
61
|
SelectViewportFrame: () => SelectViewportFrame,
|
|
@@ -66,14 +67,23 @@ var import_react_use_previous = require("@radix-ui/react-use-previous");
|
|
|
66
67
|
var import_compose_refs = require("@tamagui/compose-refs");
|
|
67
68
|
var import_core = require("@tamagui/core");
|
|
68
69
|
var import_core2 = require("@tamagui/core");
|
|
70
|
+
var import_core3 = require("@tamagui/core");
|
|
69
71
|
var import_create_context = require("@tamagui/create-context");
|
|
70
72
|
var import_list_item = require("@tamagui/list-item");
|
|
73
|
+
var import_portal = require("@tamagui/portal");
|
|
71
74
|
var import_separator = require("@tamagui/separator");
|
|
75
|
+
var import_sheet = require("@tamagui/sheet");
|
|
72
76
|
var import_stacks = require("@tamagui/stacks");
|
|
73
77
|
var import_text = require("@tamagui/text");
|
|
74
78
|
var import_use_controllable_state = require("@tamagui/use-controllable-state");
|
|
75
79
|
var React = __toESM(require("react"));
|
|
76
80
|
var ReactDOM = __toESM(require("react-dom"));
|
|
81
|
+
const SELECT_NAME = "Select";
|
|
82
|
+
const WINDOW_PADDING = 8;
|
|
83
|
+
const SCROLL_ARROW_VELOCITY = 8;
|
|
84
|
+
const SCROLL_ARROW_THRESHOLD = 8;
|
|
85
|
+
const MIN_HEIGHT = 80;
|
|
86
|
+
const FALLBACK_THRESHOLD = 16;
|
|
77
87
|
const userAgent = typeof navigator !== "undefined" && navigator.userAgent || "";
|
|
78
88
|
const isFirefox = userAgent.toLowerCase().includes("firefox");
|
|
79
89
|
if (isFirefox) {
|
|
@@ -82,12 +92,6 @@ if (isFirefox) {
|
|
|
82
92
|
function getVisualOffsetTop() {
|
|
83
93
|
return !/^((?!chrome|android).)*safari/i.test(userAgent) ? (visualViewport == null ? void 0 : visualViewport.offsetTop) ?? 0 : 0;
|
|
84
94
|
}
|
|
85
|
-
const SELECT_NAME = "Select";
|
|
86
|
-
const WINDOW_PADDING = 8;
|
|
87
|
-
const SCROLL_ARROW_VELOCITY = 8;
|
|
88
|
-
const SCROLL_ARROW_THRESHOLD = 8;
|
|
89
|
-
const MIN_HEIGHT = 80;
|
|
90
|
-
const FALLBACK_THRESHOLD = 16;
|
|
91
95
|
const [createSelectContext, createSelectScope] = (0, import_create_context.createContextScope)(SELECT_NAME);
|
|
92
96
|
const [SelectProvider, useSelectContext] = createSelectContext(SELECT_NAME);
|
|
93
97
|
const TRIGGER_NAME = "SelectTrigger";
|
|
@@ -102,6 +106,7 @@ const SelectTrigger = React.forwardRef((props, forwardedRef) => {
|
|
|
102
106
|
"aria-labelledby"
|
|
103
107
|
]);
|
|
104
108
|
const context = useSelectContext(TRIGGER_NAME, __scopeSelect);
|
|
109
|
+
const labelledBy = ariaLabelledby;
|
|
105
110
|
return /* @__PURE__ */ React.createElement(import_list_item.ListItem, __spreadValues(__spreadProps(__spreadValues({
|
|
106
111
|
backgrounded: true,
|
|
107
112
|
radiused: true,
|
|
@@ -114,15 +119,21 @@ const SelectTrigger = React.forwardRef((props, forwardedRef) => {
|
|
|
114
119
|
size: context.size,
|
|
115
120
|
"aria-expanded": context.open,
|
|
116
121
|
"aria-autocomplete": "none",
|
|
122
|
+
"aria-labelledby": labelledBy,
|
|
123
|
+
dir: context.dir,
|
|
117
124
|
disabled,
|
|
118
125
|
"data-disabled": disabled ? "" : void 0
|
|
119
126
|
}, triggerProps), {
|
|
120
127
|
ref: forwardedRef
|
|
121
|
-
}), context.interactions.getReferenceProps()
|
|
128
|
+
}), context.interactions ? context.interactions.getReferenceProps() : {
|
|
129
|
+
onPress() {
|
|
130
|
+
context.setOpen(!context.open);
|
|
131
|
+
}
|
|
132
|
+
}));
|
|
122
133
|
});
|
|
123
134
|
SelectTrigger.displayName = TRIGGER_NAME;
|
|
124
135
|
const VALUE_NAME = "SelectValue";
|
|
125
|
-
const SelectValueFrame = (0,
|
|
136
|
+
const SelectValueFrame = (0, import_core2.styled)(import_text.Paragraph, {
|
|
126
137
|
name: VALUE_NAME,
|
|
127
138
|
selectable: false
|
|
128
139
|
});
|
|
@@ -141,7 +152,7 @@ const SelectValue = SelectValueFrame.extractable(React.forwardRef(({ __scopeSele
|
|
|
141
152
|
}, context.value === void 0 && placeholder !== void 0 ? placeholder : children);
|
|
142
153
|
}));
|
|
143
154
|
SelectValue.displayName = VALUE_NAME;
|
|
144
|
-
const SelectIcon = (0,
|
|
155
|
+
const SelectIcon = (0, import_core2.styled)(import_stacks.XStack, {
|
|
145
156
|
name: "SelectIcon",
|
|
146
157
|
"aria-hidden": true,
|
|
147
158
|
children: /* @__PURE__ */ React.createElement(import_text.Paragraph, null, "\u25BC")
|
|
@@ -149,10 +160,14 @@ const SelectIcon = (0, import_core.styled)(import_stacks.XStack, {
|
|
|
149
160
|
const CONTENT_NAME = "SelectContent";
|
|
150
161
|
const SelectContent = ({ children, __scopeSelect }) => {
|
|
151
162
|
const context = useSelectContext(CONTENT_NAME, __scopeSelect);
|
|
152
|
-
const themeName = (0,
|
|
153
|
-
const
|
|
163
|
+
const themeName = (0, import_core2.useThemeName)();
|
|
164
|
+
const showSheet = useShowSelectSheet(context);
|
|
165
|
+
const contents = /* @__PURE__ */ React.createElement(import_core2.Theme, {
|
|
154
166
|
name: themeName
|
|
155
167
|
}, children);
|
|
168
|
+
if (showSheet && context.open) {
|
|
169
|
+
return contents;
|
|
170
|
+
}
|
|
156
171
|
return /* @__PURE__ */ React.createElement(import_react_dom_interactions.FloatingPortal, null, context.open ? /* @__PURE__ */ React.createElement(import_react_dom_interactions.FloatingOverlay, {
|
|
157
172
|
lockScroll: true
|
|
158
173
|
}, contents) : /* @__PURE__ */ React.createElement("div", {
|
|
@@ -160,7 +175,7 @@ const SelectContent = ({ children, __scopeSelect }) => {
|
|
|
160
175
|
}, contents));
|
|
161
176
|
};
|
|
162
177
|
const VIEWPORT_NAME = "SelectViewport";
|
|
163
|
-
const SelectViewportFrame = (0,
|
|
178
|
+
const SelectViewportFrame = (0, import_core2.styled)(import_stacks.ThemeableStack, {
|
|
164
179
|
name: VIEWPORT_NAME,
|
|
165
180
|
backgroundColor: "$background",
|
|
166
181
|
elevate: true,
|
|
@@ -181,9 +196,19 @@ const SelectViewportFrame = (0, import_core.styled)(import_stacks.ThemeableStack
|
|
|
181
196
|
}
|
|
182
197
|
});
|
|
183
198
|
const SelectViewport = React.forwardRef((props, forwardedRef) => {
|
|
199
|
+
var _b;
|
|
184
200
|
const _a = props, { __scopeSelect, children } = _a, viewportProps = __objRest(_a, ["__scopeSelect", "children"]);
|
|
185
201
|
const context = useSelectContext(VIEWPORT_NAME, __scopeSelect);
|
|
186
|
-
const _b = context.interactions.getFloatingProps(), { style } =
|
|
202
|
+
const _c = ((_b = context.interactions) == null ? void 0 : _b.getFloatingProps()) ?? {}, { style } = _c, floatingProps = __objRest(_c, ["style"]);
|
|
203
|
+
const breakpointActive = useSelectBreakpointActive(context.sheetBreakpoint);
|
|
204
|
+
if (breakpointActive || !import_core.isWeb) {
|
|
205
|
+
return /* @__PURE__ */ React.createElement(import_portal.PortalItem, {
|
|
206
|
+
hostName: `${context.scopeKey}SheetContents`
|
|
207
|
+
}, children);
|
|
208
|
+
}
|
|
209
|
+
if (!context.floatingContext) {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
187
212
|
delete style["scrollbarWidth"];
|
|
188
213
|
delete style["listStyleType"];
|
|
189
214
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("style", {
|
|
@@ -222,7 +247,7 @@ const SelectItem = React.forwardRef((props, forwardedRef) => {
|
|
|
222
247
|
const isSelected = context.value === value;
|
|
223
248
|
const [textValue, setTextValue] = React.useState(textValueProp ?? "");
|
|
224
249
|
const [isFocused, setIsFocused] = React.useState(false);
|
|
225
|
-
const textId = (0,
|
|
250
|
+
const textId = (0, import_core3.useId)();
|
|
226
251
|
const {
|
|
227
252
|
selectedIndex,
|
|
228
253
|
setSelectedIndex,
|
|
@@ -237,12 +262,14 @@ const SelectItem = React.forwardRef((props, forwardedRef) => {
|
|
|
237
262
|
} = context;
|
|
238
263
|
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, (node) => {
|
|
239
264
|
if (node instanceof HTMLElement) {
|
|
240
|
-
listRef
|
|
265
|
+
if (listRef) {
|
|
266
|
+
listRef.current[index] = node;
|
|
267
|
+
}
|
|
241
268
|
}
|
|
242
269
|
});
|
|
243
270
|
React.useEffect(() => {
|
|
244
271
|
setValueAtIndex(index, value);
|
|
245
|
-
}, [index]);
|
|
272
|
+
}, [index, setValueAtIndex, value]);
|
|
246
273
|
const timeoutRef = React.useRef();
|
|
247
274
|
const [allowMouseUp, setAllowMouseUp] = React.useState(false);
|
|
248
275
|
function handleSelect() {
|
|
@@ -265,16 +292,18 @@ const SelectItem = React.forwardRef((props, forwardedRef) => {
|
|
|
265
292
|
}
|
|
266
293
|
}, [open, index, setActiveIndex, selectedIndex]);
|
|
267
294
|
function handleKeyDown(event) {
|
|
268
|
-
if (event.key === "Enter" || event.key === " " && !dataRef.current.typing) {
|
|
295
|
+
if (event.key === "Enter" || event.key === " " && !(dataRef == null ? void 0 : dataRef.current.typing)) {
|
|
269
296
|
event.preventDefault();
|
|
270
297
|
handleSelect();
|
|
271
298
|
}
|
|
272
299
|
}
|
|
273
|
-
const selectItemProps = context.interactions.getItemProps({
|
|
300
|
+
const selectItemProps = context.interactions ? context.interactions.getItemProps({
|
|
274
301
|
onClick: allowMouseUp ? handleSelect : void 0,
|
|
275
302
|
onMouseUp: allowMouseUp ? handleSelect : void 0,
|
|
276
303
|
onKeyDown: handleKeyDown
|
|
277
|
-
})
|
|
304
|
+
}) : {
|
|
305
|
+
onPress: handleSelect
|
|
306
|
+
};
|
|
278
307
|
return /* @__PURE__ */ React.createElement(SelectItemContextProvider, {
|
|
279
308
|
scope: __scopeSelect,
|
|
280
309
|
value,
|
|
@@ -300,17 +329,18 @@ const SelectItem = React.forwardRef((props, forwardedRef) => {
|
|
|
300
329
|
});
|
|
301
330
|
SelectItem.displayName = ITEM_NAME;
|
|
302
331
|
const ITEM_TEXT_NAME = "SelectItemText";
|
|
303
|
-
const SelectItemTextFrame = (0,
|
|
332
|
+
const SelectItemTextFrame = (0, import_core2.styled)(import_text.Paragraph, {
|
|
304
333
|
name: ITEM_TEXT_NAME,
|
|
305
334
|
selectable: false
|
|
306
335
|
});
|
|
307
336
|
const SelectItemText = React.forwardRef((props, forwardedRef) => {
|
|
308
|
-
const _a = props, { __scopeSelect, className
|
|
337
|
+
const _a = props, { __scopeSelect, className } = _a, itemTextProps = __objRest(_a, ["__scopeSelect", "className"]);
|
|
309
338
|
const context = useSelectContext(ITEM_TEXT_NAME, __scopeSelect);
|
|
310
339
|
const itemContext = useSelectItemContext(ITEM_TEXT_NAME, __scopeSelect);
|
|
311
340
|
const ref = React.useRef(null);
|
|
312
341
|
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref, itemContext.onItemTextChange);
|
|
313
342
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SelectItemTextFrame, __spreadProps(__spreadValues({
|
|
343
|
+
className,
|
|
314
344
|
size: context.size,
|
|
315
345
|
id: itemContext.textId
|
|
316
346
|
}, itemTextProps), {
|
|
@@ -319,7 +349,7 @@ const SelectItemText = React.forwardRef((props, forwardedRef) => {
|
|
|
319
349
|
});
|
|
320
350
|
SelectItemText.displayName = ITEM_TEXT_NAME;
|
|
321
351
|
const ITEM_INDICATOR_NAME = "SelectItemIndicator";
|
|
322
|
-
const SelectItemIndicatorFrame = (0,
|
|
352
|
+
const SelectItemIndicatorFrame = (0, import_core2.styled)(import_stacks.XStack, {
|
|
323
353
|
name: ITEM_TEXT_NAME
|
|
324
354
|
});
|
|
325
355
|
const SelectItemIndicator = React.forwardRef((props, forwardedRef) => {
|
|
@@ -334,13 +364,13 @@ const SelectItemIndicator = React.forwardRef((props, forwardedRef) => {
|
|
|
334
364
|
SelectItemIndicator.displayName = ITEM_INDICATOR_NAME;
|
|
335
365
|
const GROUP_NAME = "SelectGroup";
|
|
336
366
|
const [SelectGroupContextProvider, useSelectGroupContext] = createSelectContext(GROUP_NAME);
|
|
337
|
-
const SelectGroupFrame = (0,
|
|
367
|
+
const SelectGroupFrame = (0, import_core2.styled)(import_stacks.YStack, {
|
|
338
368
|
name: GROUP_NAME,
|
|
339
369
|
width: "100%"
|
|
340
370
|
});
|
|
341
371
|
const SelectGroup = React.forwardRef((props, forwardedRef) => {
|
|
342
372
|
const _a = props, { __scopeSelect } = _a, groupProps = __objRest(_a, ["__scopeSelect"]);
|
|
343
|
-
const groupId = (0,
|
|
373
|
+
const groupId = (0, import_core3.useId)();
|
|
344
374
|
return /* @__PURE__ */ React.createElement(SelectGroupContextProvider, {
|
|
345
375
|
scope: __scopeSelect,
|
|
346
376
|
id: groupId || ""
|
|
@@ -387,7 +417,7 @@ const SelectScrollDownButton = React.forwardRef((props, forwardedRef) => {
|
|
|
387
417
|
}));
|
|
388
418
|
});
|
|
389
419
|
SelectScrollDownButton.displayName = SCROLL_DOWN_BUTTON_NAME;
|
|
390
|
-
const SelectScrollButtonImpl = React.forwardRef((props, forwardedRef) => {
|
|
420
|
+
const SelectScrollButtonImpl = React.memo(React.forwardRef((props, forwardedRef) => {
|
|
391
421
|
var _c;
|
|
392
422
|
const _a = props, { __scopeSelect, dir, componentName } = _a, scrollIndicatorProps = __objRest(_a, ["__scopeSelect", "dir", "componentName"]);
|
|
393
423
|
const _b = useSelectContext(componentName, __scopeSelect), { floatingRef, increaseHeight, forceUpdate } = _b, context = __objRest(_b, ["floatingRef", "increaseHeight", "forceUpdate"]);
|
|
@@ -401,8 +431,10 @@ const SelectScrollButtonImpl = React.forwardRef((props, forwardedRef) => {
|
|
|
401
431
|
});
|
|
402
432
|
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, floating);
|
|
403
433
|
React.useLayoutEffect(() => {
|
|
434
|
+
if (!floatingRef)
|
|
435
|
+
return;
|
|
404
436
|
reference(floatingRef.current);
|
|
405
|
-
}, [reference, floatingRef.current]);
|
|
437
|
+
}, [reference, floatingRef == null ? void 0 : floatingRef.current]);
|
|
406
438
|
React.useEffect(() => {
|
|
407
439
|
if (!refs.reference.current || !refs.floating.current || !isVisible) {
|
|
408
440
|
return;
|
|
@@ -420,13 +452,15 @@ const SelectScrollButtonImpl = React.forwardRef((props, forwardedRef) => {
|
|
|
420
452
|
return null;
|
|
421
453
|
}
|
|
422
454
|
const handleScrollArrowChange = () => {
|
|
455
|
+
if (!floatingRef)
|
|
456
|
+
return;
|
|
423
457
|
const floating2 = floatingRef.current;
|
|
424
458
|
const isUp = dir === "up";
|
|
425
459
|
if (floating2) {
|
|
426
460
|
const value = isUp ? -SCROLL_ARROW_VELOCITY : SCROLL_ARROW_VELOCITY;
|
|
427
461
|
const multi = isUp && floating2.scrollTop <= SCROLL_ARROW_THRESHOLD * 2 || !isUp && floating2.scrollTop >= floating2.scrollHeight - floating2.clientHeight - SCROLL_ARROW_THRESHOLD * 2 ? 2 : 1;
|
|
428
462
|
floating2.scrollTop += multi * (isUp ? -SCROLL_ARROW_VELOCITY : SCROLL_ARROW_VELOCITY);
|
|
429
|
-
increaseHeight(floating2, multi === 2 ? value * 2 : value);
|
|
463
|
+
increaseHeight == null ? void 0 : increaseHeight(floating2, multi === 2 ? value * 2 : value);
|
|
430
464
|
forceUpdate();
|
|
431
465
|
}
|
|
432
466
|
};
|
|
@@ -439,7 +473,7 @@ const SelectScrollButtonImpl = React.forwardRef((props, forwardedRef) => {
|
|
|
439
473
|
position: strategy,
|
|
440
474
|
left: x || 0,
|
|
441
475
|
top: y || 0,
|
|
442
|
-
width: `calc(${(((_c = floatingRef.current) == null ? void 0 : _c.offsetWidth) ?? 0) - 2}px)`,
|
|
476
|
+
width: `calc(${(((_c = floatingRef == null ? void 0 : floatingRef.current) == null ? void 0 : _c.offsetWidth) ?? 0) - 2}px)`,
|
|
443
477
|
onPointerMove: () => {
|
|
444
478
|
if (!loopingRef.current) {
|
|
445
479
|
intervalRef.current = setInterval(handleScrollArrowChange, 1e3 / 60);
|
|
@@ -451,51 +485,58 @@ const SelectScrollButtonImpl = React.forwardRef((props, forwardedRef) => {
|
|
|
451
485
|
clearInterval(intervalRef.current);
|
|
452
486
|
}
|
|
453
487
|
}));
|
|
454
|
-
});
|
|
455
|
-
const SelectSeparator = (0,
|
|
488
|
+
}));
|
|
489
|
+
const SelectSeparator = (0, import_core2.styled)(import_separator.Separator, {
|
|
456
490
|
name: "SelectSeparator"
|
|
457
491
|
});
|
|
458
|
-
const
|
|
492
|
+
const useSelectBreakpointActive = (sheetBreakpoint) => {
|
|
493
|
+
const media = (0, import_core.useMedia)();
|
|
494
|
+
return sheetBreakpoint ? media[sheetBreakpoint] : false;
|
|
495
|
+
};
|
|
496
|
+
const useShowSelectSheet = (context) => {
|
|
497
|
+
const breakpointActive = useSelectBreakpointActive(context.sheetBreakpoint);
|
|
498
|
+
return context.open === false ? false : breakpointActive;
|
|
499
|
+
};
|
|
500
|
+
const SelectSheetController = (props) => {
|
|
501
|
+
const context = useSelectContext("SelectSheetController", props.__scopeSelect);
|
|
502
|
+
const showSheet = useShowSelectSheet(context);
|
|
503
|
+
const breakpointActive = useSelectBreakpointActive(context.sheetBreakpoint);
|
|
504
|
+
const getShowSheet = (0, import_core2.useGet)(showSheet);
|
|
505
|
+
return /* @__PURE__ */ React.createElement(import_sheet.SheetController, {
|
|
506
|
+
onChangeOpen: (val) => {
|
|
507
|
+
if (getShowSheet()) {
|
|
508
|
+
props.onChangeOpen(val);
|
|
509
|
+
}
|
|
510
|
+
},
|
|
511
|
+
open: context.open,
|
|
512
|
+
hidden: breakpointActive === false
|
|
513
|
+
}, props.children);
|
|
514
|
+
};
|
|
515
|
+
const SHEET_CONTENTS_NAME = "SelectSheetContents";
|
|
516
|
+
const SelectSheetContents = ({ __scopeSelect }) => {
|
|
517
|
+
const context = useSelectContext(SHEET_CONTENTS_NAME, __scopeSelect);
|
|
518
|
+
return /* @__PURE__ */ React.createElement(import_portal.PortalHost, {
|
|
519
|
+
name: `${context.scopeKey}SheetContents`
|
|
520
|
+
});
|
|
521
|
+
};
|
|
522
|
+
SelectSheetContents.displayName = SHEET_CONTENTS_NAME;
|
|
523
|
+
const SelectInlineImpl = (props) => {
|
|
459
524
|
const {
|
|
460
|
-
id,
|
|
461
525
|
__scopeSelect,
|
|
462
526
|
children,
|
|
463
|
-
open
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
defaultValue,
|
|
468
|
-
onValueChange,
|
|
469
|
-
size: sizeProp,
|
|
470
|
-
dir,
|
|
471
|
-
name,
|
|
472
|
-
autoComplete
|
|
527
|
+
open = false,
|
|
528
|
+
activeIndexRef,
|
|
529
|
+
selectedIndexRef,
|
|
530
|
+
listContentRef
|
|
473
531
|
} = props;
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
defaultProp: defaultOpen || false,
|
|
477
|
-
onChange: onOpenChange
|
|
478
|
-
});
|
|
479
|
-
const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
480
|
-
prop: valueProp,
|
|
481
|
-
defaultProp: defaultValue || "",
|
|
482
|
-
onChange: onValueChange
|
|
483
|
-
});
|
|
484
|
-
const [activeIndex, setActiveIndex] = React.useState(null);
|
|
485
|
-
const selectedIndexRef = React.useRef(null);
|
|
486
|
-
const activeIndexRef = React.useRef(null);
|
|
487
|
-
const prevActiveIndex = (0, import_react_use_previous.usePrevious)(activeIndex);
|
|
532
|
+
const selectContext = useSelectContext("SelectSheetImpl", __scopeSelect);
|
|
533
|
+
const { setActiveIndex, setOpen, setSelectedIndex, selectedIndex, activeIndex, forceUpdate } = selectContext;
|
|
488
534
|
const [showArrows, setShowArrows] = React.useState(false);
|
|
489
535
|
const [scrollTop, setScrollTop] = React.useState(0);
|
|
536
|
+
const prevActiveIndex = (0, import_react_use_previous.usePrevious)(activeIndex);
|
|
490
537
|
const listItemsRef = React.useRef([]);
|
|
491
|
-
const listContentRef = React.useRef([]);
|
|
492
|
-
const [selectedIndex, setSelectedIndex] = React.useState(Math.max(0, listContentRef.current.indexOf(value)));
|
|
493
538
|
const [controlledScrolling, setControlledScrolling] = React.useState(false);
|
|
494
539
|
const [middlewareType, setMiddlewareType] = React.useState("align");
|
|
495
|
-
(0, import_core.useIsomorphicLayoutEffect)(() => {
|
|
496
|
-
selectedIndexRef.current = selectedIndex;
|
|
497
|
-
activeIndexRef.current = activeIndex;
|
|
498
|
-
});
|
|
499
540
|
React.useEffect(() => {
|
|
500
541
|
const frame = requestAnimationFrame(() => {
|
|
501
542
|
setShowArrows(open);
|
|
@@ -509,7 +550,7 @@ const Select = (0, import_core.withStaticProperties)((props) => {
|
|
|
509
550
|
return () => {
|
|
510
551
|
cancelAnimationFrame(frame);
|
|
511
552
|
};
|
|
512
|
-
}, [open]);
|
|
553
|
+
}, [open, setActiveIndex]);
|
|
513
554
|
function getFloatingPadding(floating2) {
|
|
514
555
|
var _a;
|
|
515
556
|
if (!floating2) {
|
|
@@ -590,7 +631,6 @@ const Select = (0, import_core.withStaticProperties)((props) => {
|
|
|
590
631
|
]
|
|
591
632
|
});
|
|
592
633
|
const floatingRef = refs.floating;
|
|
593
|
-
const forceUpdate = React.useReducer(() => ({}), {})[1];
|
|
594
634
|
const showUpArrow = showArrows && scrollTop > SCROLL_ARROW_THRESHOLD;
|
|
595
635
|
const showDownArrow = showArrows && floatingRef.current && scrollTop < floatingRef.current.scrollHeight - floatingRef.current.clientHeight - SCROLL_ARROW_THRESHOLD;
|
|
596
636
|
const interactions = (0, import_react_dom_interactions.useInteractions)([
|
|
@@ -636,7 +676,7 @@ const Select = (0, import_core.withStaticProperties)((props) => {
|
|
|
636
676
|
}
|
|
637
677
|
return currentTop - nextTop;
|
|
638
678
|
}
|
|
639
|
-
}, [middlewareType]);
|
|
679
|
+
}, [middlewareType, selectedIndexRef]);
|
|
640
680
|
const touchPageYRef = React.useRef(null);
|
|
641
681
|
const handleWheel = React.useCallback((event) => {
|
|
642
682
|
var _a;
|
|
@@ -669,7 +709,7 @@ const Select = (0, import_core.withStaticProperties)((props) => {
|
|
|
669
709
|
setScrollTop(currentTarget.scrollTop);
|
|
670
710
|
forceUpdate();
|
|
671
711
|
}
|
|
672
|
-
}, [
|
|
712
|
+
}, [forceUpdate, increaseHeight]);
|
|
673
713
|
React.useEffect(() => {
|
|
674
714
|
function onTouchEnd() {
|
|
675
715
|
touchPageYRef.current = null;
|
|
@@ -775,20 +815,13 @@ const Select = (0, import_core.withStaticProperties)((props) => {
|
|
|
775
815
|
});
|
|
776
816
|
return () => cancelAnimationFrame(frame);
|
|
777
817
|
}, [open]);
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
size: sizeProp,
|
|
782
|
-
scope: __scopeSelect,
|
|
818
|
+
return /* @__PURE__ */ React.createElement(SelectProvider, __spreadProps(__spreadValues({
|
|
819
|
+
scope: __scopeSelect
|
|
820
|
+
}, selectContext), {
|
|
783
821
|
increaseHeight,
|
|
784
|
-
forceUpdate,
|
|
785
822
|
floatingRef,
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
valueNodeHasChildren,
|
|
789
|
-
onValueNodeHasChildrenChange: setValueNodeHasChildren,
|
|
790
|
-
setValueAtIndex: (index, value2) => {
|
|
791
|
-
listContentRef.current[index] = value2;
|
|
823
|
+
setValueAtIndex: (index, value) => {
|
|
824
|
+
listContentRef.current[index] = value;
|
|
792
825
|
},
|
|
793
826
|
interactions: __spreadProps(__spreadValues({}, interactions), {
|
|
794
827
|
getReferenceProps() {
|
|
@@ -838,7 +871,65 @@ const Select = (0, import_core.withStaticProperties)((props) => {
|
|
|
838
871
|
canScrollUp: !!showUpArrow,
|
|
839
872
|
controlledScrolling: true,
|
|
840
873
|
dataRef: context.dataRef,
|
|
841
|
-
listRef: listItemsRef
|
|
874
|
+
listRef: listItemsRef
|
|
875
|
+
}), children);
|
|
876
|
+
};
|
|
877
|
+
const SelectSheetImpl = (props) => {
|
|
878
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, props.children);
|
|
879
|
+
};
|
|
880
|
+
const Select = (0, import_core2.withStaticProperties)((props) => {
|
|
881
|
+
const {
|
|
882
|
+
__scopeSelect,
|
|
883
|
+
children,
|
|
884
|
+
open: openProp,
|
|
885
|
+
defaultOpen,
|
|
886
|
+
onOpenChange,
|
|
887
|
+
value: valueProp,
|
|
888
|
+
defaultValue,
|
|
889
|
+
onValueChange,
|
|
890
|
+
size: sizeProp,
|
|
891
|
+
sheetBreakpoint = false,
|
|
892
|
+
dir
|
|
893
|
+
} = props;
|
|
894
|
+
const isSheet = useSelectBreakpointActive(sheetBreakpoint);
|
|
895
|
+
const SelectImpl = isSheet ? SelectSheetImpl : SelectInlineImpl;
|
|
896
|
+
const forceUpdate = React.useReducer(() => ({}), {})[1];
|
|
897
|
+
const [open, setOpen] = (0, import_use_controllable_state.useControllableState)({
|
|
898
|
+
prop: openProp,
|
|
899
|
+
defaultProp: defaultOpen || false,
|
|
900
|
+
onChange: onOpenChange
|
|
901
|
+
});
|
|
902
|
+
const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
903
|
+
prop: valueProp,
|
|
904
|
+
defaultProp: defaultValue || "",
|
|
905
|
+
onChange: onValueChange
|
|
906
|
+
});
|
|
907
|
+
const [activeIndex, setActiveIndex] = React.useState(null);
|
|
908
|
+
const selectedIndexRef = React.useRef(null);
|
|
909
|
+
const activeIndexRef = React.useRef(null);
|
|
910
|
+
const listContentRef = React.useRef([]);
|
|
911
|
+
const [selectedIndex, setSelectedIndex] = React.useState(Math.max(0, listContentRef.current.indexOf(value)));
|
|
912
|
+
const [valueNode, setValueNode] = React.useState(null);
|
|
913
|
+
const [valueNodeHasChildren, setValueNodeHasChildren] = React.useState(false);
|
|
914
|
+
(0, import_core2.useIsomorphicLayoutEffect)(() => {
|
|
915
|
+
selectedIndexRef.current = selectedIndex;
|
|
916
|
+
activeIndexRef.current = activeIndex;
|
|
917
|
+
});
|
|
918
|
+
return /* @__PURE__ */ React.createElement(SelectProvider, {
|
|
919
|
+
dir,
|
|
920
|
+
size: sizeProp,
|
|
921
|
+
forceUpdate,
|
|
922
|
+
valueNode,
|
|
923
|
+
onValueNodeChange: setValueNode,
|
|
924
|
+
onValueNodeHasChildrenChange: setValueNodeHasChildren,
|
|
925
|
+
valueNodeHasChildren,
|
|
926
|
+
scopeKey: __scopeSelect ? Object.keys(__scopeSelect)[0] : "",
|
|
927
|
+
sheetBreakpoint,
|
|
928
|
+
scope: __scopeSelect,
|
|
929
|
+
setValueAtIndex: (index, value2) => {
|
|
930
|
+
listContentRef.current[index] = value2;
|
|
931
|
+
},
|
|
932
|
+
activeIndex,
|
|
842
933
|
onChange: setValue,
|
|
843
934
|
selectedIndex,
|
|
844
935
|
setActiveIndex,
|
|
@@ -846,7 +937,17 @@ const Select = (0, import_core.withStaticProperties)((props) => {
|
|
|
846
937
|
setSelectedIndex,
|
|
847
938
|
value,
|
|
848
939
|
open
|
|
849
|
-
},
|
|
940
|
+
}, /* @__PURE__ */ React.createElement(SelectSheetController, {
|
|
941
|
+
onChangeOpen: setOpen,
|
|
942
|
+
__scopeSelect
|
|
943
|
+
}, /* @__PURE__ */ React.createElement(SelectImpl, __spreadProps(__spreadValues({
|
|
944
|
+
activeIndexRef,
|
|
945
|
+
listContentRef,
|
|
946
|
+
selectedIndexRef
|
|
947
|
+
}, props), {
|
|
948
|
+
open,
|
|
949
|
+
value
|
|
950
|
+
}), children)));
|
|
850
951
|
}, {
|
|
851
952
|
Content: SelectContent,
|
|
852
953
|
Group: SelectGroup,
|
|
@@ -859,7 +960,9 @@ const Select = (0, import_core.withStaticProperties)((props) => {
|
|
|
859
960
|
ScrollUpButton: SelectScrollUpButton,
|
|
860
961
|
Trigger: SelectTrigger,
|
|
861
962
|
Value: SelectValue,
|
|
862
|
-
Viewport: SelectViewport
|
|
963
|
+
Viewport: SelectViewport,
|
|
964
|
+
SheetContents: SelectSheetContents,
|
|
965
|
+
Sheet: import_sheet.Sheet
|
|
863
966
|
});
|
|
864
967
|
Select.displayName = SELECT_NAME;
|
|
865
968
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -870,6 +973,7 @@ Select.displayName = SELECT_NAME;
|
|
|
870
973
|
SelectItem,
|
|
871
974
|
SelectItemTextFrame,
|
|
872
975
|
SelectSeparator,
|
|
976
|
+
SelectSheetContents,
|
|
873
977
|
SelectTrigger,
|
|
874
978
|
SelectViewport,
|
|
875
979
|
SelectViewportFrame,
|