@tamagui/select 1.0.1-beta.46 → 1.0.1-beta.49
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 +28 -52
- package/dist/cjs/Select.js.map +2 -2
- package/dist/esm/Select.js +42 -68
- package/dist/esm/Select.js.map +2 -2
- package/dist/jsx/Select.js +28 -69
- package/package.json +10 -10
- package/types/Select.d.ts +209 -111
- package/types/Select.d.ts.map +1 -1
package/dist/jsx/Select.js
CHANGED
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
useTypeahead
|
|
19
19
|
} from "@floating-ui/react-dom-interactions";
|
|
20
20
|
import { usePrevious } from "@radix-ui/react-use-previous";
|
|
21
|
-
import { Button } from "@tamagui/button";
|
|
22
21
|
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
23
22
|
import {
|
|
24
23
|
getVariableValue,
|
|
@@ -28,6 +27,7 @@ import {
|
|
|
28
27
|
} from "@tamagui/core";
|
|
29
28
|
import { useId } from "@tamagui/core";
|
|
30
29
|
import { createContextScope } from "@tamagui/create-context";
|
|
30
|
+
import { ListItem } from "@tamagui/list-item";
|
|
31
31
|
import { Separator } from "@tamagui/separator";
|
|
32
32
|
import { ThemeableStack, XStack, YStack } from "@tamagui/stacks";
|
|
33
33
|
import { Paragraph } from "@tamagui/text";
|
|
@@ -69,7 +69,7 @@ const SelectTrigger = React.forwardRef((props, forwardedRef) => {
|
|
|
69
69
|
...triggerProps
|
|
70
70
|
} = props;
|
|
71
71
|
const context = useSelectContext(TRIGGER_NAME, __scopeSelect);
|
|
72
|
-
return <
|
|
72
|
+
return <ListItem backgrounded radiused hoverable pressable focusable tabIndex={-1} borderWidth={1} componentName={TRIGGER_NAME} aria-expanded={context.open} aria-autocomplete="none" disabled={disabled} data-disabled={disabled ? "" : void 0} {...triggerProps} ref={forwardedRef} {...context.interactions.getReferenceProps()} />;
|
|
73
73
|
});
|
|
74
74
|
SelectTrigger.displayName = TRIGGER_NAME;
|
|
75
75
|
const VALUE_NAME = "SelectValue";
|
|
@@ -102,6 +102,8 @@ const SelectViewportFrame = styled(ThemeableStack, {
|
|
|
102
102
|
name: VIEWPORT_NAME,
|
|
103
103
|
backgroundColor: "$background",
|
|
104
104
|
elevate: true,
|
|
105
|
+
overflow: "hidden",
|
|
106
|
+
userSelect: "none",
|
|
105
107
|
variants: {
|
|
106
108
|
size: {
|
|
107
109
|
"...size": (val, { tokens }) => {
|
|
@@ -131,26 +133,6 @@ const SelectViewport = React.forwardRef((props, forwardedRef) => {
|
|
|
131
133
|
SelectViewport.displayName = VIEWPORT_NAME;
|
|
132
134
|
const ITEM_NAME = "SelectItem";
|
|
133
135
|
const [SelectItemContextProvider, useSelectItemContext] = createSelectContext(ITEM_NAME);
|
|
134
|
-
const SelectItemFrame = styled(YStack, {
|
|
135
|
-
name: ITEM_NAME,
|
|
136
|
-
tag: "li",
|
|
137
|
-
role: "option",
|
|
138
|
-
width: "100%",
|
|
139
|
-
hoverStyle: {
|
|
140
|
-
backgroundColor: "$backgroundHover"
|
|
141
|
-
},
|
|
142
|
-
focusStyle: {
|
|
143
|
-
backgroundColor: "$backgroundFocus"
|
|
144
|
-
},
|
|
145
|
-
variants: {
|
|
146
|
-
size: {
|
|
147
|
-
"...size": getSelectItemSize
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
defaultVariants: {
|
|
151
|
-
size: "$4"
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
136
|
const SelectItem = React.forwardRef((props, forwardedRef) => {
|
|
155
137
|
const {
|
|
156
138
|
__scopeSelect,
|
|
@@ -174,18 +156,20 @@ const SelectItem = React.forwardRef((props, forwardedRef) => {
|
|
|
174
156
|
onChange,
|
|
175
157
|
activeIndex,
|
|
176
158
|
setActiveIndex,
|
|
159
|
+
setValueAtIndex,
|
|
177
160
|
dataRef
|
|
178
161
|
} = context;
|
|
179
162
|
const composedRefs = useComposedRefs(forwardedRef, (node) => {
|
|
180
|
-
console.log("node", node);
|
|
181
163
|
if (node instanceof HTMLElement) {
|
|
182
164
|
listRef.current[index] = node;
|
|
183
165
|
}
|
|
184
166
|
});
|
|
167
|
+
React.useEffect(() => {
|
|
168
|
+
setValueAtIndex(index, value);
|
|
169
|
+
}, [index]);
|
|
185
170
|
const timeoutRef = React.useRef();
|
|
186
171
|
const [allowMouseUp, setAllowMouseUp] = React.useState(false);
|
|
187
172
|
function handleSelect() {
|
|
188
|
-
console.log("handling select!");
|
|
189
173
|
setSelectedIndex(index);
|
|
190
174
|
onChange(value);
|
|
191
175
|
setOpen(false);
|
|
@@ -206,7 +190,6 @@ const SelectItem = React.forwardRef((props, forwardedRef) => {
|
|
|
206
190
|
}
|
|
207
191
|
}, [open, index, setActiveIndex, selectedIndex]);
|
|
208
192
|
function handleKeyDown(event) {
|
|
209
|
-
console.log("item key down");
|
|
210
193
|
if (event.key === "Enter" || event.key === " " && !dataRef.current.typing) {
|
|
211
194
|
event.preventDefault();
|
|
212
195
|
handleSelect();
|
|
@@ -219,7 +202,7 @@ const SelectItem = React.forwardRef((props, forwardedRef) => {
|
|
|
219
202
|
onKeyDown: handleKeyDown
|
|
220
203
|
});
|
|
221
204
|
return <SelectItemContextProvider scope={__scopeSelect} value={value} textId={textId || ""} isSelected={isSelected} onItemTextChange={React.useCallback((node) => {
|
|
222
|
-
}, [])}><
|
|
205
|
+
}, [])}><ListItem backgrounded hoverable pressable focusable componentName={ITEM_NAME} ref={composedRefs} aria-labelledby={textId} aria-selected={isSelected && isFocused} data-state={isSelected ? "active" : "inactive"} aria-disabled={disabled || void 0} data-disabled={disabled ? "" : void 0} tabIndex={disabled ? void 0 : -1} {...itemProps} {...selectItemProps} /></SelectItemContextProvider>;
|
|
223
206
|
});
|
|
224
207
|
SelectItem.displayName = ITEM_NAME;
|
|
225
208
|
const ITEM_TEXT_NAME = "SelectItemText";
|
|
@@ -262,27 +245,10 @@ const SelectGroup = React.forwardRef((props, forwardedRef) => {
|
|
|
262
245
|
});
|
|
263
246
|
SelectGroup.displayName = GROUP_NAME;
|
|
264
247
|
const LABEL_NAME = "SelectLabel";
|
|
265
|
-
const SelectLabelFrame = styled(SelectItemTextFrame, {
|
|
266
|
-
name: LABEL_NAME,
|
|
267
|
-
variants: {
|
|
268
|
-
size: {
|
|
269
|
-
"...size": (val, extras) => {
|
|
270
|
-
const size2 = getSelectItemSize(val, extras);
|
|
271
|
-
return {
|
|
272
|
-
...size2,
|
|
273
|
-
paddingTop: size2.paddingVertical * 4
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
},
|
|
278
|
-
defaultVariants: {
|
|
279
|
-
size: "$4"
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
248
|
const SelectLabel = React.forwardRef((props, forwardedRef) => {
|
|
283
249
|
const { __scopeSelect, ...labelProps } = props;
|
|
284
250
|
const groupContext = useSelectGroupContext(LABEL_NAME, __scopeSelect);
|
|
285
|
-
return <
|
|
251
|
+
return <ListItem componentName={LABEL_NAME} fontWeight="800" id={groupContext.id} {...labelProps} ref={forwardedRef} />;
|
|
286
252
|
});
|
|
287
253
|
SelectLabel.displayName = LABEL_NAME;
|
|
288
254
|
const SCROLL_UP_BUTTON_NAME = "SelectScrollUpButton";
|
|
@@ -352,7 +318,6 @@ const SelectSeparator = styled(Separator, {
|
|
|
352
318
|
name: "SelectSeparator"
|
|
353
319
|
});
|
|
354
320
|
const Select = withStaticProperties((props) => {
|
|
355
|
-
var _a;
|
|
356
321
|
const {
|
|
357
322
|
__scopeSelect,
|
|
358
323
|
children,
|
|
@@ -383,10 +348,7 @@ const Select = withStaticProperties((props) => {
|
|
|
383
348
|
const [showArrows, setShowArrows] = React.useState(false);
|
|
384
349
|
const [scrollTop, setScrollTop] = React.useState(0);
|
|
385
350
|
const listItemsRef = React.useRef([]);
|
|
386
|
-
const listContentRef = React.useRef([
|
|
387
|
-
"Select...",
|
|
388
|
-
...(_a = React.Children.map(children, (child) => React.Children.map(React.isValidElement(child) && child.props.children, (child2) => child2.props.value))) != null ? _a : []
|
|
389
|
-
]);
|
|
351
|
+
const listContentRef = React.useRef([]);
|
|
390
352
|
const [selectedIndex, setSelectedIndex] = React.useState(Math.max(0, listContentRef.current.indexOf(value)));
|
|
391
353
|
const [controlledScrolling, setControlledScrolling] = React.useState(false);
|
|
392
354
|
const [middlewareType, setMiddlewareType] = React.useState("align");
|
|
@@ -409,11 +371,11 @@ const Select = withStaticProperties((props) => {
|
|
|
409
371
|
};
|
|
410
372
|
}, [open]);
|
|
411
373
|
function getFloatingPadding(floating2) {
|
|
412
|
-
var
|
|
374
|
+
var _a;
|
|
413
375
|
if (!floating2) {
|
|
414
376
|
return 0;
|
|
415
377
|
}
|
|
416
|
-
return Number((
|
|
378
|
+
return Number((_a = getComputedStyle(floating2).paddingLeft) == null ? void 0 : _a.replace("px", ""));
|
|
417
379
|
}
|
|
418
380
|
__name(getFloatingPadding, "getFloatingPadding");
|
|
419
381
|
const { x, y, reference, floating, strategy, context, refs, middlewareData, update } = useFloating({
|
|
@@ -422,8 +384,8 @@ const Select = withStaticProperties((props) => {
|
|
|
422
384
|
placement: "bottom",
|
|
423
385
|
middleware: middlewareType === "align" ? [
|
|
424
386
|
offset(({ rects }) => {
|
|
425
|
-
var
|
|
426
|
-
const index = (
|
|
387
|
+
var _a;
|
|
388
|
+
const index = (_a = activeIndexRef.current) != null ? _a : selectedIndexRef.current;
|
|
427
389
|
if (index == null) {
|
|
428
390
|
return 0;
|
|
429
391
|
}
|
|
@@ -439,7 +401,7 @@ const Select = withStaticProperties((props) => {
|
|
|
439
401
|
{
|
|
440
402
|
name: "size",
|
|
441
403
|
async fn(args) {
|
|
442
|
-
var
|
|
404
|
+
var _a;
|
|
443
405
|
const {
|
|
444
406
|
elements: { floating: floating2 },
|
|
445
407
|
rects: { reference: reference2 },
|
|
@@ -451,7 +413,7 @@ const Select = withStaticProperties((props) => {
|
|
|
451
413
|
const top = Math.max(0, overflow.top);
|
|
452
414
|
const bottom = Math.max(0, overflow.bottom);
|
|
453
415
|
const nextY = args.y + top;
|
|
454
|
-
if ((
|
|
416
|
+
if ((_a = middlewareData2.size) == null ? void 0 : _a.skip) {
|
|
455
417
|
return {
|
|
456
418
|
y: nextY,
|
|
457
419
|
data: {
|
|
@@ -493,10 +455,6 @@ const Select = withStaticProperties((props) => {
|
|
|
493
455
|
const forceUpdate = React.useReducer(() => ({}), {})[1];
|
|
494
456
|
const showUpArrow = showArrows && scrollTop > SCROLL_ARROW_THRESHOLD;
|
|
495
457
|
const showDownArrow = showArrows && floatingRef.current && scrollTop < floatingRef.current.scrollHeight - floatingRef.current.clientHeight - SCROLL_ARROW_THRESHOLD;
|
|
496
|
-
console.log("Select", {
|
|
497
|
-
activeIndex,
|
|
498
|
-
selectedIndex
|
|
499
|
-
});
|
|
500
458
|
const interactions = useInteractions([
|
|
501
459
|
useClick(context, { pointerDown: true }),
|
|
502
460
|
useRole(context, { role: "listbox" }),
|
|
@@ -542,7 +500,7 @@ const Select = withStaticProperties((props) => {
|
|
|
542
500
|
}, [middlewareType]);
|
|
543
501
|
const touchPageYRef = React.useRef(null);
|
|
544
502
|
const handleWheel = React.useCallback((event) => {
|
|
545
|
-
var
|
|
503
|
+
var _a, _b;
|
|
546
504
|
const pinching = event.ctrlKey;
|
|
547
505
|
const currentTarget = event.currentTarget;
|
|
548
506
|
function isWheelEvent(event2) {
|
|
@@ -553,7 +511,7 @@ const Select = withStaticProperties((props) => {
|
|
|
553
511
|
return event2.touches != null;
|
|
554
512
|
}
|
|
555
513
|
__name(isTouchEvent, "isTouchEvent");
|
|
556
|
-
if (Math.abs(((
|
|
514
|
+
if (Math.abs(((_a = currentTarget == null ? void 0 : currentTarget.offsetHeight) != null ? _a : 0) - (visualViewport.height - WINDOW_PADDING * 2)) > 1 && !pinching) {
|
|
557
515
|
event.preventDefault();
|
|
558
516
|
} else if (isWheelEvent(event) && isFirefox) {
|
|
559
517
|
currentTarget.scrollTop += event.deltaY;
|
|
@@ -599,12 +557,12 @@ const Select = withStaticProperties((props) => {
|
|
|
599
557
|
};
|
|
600
558
|
}, [update]);
|
|
601
559
|
React.useLayoutEffect(() => {
|
|
602
|
-
var
|
|
560
|
+
var _a, _b, _c;
|
|
603
561
|
const floating2 = floatingRef.current;
|
|
604
562
|
if (open && controlledScrolling && floating2) {
|
|
605
563
|
const item = activeIndex != null ? listItemsRef.current[activeIndex] : selectedIndex != null ? listItemsRef.current[selectedIndex] : null;
|
|
606
564
|
if (item && prevActiveIndex != null) {
|
|
607
|
-
const itemHeight = (_b = (
|
|
565
|
+
const itemHeight = (_b = (_a = listItemsRef.current[prevActiveIndex]) == null ? void 0 : _a.offsetHeight) != null ? _b : 0;
|
|
608
566
|
const floatingHeight = floating2.offsetHeight;
|
|
609
567
|
const top = item.offsetTop;
|
|
610
568
|
const bottom = top + itemHeight;
|
|
@@ -633,7 +591,7 @@ const Select = withStaticProperties((props) => {
|
|
|
633
591
|
increaseHeight
|
|
634
592
|
]);
|
|
635
593
|
React.useLayoutEffect(() => {
|
|
636
|
-
var
|
|
594
|
+
var _a;
|
|
637
595
|
const floating2 = refs.floating.current;
|
|
638
596
|
const reference2 = refs.reference.current;
|
|
639
597
|
if (open && floating2 && reference2 && floating2.offsetHeight < floating2.scrollHeight) {
|
|
@@ -645,7 +603,7 @@ const Select = withStaticProperties((props) => {
|
|
|
645
603
|
}
|
|
646
604
|
return;
|
|
647
605
|
}
|
|
648
|
-
floating2.scrollTop = (
|
|
606
|
+
floating2.scrollTop = (_a = middlewareData.size) == null ? void 0 : _a.y;
|
|
649
607
|
const closeToBottom = visualViewport.height + getVisualOffsetTop() - referenceRect.bottom < FALLBACK_THRESHOLD;
|
|
650
608
|
const closeToTop = referenceRect.top < FALLBACK_THRESHOLD;
|
|
651
609
|
if (floating2.offsetHeight < MIN_HEIGHT || closeToTop || closeToBottom) {
|
|
@@ -662,11 +620,10 @@ const Select = withStaticProperties((props) => {
|
|
|
662
620
|
middlewareData
|
|
663
621
|
]);
|
|
664
622
|
React.useLayoutEffect(() => {
|
|
665
|
-
console.log("focusin", selectedIndex, listItemsRef.current[selectedIndex], listItemsRef.current);
|
|
666
623
|
if (open && selectedIndex != null) {
|
|
667
624
|
requestAnimationFrame(() => {
|
|
668
|
-
var
|
|
669
|
-
(
|
|
625
|
+
var _a;
|
|
626
|
+
(_a = listItemsRef.current[selectedIndex]) == null ? void 0 : _a.focus({ preventScroll: true });
|
|
670
627
|
});
|
|
671
628
|
}
|
|
672
629
|
}, [listItemsRef, selectedIndex, open]);
|
|
@@ -684,7 +641,9 @@ const Select = withStaticProperties((props) => {
|
|
|
684
641
|
}, [open]);
|
|
685
642
|
const [valueNode, setValueNode] = React.useState(null);
|
|
686
643
|
const [valueNodeHasChildren, setValueNodeHasChildren] = React.useState(false);
|
|
687
|
-
return <SelectProvider scope={__scopeSelect} increaseHeight={increaseHeight} forceUpdate={forceUpdate} floatingRef={floatingRef} valueNode={valueNode} onValueNodeChange={setValueNode} valueNodeHasChildren={valueNodeHasChildren} onValueNodeHasChildrenChange={setValueNodeHasChildren}
|
|
644
|
+
return <SelectProvider scope={__scopeSelect} increaseHeight={increaseHeight} forceUpdate={forceUpdate} floatingRef={floatingRef} valueNode={valueNode} onValueNodeChange={setValueNode} valueNodeHasChildren={valueNodeHasChildren} onValueNodeHasChildrenChange={setValueNodeHasChildren} setValueAtIndex={(index, value2) => {
|
|
645
|
+
listContentRef.current[index] = value2;
|
|
646
|
+
}} interactions={{
|
|
688
647
|
...interactions,
|
|
689
648
|
getReferenceProps() {
|
|
690
649
|
return interactions.getReferenceProps({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/select",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.49",
|
|
4
4
|
"sideEffects": true,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
"@floating-ui/react-native": "^0.7.0",
|
|
24
24
|
"@radix-ui/react-use-callback-ref": "^0.1.0",
|
|
25
25
|
"@radix-ui/react-use-previous": "^0.1.1",
|
|
26
|
-
"@tamagui/
|
|
27
|
-
"@tamagui/
|
|
28
|
-
"@tamagui/
|
|
29
|
-
"@tamagui/
|
|
30
|
-
"@tamagui/separator": "^1.0.1-beta.
|
|
31
|
-
"@tamagui/stacks": "^1.0.1-beta.
|
|
32
|
-
"@tamagui/text": "^1.0.1-beta.
|
|
33
|
-
"@tamagui/use-controllable-state": "^1.0.1-beta.
|
|
26
|
+
"@tamagui/compose-refs": "^1.0.1-beta.49",
|
|
27
|
+
"@tamagui/core": "^1.0.1-beta.49",
|
|
28
|
+
"@tamagui/create-context": "^1.0.1-beta.49",
|
|
29
|
+
"@tamagui/list-item": "^1.0.1-beta.49",
|
|
30
|
+
"@tamagui/separator": "^1.0.1-beta.49",
|
|
31
|
+
"@tamagui/stacks": "^1.0.1-beta.49",
|
|
32
|
+
"@tamagui/text": "^1.0.1-beta.49",
|
|
33
|
+
"@tamagui/use-controllable-state": "^1.0.1-beta.49"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": "*",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"react-native": "*"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@tamagui/build": "^1.0.1-beta.
|
|
41
|
+
"@tamagui/build": "^1.0.1-beta.49",
|
|
42
42
|
"@types/react-native": "^0.67.3",
|
|
43
43
|
"react": "*",
|
|
44
44
|
"react-dom": "*",
|