@tamagui/select 1.115.4 → 1.116.0
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.cjs +117 -122
- package/dist/cjs/Select.cjs.map +2 -2
- package/dist/cjs/Select.native.js +100 -101
- package/dist/cjs/Select.native.js.map +2 -2
- package/dist/cjs/SelectViewport.cjs +4 -6
- package/dist/cjs/SelectViewport.cjs.map +1 -1
- package/dist/cjs/SelectViewport.native.cjs +8 -22
- package/dist/cjs/SelectViewport.native.cjs.map +1 -1
- package/dist/cjs/SelectViewport.native.js +7 -16
- package/dist/cjs/SelectViewport.native.js.map +2 -2
- package/dist/cjs/useSelectBreakpointActive.cjs +5 -10
- package/dist/cjs/useSelectBreakpointActive.cjs.map +1 -1
- package/dist/cjs/useSelectBreakpointActive.native.js +2 -7
- package/dist/cjs/useSelectBreakpointActive.native.js.map +2 -2
- package/dist/esm/Select.js +110 -118
- package/dist/esm/Select.js.map +1 -1
- package/dist/esm/Select.mjs +118 -123
- package/dist/esm/Select.mjs.map +1 -1
- package/dist/esm/Select.native.js +103 -106
- package/dist/esm/Select.native.js.map +2 -2
- package/dist/esm/SelectViewport.js +5 -6
- package/dist/esm/SelectViewport.js.map +1 -1
- package/dist/esm/SelectViewport.mjs +4 -6
- package/dist/esm/SelectViewport.mjs.map +1 -1
- package/dist/esm/SelectViewport.native.js +5 -8
- package/dist/esm/SelectViewport.native.js.map +2 -2
- package/dist/esm/useSelectBreakpointActive.js +3 -7
- package/dist/esm/useSelectBreakpointActive.js.map +1 -1
- package/dist/esm/useSelectBreakpointActive.mjs +6 -10
- package/dist/esm/useSelectBreakpointActive.mjs.map +1 -1
- package/dist/esm/useSelectBreakpointActive.native.js +3 -7
- package/dist/esm/useSelectBreakpointActive.native.js.map +2 -2
- package/dist/jsx/Select.js +110 -118
- package/dist/jsx/Select.js.map +1 -1
- package/dist/jsx/Select.mjs +118 -123
- package/dist/jsx/Select.mjs.map +1 -1
- package/dist/jsx/Select.native.js +103 -106
- package/dist/jsx/Select.native.js.map +2 -2
- package/dist/jsx/SelectViewport.js +5 -6
- package/dist/jsx/SelectViewport.js.map +1 -1
- package/dist/jsx/SelectViewport.mjs +4 -6
- package/dist/jsx/SelectViewport.mjs.map +1 -1
- package/dist/jsx/SelectViewport.native.js +5 -8
- package/dist/jsx/SelectViewport.native.js.map +2 -2
- package/dist/jsx/useSelectBreakpointActive.js +3 -7
- package/dist/jsx/useSelectBreakpointActive.js.map +1 -1
- package/dist/jsx/useSelectBreakpointActive.mjs +6 -10
- package/dist/jsx/useSelectBreakpointActive.mjs.map +1 -1
- package/dist/jsx/useSelectBreakpointActive.native.js +3 -7
- package/dist/jsx/useSelectBreakpointActive.native.js.map +2 -2
- package/package.json +23 -23
- package/src/Select.tsx +174 -186
- package/src/SelectViewport.native.tsx +7 -10
- package/src/SelectViewport.tsx +7 -9
- package/src/types.tsx +0 -1
- package/src/useSelectBreakpointActive.tsx +2 -12
- package/types/Select.d.ts +5 -3
- package/types/Select.d.ts.map +1 -1
- package/types/SelectViewport.d.ts.map +1 -1
- package/types/SelectViewport.native.d.ts.map +1 -1
- package/types/types.d.ts +0 -1
- package/types/types.d.ts.map +1 -1
- package/types/useSelectBreakpointActive.d.ts +0 -1
- package/types/useSelectBreakpointActive.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/select",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.116.0",
|
|
4
4
|
"removeSideEffects": "true",
|
|
5
5
|
"source": "src/index.tsx",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -35,33 +35,33 @@
|
|
|
35
35
|
"@floating-ui/react": "^0.26.24",
|
|
36
36
|
"@floating-ui/react-dom": "^2.1.2",
|
|
37
37
|
"@floating-ui/react-native": "^0.10.6",
|
|
38
|
-
"@tamagui/adapt": "1.
|
|
39
|
-
"@tamagui/animate-presence": "1.
|
|
40
|
-
"@tamagui/compose-refs": "1.
|
|
41
|
-
"@tamagui/constants": "1.
|
|
42
|
-
"@tamagui/core": "1.
|
|
43
|
-
"@tamagui/create-context": "1.
|
|
44
|
-
"@tamagui/dismissable": "1.
|
|
45
|
-
"@tamagui/focus-scope": "1.
|
|
46
|
-
"@tamagui/get-token": "1.
|
|
47
|
-
"@tamagui/helpers": "1.
|
|
48
|
-
"@tamagui/list-item": "1.
|
|
49
|
-
"@tamagui/portal": "1.
|
|
50
|
-
"@tamagui/remove-scroll": "1.
|
|
51
|
-
"@tamagui/separator": "1.
|
|
52
|
-
"@tamagui/sheet": "1.
|
|
53
|
-
"@tamagui/stacks": "1.
|
|
54
|
-
"@tamagui/text": "1.
|
|
55
|
-
"@tamagui/use-controllable-state": "1.
|
|
56
|
-
"@tamagui/use-debounce": "1.
|
|
57
|
-
"@tamagui/use-event": "1.
|
|
58
|
-
"@tamagui/use-previous": "1.
|
|
38
|
+
"@tamagui/adapt": "1.116.0",
|
|
39
|
+
"@tamagui/animate-presence": "1.116.0",
|
|
40
|
+
"@tamagui/compose-refs": "1.116.0",
|
|
41
|
+
"@tamagui/constants": "1.116.0",
|
|
42
|
+
"@tamagui/core": "1.116.0",
|
|
43
|
+
"@tamagui/create-context": "1.116.0",
|
|
44
|
+
"@tamagui/dismissable": "1.116.0",
|
|
45
|
+
"@tamagui/focus-scope": "1.116.0",
|
|
46
|
+
"@tamagui/get-token": "1.116.0",
|
|
47
|
+
"@tamagui/helpers": "1.116.0",
|
|
48
|
+
"@tamagui/list-item": "1.116.0",
|
|
49
|
+
"@tamagui/portal": "1.116.0",
|
|
50
|
+
"@tamagui/remove-scroll": "1.116.0",
|
|
51
|
+
"@tamagui/separator": "1.116.0",
|
|
52
|
+
"@tamagui/sheet": "1.116.0",
|
|
53
|
+
"@tamagui/stacks": "1.116.0",
|
|
54
|
+
"@tamagui/text": "1.116.0",
|
|
55
|
+
"@tamagui/use-controllable-state": "1.116.0",
|
|
56
|
+
"@tamagui/use-debounce": "1.116.0",
|
|
57
|
+
"@tamagui/use-event": "1.116.0",
|
|
58
|
+
"@tamagui/use-previous": "1.116.0"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"react": "*"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@tamagui/build": "1.
|
|
64
|
+
"@tamagui/build": "1.116.0",
|
|
65
65
|
"react": "^18.2.0 || ^19.0.0",
|
|
66
66
|
"react-dom": "^18.2.0 || ^19.0.0",
|
|
67
67
|
"react-native": "0.74.1"
|
package/src/Select.tsx
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import { Adapt,
|
|
1
|
+
import { Adapt, AdaptParent, useAdaptIsActive } from '@tamagui/adapt'
|
|
2
2
|
import { useComposedRefs } from '@tamagui/compose-refs'
|
|
3
3
|
import { isWeb, useIsomorphicLayoutEffect } from '@tamagui/constants'
|
|
4
4
|
import type { FontSizeTokens, GetProps, TamaguiElement } from '@tamagui/core'
|
|
5
5
|
import { getVariableValue, styled, useEvent, useGet } from '@tamagui/core'
|
|
6
|
+
import { registerFocusable } from '@tamagui/focusable'
|
|
6
7
|
import { getSpace } from '@tamagui/get-token'
|
|
7
8
|
import { withStaticProperties } from '@tamagui/helpers'
|
|
8
9
|
import type { ListItemProps } from '@tamagui/list-item'
|
|
9
10
|
import { ListItem } from '@tamagui/list-item'
|
|
10
|
-
import { PortalHost } from '@tamagui/portal'
|
|
11
11
|
import { Separator } from '@tamagui/separator'
|
|
12
|
-
import { registerFocusable } from '@tamagui/focusable'
|
|
13
12
|
import { Sheet, SheetController } from '@tamagui/sheet'
|
|
14
13
|
import { ThemeableStack, XStack, YStack } from '@tamagui/stacks'
|
|
15
14
|
import { Paragraph, SizableText } from '@tamagui/text'
|
|
16
15
|
import { useControllableState } from '@tamagui/use-controllable-state'
|
|
17
|
-
import * as React from 'react'
|
|
18
16
|
import { useDebounce } from '@tamagui/use-debounce'
|
|
19
|
-
|
|
20
|
-
import { SELECT_NAME } from './constants'
|
|
17
|
+
import * as React from 'react'
|
|
21
18
|
import {
|
|
22
19
|
SelectItemParentProvider,
|
|
23
20
|
SelectProvider,
|
|
@@ -32,11 +29,8 @@ import { ITEM_TEXT_NAME, SelectItemText } from './SelectItemText'
|
|
|
32
29
|
import { SelectScrollDownButton, SelectScrollUpButton } from './SelectScrollButton'
|
|
33
30
|
import { SelectTrigger } from './SelectTrigger'
|
|
34
31
|
import { SelectViewport } from './SelectViewport'
|
|
35
|
-
import type {
|
|
36
|
-
import {
|
|
37
|
-
useSelectBreakpointActive,
|
|
38
|
-
useShowSelectSheet,
|
|
39
|
-
} from './useSelectBreakpointActive'
|
|
32
|
+
import type { SelectImplProps, SelectProps, SelectScopedProps } from './types'
|
|
33
|
+
import { useShowSelectSheet } from './useSelectBreakpointActive'
|
|
40
34
|
|
|
41
35
|
/* -------------------------------------------------------------------------------------------------
|
|
42
36
|
* SelectValue
|
|
@@ -314,7 +308,7 @@ const SelectSheetController = (
|
|
|
314
308
|
) => {
|
|
315
309
|
const context = useSelectContext('SelectSheetController', props.__scopeSelect)
|
|
316
310
|
const showSheet = useShowSelectSheet(context)
|
|
317
|
-
const
|
|
311
|
+
const isAdapted = useAdaptIsActive()
|
|
318
312
|
const getShowSheet = useGet(showSheet)
|
|
319
313
|
|
|
320
314
|
return (
|
|
@@ -325,7 +319,7 @@ const SelectSheetController = (
|
|
|
325
319
|
}
|
|
326
320
|
}}
|
|
327
321
|
open={context.open}
|
|
328
|
-
hidden={
|
|
322
|
+
hidden={isAdapted === false}
|
|
329
323
|
>
|
|
330
324
|
{props.children}
|
|
331
325
|
</SheetController>
|
|
@@ -341,181 +335,16 @@ const SelectSheetImpl = (props: SelectImplProps) => {
|
|
|
341
335
|
* -----------------------------------------------------------------------------------------------*/
|
|
342
336
|
|
|
343
337
|
export const Select = withStaticProperties(
|
|
344
|
-
(props: SelectScopedProps<SelectProps>)
|
|
345
|
-
const {
|
|
346
|
-
__scopeSelect,
|
|
347
|
-
native,
|
|
348
|
-
children,
|
|
349
|
-
open: openProp,
|
|
350
|
-
defaultOpen,
|
|
351
|
-
onOpenChange,
|
|
352
|
-
value: valueProp,
|
|
353
|
-
defaultValue,
|
|
354
|
-
onValueChange,
|
|
355
|
-
disablePreventBodyScroll,
|
|
356
|
-
size: sizeProp = '$true',
|
|
357
|
-
onActiveChange,
|
|
358
|
-
dir,
|
|
359
|
-
id,
|
|
360
|
-
} = props
|
|
361
|
-
|
|
338
|
+
function Select(props: SelectScopedProps<SelectProps>) {
|
|
362
339
|
const internalId = React.useId()
|
|
363
|
-
const scopeKey = __scopeSelect
|
|
364
|
-
? (Object.keys(__scopeSelect)[0] ?? internalId)
|
|
340
|
+
const scopeKey = props.__scopeSelect
|
|
341
|
+
? (Object.keys(props.__scopeSelect)[0] ?? internalId)
|
|
365
342
|
: internalId
|
|
366
343
|
|
|
367
|
-
const { when, AdaptProvider } = useAdaptParent({
|
|
368
|
-
Contents: React.useCallback(
|
|
369
|
-
() => <PortalHost name={`${scopeKey}SheetContents`} />,
|
|
370
|
-
[scopeKey]
|
|
371
|
-
),
|
|
372
|
-
})
|
|
373
|
-
|
|
374
|
-
const sheetBreakpoint = when
|
|
375
|
-
const isSheet = useSelectBreakpointActive(sheetBreakpoint)
|
|
376
|
-
const SelectImpl = isSheet || !isWeb ? SelectSheetImpl : SelectInlineImpl
|
|
377
|
-
const forceUpdate = React.useReducer(() => ({}), {})[1]
|
|
378
|
-
const [selectedItem, setSelectedItem] = React.useState<React.ReactNode>(null)
|
|
379
|
-
|
|
380
|
-
const [open, setOpen] = useControllableState({
|
|
381
|
-
prop: openProp,
|
|
382
|
-
defaultProp: defaultOpen || false,
|
|
383
|
-
onChange: onOpenChange,
|
|
384
|
-
})
|
|
385
|
-
|
|
386
|
-
const [value, setValue] = useControllableState({
|
|
387
|
-
prop: valueProp,
|
|
388
|
-
defaultProp: defaultValue || '',
|
|
389
|
-
onChange: onValueChange,
|
|
390
|
-
transition: true,
|
|
391
|
-
})
|
|
392
|
-
|
|
393
|
-
React.useEffect(() => {
|
|
394
|
-
if (open) {
|
|
395
|
-
emitValue(value)
|
|
396
|
-
}
|
|
397
|
-
}, [open])
|
|
398
|
-
|
|
399
|
-
React.useEffect(() => {
|
|
400
|
-
emitValue(value)
|
|
401
|
-
}, [value])
|
|
402
|
-
|
|
403
|
-
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
404
|
-
React.useEffect(() => {
|
|
405
|
-
if (!props.id) return
|
|
406
|
-
|
|
407
|
-
return registerFocusable(props.id, {
|
|
408
|
-
focusAndSelect: () => {
|
|
409
|
-
setOpen?.((value) => !value)
|
|
410
|
-
},
|
|
411
|
-
focus: () => {},
|
|
412
|
-
})
|
|
413
|
-
}, [props.id])
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
const [activeIndex, setActiveIndex] = React.useState<number | null>(0)
|
|
417
|
-
|
|
418
|
-
const [emitValue, valueSubscribe] = useEmitter<any>()
|
|
419
|
-
const [emitActiveIndex, activeIndexSubscribe] = useEmitter<number>()
|
|
420
|
-
|
|
421
|
-
const selectedIndexRef = React.useRef<number | null>(null)
|
|
422
|
-
const activeIndexRef = React.useRef<number | null>(null)
|
|
423
|
-
const listContentRef = React.useRef<string[]>([])
|
|
424
|
-
const [selectedIndex, setSelectedIndex] = React.useState(0)
|
|
425
|
-
const [valueNode, setValueNode] = React.useState<HTMLElement | null>(null)
|
|
426
|
-
|
|
427
|
-
useIsomorphicLayoutEffect(() => {
|
|
428
|
-
selectedIndexRef.current = selectedIndex
|
|
429
|
-
activeIndexRef.current = activeIndex
|
|
430
|
-
})
|
|
431
|
-
|
|
432
|
-
const shouldRenderWebNative =
|
|
433
|
-
isWeb &&
|
|
434
|
-
(native === true ||
|
|
435
|
-
native === 'web' ||
|
|
436
|
-
(Array.isArray(native) && native.includes('web')))
|
|
437
|
-
|
|
438
|
-
// TODO its calling this a bunch if you move mouse around on select items fast
|
|
439
|
-
// using a debounce for now but need to fix root issue
|
|
440
|
-
const setActiveIndexDebounced = useDebounce(
|
|
441
|
-
(index: number | null) => {
|
|
442
|
-
setActiveIndex((prev) => {
|
|
443
|
-
if (prev !== index) {
|
|
444
|
-
if (typeof index === 'number') {
|
|
445
|
-
emitActiveIndex(index)
|
|
446
|
-
}
|
|
447
|
-
return index
|
|
448
|
-
}
|
|
449
|
-
return prev
|
|
450
|
-
})
|
|
451
|
-
},
|
|
452
|
-
1,
|
|
453
|
-
{},
|
|
454
|
-
[]
|
|
455
|
-
)
|
|
456
|
-
|
|
457
344
|
return (
|
|
458
|
-
<
|
|
459
|
-
<
|
|
460
|
-
|
|
461
|
-
initialValue={React.useMemo(() => value, [open])}
|
|
462
|
-
size={sizeProp}
|
|
463
|
-
activeIndexSubscribe={activeIndexSubscribe}
|
|
464
|
-
valueSubscribe={valueSubscribe}
|
|
465
|
-
setOpen={setOpen}
|
|
466
|
-
id={id}
|
|
467
|
-
onChange={React.useCallback((val) => {
|
|
468
|
-
setValue(val)
|
|
469
|
-
emitValue(val)
|
|
470
|
-
}, [])}
|
|
471
|
-
onActiveChange={useEvent((...args) => {
|
|
472
|
-
onActiveChange?.(...args)
|
|
473
|
-
})}
|
|
474
|
-
setSelectedIndex={setSelectedIndex}
|
|
475
|
-
setValueAtIndex={React.useCallback((index, value) => {
|
|
476
|
-
listContentRef.current[index] = value
|
|
477
|
-
}, [])}
|
|
478
|
-
shouldRenderWebNative={shouldRenderWebNative}
|
|
479
|
-
>
|
|
480
|
-
<SelectProvider
|
|
481
|
-
scope={__scopeSelect}
|
|
482
|
-
disablePreventBodyScroll={disablePreventBodyScroll}
|
|
483
|
-
dir={dir}
|
|
484
|
-
blockSelection={false}
|
|
485
|
-
fallback={false}
|
|
486
|
-
selectedItem={selectedItem}
|
|
487
|
-
setSelectedItem={setSelectedItem}
|
|
488
|
-
forceUpdate={forceUpdate}
|
|
489
|
-
valueNode={valueNode}
|
|
490
|
-
onValueNodeChange={setValueNode}
|
|
491
|
-
scopeKey={scopeKey}
|
|
492
|
-
sheetBreakpoint={sheetBreakpoint}
|
|
493
|
-
activeIndex={activeIndex}
|
|
494
|
-
selectedIndex={selectedIndex}
|
|
495
|
-
setActiveIndex={setActiveIndexDebounced}
|
|
496
|
-
value={value}
|
|
497
|
-
open={open}
|
|
498
|
-
native={native}
|
|
499
|
-
>
|
|
500
|
-
<SelectSheetController onOpenChange={setOpen} __scopeSelect={__scopeSelect}>
|
|
501
|
-
{shouldRenderWebNative ? (
|
|
502
|
-
children
|
|
503
|
-
) : (
|
|
504
|
-
<SelectImpl
|
|
505
|
-
activeIndexRef={activeIndexRef}
|
|
506
|
-
listContentRef={listContentRef}
|
|
507
|
-
selectedIndexRef={selectedIndexRef}
|
|
508
|
-
{...props}
|
|
509
|
-
open={open}
|
|
510
|
-
value={value}
|
|
511
|
-
>
|
|
512
|
-
{children}
|
|
513
|
-
</SelectImpl>
|
|
514
|
-
)}
|
|
515
|
-
</SelectSheetController>
|
|
516
|
-
</SelectProvider>
|
|
517
|
-
</SelectItemParentProvider>
|
|
518
|
-
</AdaptProvider>
|
|
345
|
+
<AdaptParent scope={`${scopeKey}SheetContents`} portal>
|
|
346
|
+
<SelectInner scopeKey={scopeKey} {...props} />
|
|
347
|
+
</AdaptParent>
|
|
519
348
|
)
|
|
520
349
|
},
|
|
521
350
|
{
|
|
@@ -553,5 +382,164 @@ function useEmitter<A>() {
|
|
|
553
382
|
return [emit, subscribe] as const
|
|
554
383
|
}
|
|
555
384
|
|
|
556
|
-
|
|
557
|
-
|
|
385
|
+
function SelectInner(props: SelectScopedProps<SelectProps> & { scopeKey: string }) {
|
|
386
|
+
const {
|
|
387
|
+
__scopeSelect,
|
|
388
|
+
native,
|
|
389
|
+
children,
|
|
390
|
+
open: openProp,
|
|
391
|
+
defaultOpen,
|
|
392
|
+
onOpenChange,
|
|
393
|
+
value: valueProp,
|
|
394
|
+
defaultValue,
|
|
395
|
+
onValueChange,
|
|
396
|
+
disablePreventBodyScroll,
|
|
397
|
+
size: sizeProp = '$true',
|
|
398
|
+
onActiveChange,
|
|
399
|
+
dir,
|
|
400
|
+
id,
|
|
401
|
+
} = props
|
|
402
|
+
|
|
403
|
+
const isAdapted = useAdaptIsActive()
|
|
404
|
+
const SelectImpl = isAdapted || !isWeb ? SelectSheetImpl : SelectInlineImpl
|
|
405
|
+
const forceUpdate = React.useReducer(() => ({}), {})[1]
|
|
406
|
+
const [selectedItem, setSelectedItem] = React.useState<React.ReactNode>(null)
|
|
407
|
+
|
|
408
|
+
const [open, setOpen] = useControllableState({
|
|
409
|
+
prop: openProp,
|
|
410
|
+
defaultProp: defaultOpen || false,
|
|
411
|
+
onChange: onOpenChange,
|
|
412
|
+
})
|
|
413
|
+
|
|
414
|
+
const [value, setValue] = useControllableState({
|
|
415
|
+
prop: valueProp,
|
|
416
|
+
defaultProp: defaultValue || '',
|
|
417
|
+
onChange: onValueChange,
|
|
418
|
+
transition: true,
|
|
419
|
+
})
|
|
420
|
+
|
|
421
|
+
React.useEffect(() => {
|
|
422
|
+
if (open) {
|
|
423
|
+
emitValue(value)
|
|
424
|
+
}
|
|
425
|
+
}, [open])
|
|
426
|
+
|
|
427
|
+
React.useEffect(() => {
|
|
428
|
+
emitValue(value)
|
|
429
|
+
}, [value])
|
|
430
|
+
|
|
431
|
+
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
432
|
+
React.useEffect(() => {
|
|
433
|
+
if (!props.id) return
|
|
434
|
+
|
|
435
|
+
return registerFocusable(props.id, {
|
|
436
|
+
focusAndSelect: () => {
|
|
437
|
+
setOpen?.((value) => !value)
|
|
438
|
+
},
|
|
439
|
+
focus: () => {},
|
|
440
|
+
})
|
|
441
|
+
}, [props.id])
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
const [activeIndex, setActiveIndex] = React.useState<number | null>(0)
|
|
445
|
+
|
|
446
|
+
const [emitValue, valueSubscribe] = useEmitter<any>()
|
|
447
|
+
const [emitActiveIndex, activeIndexSubscribe] = useEmitter<number>()
|
|
448
|
+
|
|
449
|
+
const selectedIndexRef = React.useRef<number | null>(null)
|
|
450
|
+
const activeIndexRef = React.useRef<number | null>(null)
|
|
451
|
+
const listContentRef = React.useRef<string[]>([])
|
|
452
|
+
const [selectedIndex, setSelectedIndex] = React.useState(0)
|
|
453
|
+
const [valueNode, setValueNode] = React.useState<HTMLElement | null>(null)
|
|
454
|
+
|
|
455
|
+
useIsomorphicLayoutEffect(() => {
|
|
456
|
+
selectedIndexRef.current = selectedIndex
|
|
457
|
+
activeIndexRef.current = activeIndex
|
|
458
|
+
})
|
|
459
|
+
|
|
460
|
+
const shouldRenderWebNative =
|
|
461
|
+
isWeb &&
|
|
462
|
+
(native === true ||
|
|
463
|
+
native === 'web' ||
|
|
464
|
+
(Array.isArray(native) && native.includes('web')))
|
|
465
|
+
|
|
466
|
+
// TODO its calling this a bunch if you move mouse around on select items fast
|
|
467
|
+
// using a debounce for now but need to fix root issue
|
|
468
|
+
const setActiveIndexDebounced = useDebounce(
|
|
469
|
+
(index: number | null) => {
|
|
470
|
+
setActiveIndex((prev) => {
|
|
471
|
+
if (prev !== index) {
|
|
472
|
+
if (typeof index === 'number') {
|
|
473
|
+
emitActiveIndex(index)
|
|
474
|
+
}
|
|
475
|
+
return index
|
|
476
|
+
}
|
|
477
|
+
return prev
|
|
478
|
+
})
|
|
479
|
+
},
|
|
480
|
+
1,
|
|
481
|
+
{},
|
|
482
|
+
[]
|
|
483
|
+
)
|
|
484
|
+
|
|
485
|
+
return (
|
|
486
|
+
<SelectItemParentProvider
|
|
487
|
+
scope={__scopeSelect}
|
|
488
|
+
initialValue={React.useMemo(() => value, [open])}
|
|
489
|
+
size={sizeProp}
|
|
490
|
+
activeIndexSubscribe={activeIndexSubscribe}
|
|
491
|
+
valueSubscribe={valueSubscribe}
|
|
492
|
+
setOpen={setOpen}
|
|
493
|
+
id={id}
|
|
494
|
+
onChange={React.useCallback((val) => {
|
|
495
|
+
setValue(val)
|
|
496
|
+
emitValue(val)
|
|
497
|
+
}, [])}
|
|
498
|
+
onActiveChange={useEvent((...args) => {
|
|
499
|
+
onActiveChange?.(...args)
|
|
500
|
+
})}
|
|
501
|
+
setSelectedIndex={setSelectedIndex}
|
|
502
|
+
setValueAtIndex={React.useCallback((index, value) => {
|
|
503
|
+
listContentRef.current[index] = value
|
|
504
|
+
}, [])}
|
|
505
|
+
shouldRenderWebNative={shouldRenderWebNative}
|
|
506
|
+
>
|
|
507
|
+
<SelectProvider
|
|
508
|
+
scope={__scopeSelect}
|
|
509
|
+
disablePreventBodyScroll={disablePreventBodyScroll}
|
|
510
|
+
dir={dir}
|
|
511
|
+
blockSelection={false}
|
|
512
|
+
fallback={false}
|
|
513
|
+
selectedItem={selectedItem}
|
|
514
|
+
setSelectedItem={setSelectedItem}
|
|
515
|
+
forceUpdate={forceUpdate}
|
|
516
|
+
valueNode={valueNode}
|
|
517
|
+
onValueNodeChange={setValueNode}
|
|
518
|
+
scopeKey={props.scopeKey}
|
|
519
|
+
activeIndex={activeIndex}
|
|
520
|
+
selectedIndex={selectedIndex}
|
|
521
|
+
setActiveIndex={setActiveIndexDebounced}
|
|
522
|
+
value={value}
|
|
523
|
+
open={open}
|
|
524
|
+
native={native}
|
|
525
|
+
>
|
|
526
|
+
<SelectSheetController onOpenChange={setOpen} __scopeSelect={__scopeSelect}>
|
|
527
|
+
{shouldRenderWebNative ? (
|
|
528
|
+
children
|
|
529
|
+
) : (
|
|
530
|
+
<SelectImpl
|
|
531
|
+
activeIndexRef={activeIndexRef}
|
|
532
|
+
listContentRef={listContentRef}
|
|
533
|
+
selectedIndexRef={selectedIndexRef}
|
|
534
|
+
{...props}
|
|
535
|
+
open={open}
|
|
536
|
+
value={value}
|
|
537
|
+
>
|
|
538
|
+
{children}
|
|
539
|
+
</SelectImpl>
|
|
540
|
+
)}
|
|
541
|
+
</SelectSheetController>
|
|
542
|
+
</SelectProvider>
|
|
543
|
+
</SelectItemParentProvider>
|
|
544
|
+
)
|
|
545
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AdaptContext, AdaptPortalContents, useAdaptContext } from '@tamagui/adapt'
|
|
2
2
|
import { Theme, useThemeName } from '@tamagui/core'
|
|
3
|
-
import { PortalItem } from '@tamagui/portal'
|
|
4
|
-
import * as React from 'react'
|
|
5
3
|
|
|
6
4
|
import { VIEWPORT_NAME } from './constants'
|
|
7
5
|
import {
|
|
@@ -16,23 +14,22 @@ export const SelectViewport = (props: SelectScopedProps<SelectViewportProps>) =>
|
|
|
16
14
|
const context = useSelectContext(VIEWPORT_NAME, __scopeSelect)
|
|
17
15
|
const itemParentContext = useSelectItemParentContext(VIEWPORT_NAME, __scopeSelect)
|
|
18
16
|
const themeName = useThemeName()
|
|
19
|
-
const adaptContext = React.useContext(AdaptParentContext)
|
|
20
17
|
|
|
21
|
-
//
|
|
18
|
+
// re-propogate context...
|
|
19
|
+
const adaptContext = useAdaptContext()
|
|
20
|
+
|
|
22
21
|
return (
|
|
23
|
-
<
|
|
22
|
+
<AdaptPortalContents>
|
|
24
23
|
<Theme name={themeName}>
|
|
25
24
|
<ForwardSelectContext
|
|
26
25
|
__scopeSelect={__scopeSelect}
|
|
27
26
|
itemContext={itemParentContext}
|
|
28
27
|
context={context}
|
|
29
28
|
>
|
|
30
|
-
<
|
|
31
|
-
{children}
|
|
32
|
-
</AdaptParentContext.Provider>
|
|
29
|
+
<AdaptContext.Provider {...adaptContext}>{children}</AdaptContext.Provider>
|
|
33
30
|
</ForwardSelectContext>
|
|
34
31
|
</Theme>
|
|
35
|
-
</
|
|
32
|
+
</AdaptPortalContents>
|
|
36
33
|
)
|
|
37
34
|
}
|
|
38
35
|
|
package/src/SelectViewport.tsx
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { FloatingFocusManager } from '@floating-ui/react'
|
|
2
|
+
import { AdaptPortalContents, useAdaptIsActive } from '@tamagui/adapt'
|
|
2
3
|
import { AnimatePresence } from '@tamagui/animate-presence'
|
|
3
4
|
import { composeRefs } from '@tamagui/compose-refs'
|
|
4
5
|
import { isWeb, useIsomorphicLayoutEffect } from '@tamagui/constants'
|
|
5
|
-
import {
|
|
6
|
-
import { PortalItem } from '@tamagui/portal'
|
|
6
|
+
import { styled } from '@tamagui/core'
|
|
7
7
|
import { ThemeableStack } from '@tamagui/stacks'
|
|
8
|
-
|
|
9
8
|
import { VIEWPORT_NAME } from './constants'
|
|
10
9
|
import {
|
|
11
10
|
ForwardSelectContext,
|
|
@@ -17,7 +16,6 @@ import type {
|
|
|
17
16
|
SelectViewportExtraProps,
|
|
18
17
|
SelectViewportProps,
|
|
19
18
|
} from './types'
|
|
20
|
-
import { useSelectBreakpointActive } from './useSelectBreakpointActive'
|
|
21
19
|
|
|
22
20
|
/* -------------------------------------------------------------------------------------------------
|
|
23
21
|
* SelectViewport
|
|
@@ -57,21 +55,21 @@ export const SelectViewport = SelectViewportFrame.styleable<SelectViewportExtraP
|
|
|
57
55
|
const { __scopeSelect, children, disableScroll, ...viewportProps } = props
|
|
58
56
|
const context = useSelectContext(VIEWPORT_NAME, __scopeSelect)
|
|
59
57
|
const itemContext = useSelectItemParentContext(VIEWPORT_NAME, __scopeSelect)
|
|
60
|
-
const
|
|
58
|
+
const isAdapted = useAdaptIsActive()
|
|
61
59
|
|
|
62
60
|
useIsomorphicLayoutEffect(() => {
|
|
63
61
|
if (context.update) {
|
|
64
62
|
context.update()
|
|
65
63
|
}
|
|
66
|
-
}, [
|
|
64
|
+
}, [isAdapted])
|
|
67
65
|
|
|
68
66
|
if (itemContext.shouldRenderWebNative) {
|
|
69
67
|
return <>{children}</>
|
|
70
68
|
}
|
|
71
69
|
|
|
72
|
-
if (
|
|
70
|
+
if (isAdapted || !isWeb) {
|
|
73
71
|
return (
|
|
74
|
-
<
|
|
72
|
+
<AdaptPortalContents>
|
|
75
73
|
<ForwardSelectContext
|
|
76
74
|
__scopeSelect={__scopeSelect}
|
|
77
75
|
itemContext={itemContext}
|
|
@@ -79,7 +77,7 @@ export const SelectViewport = SelectViewportFrame.styleable<SelectViewportExtraP
|
|
|
79
77
|
>
|
|
80
78
|
{children}
|
|
81
79
|
</ForwardSelectContext>
|
|
82
|
-
</
|
|
80
|
+
</AdaptPortalContents>
|
|
83
81
|
)
|
|
84
82
|
}
|
|
85
83
|
|
package/src/types.tsx
CHANGED
|
@@ -73,7 +73,6 @@ export interface SelectItemParentContextValue {
|
|
|
73
73
|
export interface SelectContextValue {
|
|
74
74
|
dir?: SelectDirection
|
|
75
75
|
scopeKey: string
|
|
76
|
-
sheetBreakpoint: string | boolean | null
|
|
77
76
|
value: any
|
|
78
77
|
selectedItem: ReactNode
|
|
79
78
|
setSelectedItem: (item: ReactNode) => void
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { useAdaptIsActive } from '@tamagui/adapt'
|
|
3
2
|
import type { SelectContextValue } from './types'
|
|
4
3
|
|
|
5
|
-
export const useSelectBreakpointActive = (
|
|
6
|
-
sheetBreakpoint: SelectContextValue['sheetBreakpoint']
|
|
7
|
-
) => {
|
|
8
|
-
const media = useMedia()
|
|
9
|
-
if (!sheetBreakpoint) return false
|
|
10
|
-
if (sheetBreakpoint === true) return true
|
|
11
|
-
return sheetBreakpoint ? media[sheetBreakpoint] : false
|
|
12
|
-
}
|
|
13
|
-
|
|
14
4
|
export const useShowSelectSheet = (context: SelectContextValue) => {
|
|
15
|
-
const breakpointActive =
|
|
5
|
+
const breakpointActive = useAdaptIsActive()
|
|
16
6
|
return context.open === false ? false : breakpointActive
|
|
17
7
|
}
|
package/types/Select.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FontSizeTokens, TamaguiElement } from '@tamagui/core';
|
|
2
2
|
import type { ListItemProps } from '@tamagui/list-item';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import type {
|
|
4
|
+
import type { SelectProps, SelectScopedProps } from './types';
|
|
5
5
|
export interface SelectValueExtraProps {
|
|
6
6
|
placeholder?: React.ReactNode;
|
|
7
7
|
}
|
|
@@ -30,9 +30,11 @@ export declare const SelectSeparator: import("@tamagui/core").TamaguiComponent<i
|
|
|
30
30
|
vertical?: boolean | undefined;
|
|
31
31
|
}, import("@tamagui/core").StaticConfigPublic>;
|
|
32
32
|
export declare const Select: ((props: SelectScopedProps<SelectProps>) => import("react/jsx-runtime").JSX.Element) & {
|
|
33
|
-
Adapt: ((
|
|
33
|
+
Adapt: ((props: import("@tamagui/adapt").AdaptProps) => import("react/jsx-runtime").JSX.Element) & {
|
|
34
34
|
Contents: {
|
|
35
|
-
(
|
|
35
|
+
({ scope, ...rest }: {
|
|
36
|
+
scope?: string;
|
|
37
|
+
}): React.FunctionComponentElement<any>;
|
|
36
38
|
shouldForwardSpace: boolean;
|
|
37
39
|
};
|
|
38
40
|
};
|
package/types/Select.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../src/Select.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAY,cAAc,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../src/Select.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAY,cAAc,EAAE,MAAM,eAAe,CAAA;AAK7E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAQvD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAe9B,OAAO,KAAK,EAAmB,WAAW,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAc9E,MAAM,WAAW,qBAAqB;IACpC,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC9B;AA0DD,eAAO,MAAM,UAAU;;;;;;;;;8CAKrB,CAAA;AA2CF,eAAO,MAAM,gBAAgB;;;;;;;;;8CAG3B,CAAA;AA8GF,MAAM,MAAM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":"
|
|
1
|
+
{"version":3,"file":"SelectViewport.d.ts","sourceRoot":"","sources":["../src/SelectViewport.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAEV,wBAAwB,EAEzB,MAAM,SAAS,CAAA;AAMhB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;8CA2B9B,CAAA;AAEF,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8CAsF1B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectViewport.native.d.ts","sourceRoot":"","sources":["../src/SelectViewport.native.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SelectViewport.native.d.ts","sourceRoot":"","sources":["../src/SelectViewport.native.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAErE,eAAO,MAAM,cAAc;YAAW,iBAAiB,CAAC,mBAAmB,CAAC;;CAsB3E,CAAA"}
|
package/types/types.d.ts
CHANGED
|
@@ -66,7 +66,6 @@ export interface SelectItemParentContextValue {
|
|
|
66
66
|
export interface SelectContextValue {
|
|
67
67
|
dir?: SelectDirection;
|
|
68
68
|
scopeKey: string;
|
|
69
|
-
sheetBreakpoint: string | boolean | null;
|
|
70
69
|
value: any;
|
|
71
70
|
selectedItem: ReactNode;
|
|
72
71
|
setSelectedItem: (item: ReactNode) => void;
|