@tamagui/select 1.0.21 → 1.0.23
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 +5 -5
- package/dist/cjs/Select.js.map +2 -2
- package/dist/cjs/SelectImpl.js +56 -55
- package/dist/cjs/SelectImpl.js.map +2 -2
- package/dist/esm/Select.js +5 -5
- package/dist/esm/Select.js.map +2 -2
- package/dist/esm/SelectImpl.js +62 -56
- package/dist/esm/SelectImpl.js.map +2 -2
- package/dist/jsx/Select.js +5 -7
- package/dist/jsx/Select.js.map +2 -2
- package/dist/jsx/SelectImpl.js +62 -56
- package/dist/jsx/SelectImpl.js.map +2 -2
- package/package.json +18 -18
- package/src/Select.tsx +5 -8
- package/src/SelectImpl.tsx +68 -62
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/SelectImpl.tsx"],
|
|
4
|
-
"sourcesContent": ["import {\n SideObject,\n autoUpdate,\n flip,\n inner,\n offset,\n shift,\n size,\n useClick,\n useDismiss,\n useFloating,\n useInnerOffset,\n useInteractions,\n useListNavigation,\n useRole,\n useTypeahead,\n} from '@floating-ui/react-dom-interactions'\nimport { isWeb, useIsTouchDevice, useIsomorphicLayoutEffect } from '@tamagui/core'\nimport * as React from 'react'\nimport { flushSync } from 'react-dom'\n\nimport { SCROLL_ARROW_THRESHOLD, WINDOW_PADDING } from './constants'\nimport { SelectProvider, useSelectContext } from './context'\nimport { SelectImplProps } from './types'\n\n// TODO use id for focusing from label\nexport const SelectInlineImpl = (props: SelectImplProps) => {\n const {\n __scopeSelect,\n children,\n open = false,\n selectedIndexRef,\n listContentRef,\n } = props\n\n const selectContext = useSelectContext('SelectSheetImpl', __scopeSelect)\n const {\n setActiveIndex,\n setOpen,\n setSelectedIndex,\n selectedIndex,\n activeIndex,\n forceUpdate,\n } = selectContext\n const [scrollTop, setScrollTop] = React.useState(0)\n const touch = useIsTouchDevice()\n\n const listItemsRef = React.useRef<Array<HTMLElement | null>>([])\n const overflowRef = React.useRef<null | SideObject>(null)\n const upArrowRef = React.useRef<HTMLDivElement | null>(null)\n const downArrowRef = React.useRef<HTMLDivElement | null>(null)\n const allowSelectRef = React.useRef(false)\n const allowMouseUpRef = React.useRef(true)\n const selectTimeoutRef = React.useRef<any>()\n const state = React.useRef({\n isMouseOutside: false,\n })\n\n const [controlledScrolling, setControlledScrolling] = React.useState(false)\n const [fallback, setFallback] = React.useState(false)\n const [innerOffset, setInnerOffset] = React.useState(0)\n const [blockSelection, setBlockSelection] = React.useState(false)\n const floatingStyle = React.useRef({})\n\n // Wait for scroll position to settle before showing arrows to prevent\n // interference with pointer events.\n React.useEffect(() => {\n const frame = requestAnimationFrame(() => {\n if (!open) {\n setScrollTop(0)\n setFallback(false)\n setActiveIndex(null)\n setControlledScrolling(false)\n }\n })\n return () => {\n cancelAnimationFrame(frame)\n }\n }, [open, setActiveIndex])\n\n // close when mouseup outside select\n if (isWeb) {\n React.useEffect(() => {\n if (!open) return\n const mouseUp = (e: MouseEvent) => {\n if (state.current.isMouseOutside) {\n setOpen(false)\n }\n }\n document.addEventListener('mouseup', mouseUp)\n return () => {\n document.removeEventListener('mouseup', mouseUp)\n }\n }, [open])\n }\n\n const updateFloatingSize = size({\n apply({\n availableHeight,\n rects: {\n reference: { width },\n },\n }) {\n floatingStyle.current = {\n width: width,\n maxHeight: availableHeight,\n }\n },\n padding: WINDOW_PADDING,\n })\n\n const { x, y, reference, floating, strategy, context, refs } = useFloating({\n open,\n onOpenChange: setOpen,\n whileElementsMounted: autoUpdate,\n placement: 'bottom-start',\n middleware: fallback\n ? [\n offset(5),\n ...[\n touch\n ? shift({ crossAxis: true, padding: WINDOW_PADDING })\n : flip({ padding: WINDOW_PADDING }),\n ],\n updateFloatingSize,\n ]\n : [\n inner({\n listRef: listItemsRef,\n overflowRef,\n index: selectedIndex,\n offset: innerOffset,\n onFallbackChange: setFallback,\n padding: 10,\n minItemsVisible: touch ? 10 : 4,\n referenceOverflowThreshold: 20,\n }),\n updateFloatingSize,\n ],\n })\n\n const floatingRef = refs.floating\n\n const showUpArrow = open && scrollTop > SCROLL_ARROW_THRESHOLD\n const showDownArrow =\n open &&\n floatingRef.current &&\n scrollTop <\n floatingRef.current.scrollHeight -\n floatingRef.current.clientHeight -\n SCROLL_ARROW_THRESHOLD\n\n const interactions = useInteractions([\n useClick(context, { event: 'mousedown' }),\n useDismiss(context, { outsidePress: false }),\n useRole(context, { role: 'listbox' }),\n useInnerOffset(context, {\n enabled: !fallback,\n onChange: setInnerOffset,\n overflowRef,\n }),\n useListNavigation(context, {\n listRef: listItemsRef,\n activeIndex,\n selectedIndex,\n onNavigate: setActiveIndex,\n }),\n useTypeahead(context, {\n listRef: listContentRef,\n onMatch: open ? setActiveIndex : setSelectedIndex,\n selectedIndex,\n activeIndex,\n }),\n ])\n\n const interactionsContext = {\n ...interactions,\n getReferenceProps() {\n return interactions.getReferenceProps({\n ref: reference,\n className: 'SelectTrigger',\n onKeyDown(event) {\n if (\n event.key === 'Enter' ||\n (event.key === ' ' && !context.dataRef.current.typing)\n ) {\n event.preventDefault()\n setOpen(true)\n }\n },\n })\n },\n getFloatingProps(props) {\n return interactions.getFloatingProps({\n ref: floating,\n className: 'Select',\n ...props,\n style: {\n position: strategy,\n top: y ?? '',\n left: x ?? '',\n outline: 0,\n listStyleType: 'none',\n scrollbarWidth: 'none',\n ...floatingStyle.current,\n ...props?.style,\n },\n onPointerEnter() {\n setControlledScrolling(false)\n state.current.isMouseOutside = false\n },\n onPointerLeave() {\n state.current.isMouseOutside = true\n },\n onPointerMove() {\n state.current.isMouseOutside = false\n setControlledScrolling(false)\n },\n onKeyDown() {\n setControlledScrolling(true)\n },\n onContextMenu(e) {\n e.preventDefault()\n },\n onScroll(event) {\n // In React 18, the ScrollArrows need to synchronously know this value to prevent\n // painting at the wrong time.\n flushSync(() => setScrollTop(event.currentTarget.scrollTop))\n },\n })\n },\n }\n\n // effects\n\n useIsomorphicLayoutEffect(() => {\n if (open) {\n selectTimeoutRef.current = setTimeout(() => {\n allowSelectRef.current = true\n }, 300)\n\n return () => {\n clearTimeout(selectTimeoutRef.current)\n }\n } else {\n allowSelectRef.current = false\n allowMouseUpRef.current = true\n setInnerOffset(0)\n setFallback(false)\n setBlockSelection(false)\n }\n }, [open])\n\n // Replacement for `useDismiss` as the arrows are outside of the floating\n // element DOM tree.\n useIsomorphicLayoutEffect(() => {\n function onPointerDown(e: PointerEvent) {\n const target = e.target as Node\n if (\n !(\n refs.floating.current?.contains(target) ||\n upArrowRef.current?.contains(target) ||\n downArrowRef.current?.contains(target)\n )\n ) {\n setOpen(false)\n setControlledScrolling(false)\n }\n }\n\n if (open) {\n document.addEventListener('pointerdown', onPointerDown)\n return () => {\n document.removeEventListener('pointerdown', onPointerDown)\n }\n }\n }, [open, refs, setOpen])\n\n // Scroll the `activeIndex` item into view only in \"controlledScrolling\"\n // (keyboard nav) mode.\n useIsomorphicLayoutEffect(() => {\n if (open && controlledScrolling) {\n if (activeIndex != null) {\n listItemsRef.current[activeIndex]?.scrollIntoView({ block: 'nearest' })\n }\n }\n\n setScrollTop(refs.floating.current?.scrollTop ?? 0)\n }, [open, refs, controlledScrolling, activeIndex])\n\n // Scroll the `selectedIndex` into view upon opening the floating element.\n useIsomorphicLayoutEffect(() => {\n if (open && fallback) {\n if (selectedIndex != null) {\n listItemsRef.current[selectedIndex]?.scrollIntoView({ block: 'nearest' })\n }\n }\n }, [open, fallback, selectedIndex])\n\n // Unset the height limiting for fallback mode. This gets executed prior to\n // the positioning call.\n useIsomorphicLayoutEffect(() => {\n if (refs.floating.current && fallback) {\n refs.floating.current.style.maxHeight = ''\n }\n }, [refs, fallback])\n\n // We set this to true by default so that events bubble to forms without JS (SSR)\n // const isFormControl = trigger ? Boolean(trigger.closest('form')) : true\n // const [bubbleSelect, setBubbleSelect] = React.useState<HTMLSelectElement | null>(null)\n // const triggerPointerDownPosRef = React.useRef<{ x: number; y: number } | null>(null)\n\n return (\n <SelectProvider\n scope={__scopeSelect}\n {...(selectContext as Required<typeof selectContext>)}\n setScrollTop={setScrollTop}\n setInnerOffset={setInnerOffset}\n floatingRef={floatingRef}\n setValueAtIndex={(index, value) => {\n listContentRef.current[index] = value\n }}\n fallback={fallback}\n interactions={interactionsContext}\n floatingContext={context}\n activeIndex={activeIndex}\n canScrollDown={!!showDownArrow}\n canScrollUp={!!showUpArrow}\n controlledScrolling\n dataRef={context.dataRef}\n listRef={listItemsRef}\n blockSelection={blockSelection}\n allowMouseUpRef={allowMouseUpRef}\n upArrowRef={upArrowRef}\n downArrowRef={downArrowRef}\n selectTimeoutRef={selectTimeoutRef}\n allowSelectRef={allowSelectRef}\n >\n {children}\n {/* {isFormControl ? (\n <BubbleSelect\n ref={setBubbleSelect}\n aria-hidden\n tabIndex={-1}\n name={name}\n autoComplete={autoComplete}\n value={value}\n // enable form autofill\n onChange={(event) => setValue(event.target.value)}\n />\n ) : null} */}\n </SelectProvider>\n )\n}\n\n// Cross browser fixes for pinch-zooming/backdrop-filter \uD83D\uDE44\nconst userAgent = (typeof navigator !== 'undefined' && navigator.userAgent) || ''\n"],
|
|
5
|
-
"mappings": "AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,
|
|
4
|
+
"sourcesContent": ["import {\n SideObject,\n autoUpdate,\n flip,\n inner,\n offset,\n shift,\n size,\n useClick,\n useDismiss,\n useFloating,\n useInnerOffset,\n useInteractions,\n useListNavigation,\n useRole,\n useTypeahead,\n} from '@floating-ui/react-dom-interactions'\nimport {\n isClient,\n isWeb,\n useIsTouchDevice,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport * as React from 'react'\nimport { flushSync } from 'react-dom'\n\nimport { SCROLL_ARROW_THRESHOLD, WINDOW_PADDING } from './constants'\nimport { SelectProvider, useSelectContext } from './context'\nimport { SelectImplProps } from './types'\n\n// TODO use id for focusing from label\nexport const SelectInlineImpl = (props: SelectImplProps) => {\n const {\n __scopeSelect,\n children,\n open = false,\n selectedIndexRef,\n listContentRef,\n } = props\n\n const selectContext = useSelectContext('SelectSheetImpl', __scopeSelect)\n const {\n setActiveIndex,\n setOpen,\n setSelectedIndex,\n selectedIndex,\n activeIndex,\n forceUpdate,\n } = selectContext\n const [scrollTop, setScrollTop] = React.useState(0)\n const touch = useIsTouchDevice()\n\n const listItemsRef = React.useRef<Array<HTMLElement | null>>([])\n const overflowRef = React.useRef<null | SideObject>(null)\n const upArrowRef = React.useRef<HTMLDivElement | null>(null)\n const downArrowRef = React.useRef<HTMLDivElement | null>(null)\n const allowSelectRef = React.useRef(false)\n const allowMouseUpRef = React.useRef(true)\n const selectTimeoutRef = React.useRef<any>()\n const state = React.useRef({\n isMouseOutside: false,\n })\n\n const [controlledScrolling, setControlledScrolling] = React.useState(false)\n const [fallback, setFallback] = React.useState(false)\n const [innerOffset, setInnerOffset] = React.useState(0)\n const [blockSelection, setBlockSelection] = React.useState(false)\n const floatingStyle = React.useRef({})\n\n // Wait for scroll position to settle before showing arrows to prevent\n // interference with pointer events.\n React.useEffect(() => {\n const frame = requestAnimationFrame(() => {\n if (!open) {\n setScrollTop(0)\n setFallback(false)\n setActiveIndex(null)\n setControlledScrolling(false)\n }\n })\n return () => {\n cancelAnimationFrame(frame)\n }\n }, [open, setActiveIndex])\n\n // close when mouseup outside select\n if (isWeb && isClient) {\n React.useEffect(() => {\n if (!open) return\n const mouseUp = (e: MouseEvent) => {\n if (state.current.isMouseOutside) {\n setOpen(false)\n }\n }\n document.addEventListener('mouseup', mouseUp)\n return () => {\n document.removeEventListener('mouseup', mouseUp)\n }\n }, [open])\n }\n\n const updateFloatingSize = size({\n apply({\n availableHeight,\n rects: {\n reference: { width },\n },\n }) {\n floatingStyle.current = {\n width: width,\n maxHeight: availableHeight,\n }\n },\n padding: WINDOW_PADDING,\n })\n\n const { x, y, reference, floating, strategy, context, refs } = useFloating({\n open,\n onOpenChange: setOpen,\n whileElementsMounted: autoUpdate,\n placement: 'bottom-start',\n middleware: fallback\n ? [\n offset(5),\n ...[\n touch\n ? shift({ crossAxis: true, padding: WINDOW_PADDING })\n : flip({ padding: WINDOW_PADDING }),\n ],\n updateFloatingSize,\n ]\n : [\n inner({\n listRef: listItemsRef,\n overflowRef,\n index: selectedIndex,\n offset: innerOffset,\n onFallbackChange: setFallback,\n padding: 10,\n minItemsVisible: touch ? 10 : 4,\n referenceOverflowThreshold: 20,\n }),\n updateFloatingSize,\n ],\n })\n\n const floatingRef = refs.floating\n\n const showUpArrow = open && scrollTop > SCROLL_ARROW_THRESHOLD\n const showDownArrow =\n open &&\n floatingRef.current &&\n scrollTop <\n floatingRef.current.scrollHeight -\n floatingRef.current.clientHeight -\n SCROLL_ARROW_THRESHOLD\n\n const interactions = useInteractions([\n useClick(context, { pointerDown: true }),\n useDismiss(context, { outsidePointerDown: true }),\n useRole(context, { role: 'listbox' }),\n useInnerOffset(context, {\n enabled: !fallback,\n onChange: setInnerOffset,\n overflowRef,\n }),\n useListNavigation(context, {\n listRef: listItemsRef,\n activeIndex,\n selectedIndex,\n onNavigate: setActiveIndex,\n }),\n useTypeahead(context, {\n listRef: listContentRef,\n onMatch: open ? setActiveIndex : setSelectedIndex,\n selectedIndex,\n activeIndex,\n }),\n ])\n\n const interactionsContext = React.useMemo(() => {\n return {\n ...interactions,\n getReferenceProps() {\n return interactions.getReferenceProps({\n ref: reference,\n className: 'SelectTrigger',\n onKeyDown(event) {\n if (\n event.key === 'Enter' ||\n (event.key === ' ' && !context.dataRef.current.typing)\n ) {\n event.preventDefault()\n setOpen(true)\n }\n },\n })\n },\n getFloatingProps(props) {\n return interactions.getFloatingProps({\n ref: floating,\n className: 'Select',\n ...props,\n style: {\n position: strategy,\n top: y ?? '',\n left: x ?? '',\n outline: 0,\n scrollbarWidth: 'none',\n ...floatingStyle.current,\n ...props?.style,\n },\n onPointerEnter() {\n setControlledScrolling(false)\n state.current.isMouseOutside = false\n },\n onPointerLeave() {\n state.current.isMouseOutside = true\n },\n onPointerMove() {\n state.current.isMouseOutside = false\n setControlledScrolling(false)\n },\n onKeyDown() {\n setControlledScrolling(true)\n },\n onContextMenu(e) {\n e.preventDefault()\n },\n onScroll(event) {\n // In React 18, the ScrollArrows need to synchronously know this value to prevent\n // painting at the wrong time.\n flushSync(() => setScrollTop(event.currentTarget.scrollTop))\n },\n })\n },\n }\n }, [floating, y, x, interactions])\n\n // effects\n\n useIsomorphicLayoutEffect(() => {\n if (open) {\n selectTimeoutRef.current = setTimeout(() => {\n allowSelectRef.current = true\n }, 300)\n\n return () => {\n clearTimeout(selectTimeoutRef.current)\n }\n } else {\n allowSelectRef.current = false\n allowMouseUpRef.current = true\n setInnerOffset(0)\n setFallback(false)\n setBlockSelection(false)\n }\n }, [open])\n\n // Replacement for `useDismiss` as the arrows are outside of the floating\n // element DOM tree.\n useIsomorphicLayoutEffect(() => {\n function onPointerDown(e: PointerEvent) {\n const target = e.target as Node\n if (\n !(\n refs.floating.current?.contains(target) ||\n upArrowRef.current?.contains(target) ||\n downArrowRef.current?.contains(target)\n )\n ) {\n setOpen(false)\n setControlledScrolling(false)\n }\n }\n\n if (open) {\n document.addEventListener('pointerdown', onPointerDown)\n return () => {\n document.removeEventListener('pointerdown', onPointerDown)\n }\n }\n }, [open, refs, setOpen])\n\n // Scroll the `activeIndex` item into view only in \"controlledScrolling\"\n // (keyboard nav) mode.\n useIsomorphicLayoutEffect(() => {\n if (open && controlledScrolling) {\n if (activeIndex != null) {\n listItemsRef.current[activeIndex]?.scrollIntoView({ block: 'nearest' })\n }\n }\n\n setScrollTop(refs.floating.current?.scrollTop ?? 0)\n }, [open, refs, controlledScrolling, activeIndex])\n\n // Scroll the `selectedIndex` into view upon opening the floating element.\n useIsomorphicLayoutEffect(() => {\n if (open && fallback) {\n if (selectedIndex != null) {\n listItemsRef.current[selectedIndex]?.scrollIntoView({ block: 'nearest' })\n }\n }\n }, [open, fallback, selectedIndex])\n\n // Unset the height limiting for fallback mode. This gets executed prior to\n // the positioning call.\n useIsomorphicLayoutEffect(() => {\n if (refs.floating.current && fallback) {\n refs.floating.current.style.maxHeight = ''\n }\n }, [refs, fallback])\n\n // We set this to true by default so that events bubble to forms without JS (SSR)\n // const isFormControl = trigger ? Boolean(trigger.closest('form')) : true\n // const [bubbleSelect, setBubbleSelect] = React.useState<HTMLSelectElement | null>(null)\n // const triggerPointerDownPosRef = React.useRef<{ x: number; y: number } | null>(null)\n\n return (\n <SelectProvider\n scope={__scopeSelect}\n {...(selectContext as Required<typeof selectContext>)}\n setScrollTop={setScrollTop}\n setInnerOffset={setInnerOffset}\n floatingRef={floatingRef}\n setValueAtIndex={(index, value) => {\n listContentRef.current[index] = value\n }}\n fallback={fallback}\n interactions={interactionsContext}\n floatingContext={context}\n activeIndex={activeIndex}\n canScrollDown={!!showDownArrow}\n canScrollUp={!!showUpArrow}\n controlledScrolling={controlledScrolling}\n dataRef={context.dataRef}\n listRef={listItemsRef}\n blockSelection={blockSelection}\n allowMouseUpRef={allowMouseUpRef}\n upArrowRef={upArrowRef}\n downArrowRef={downArrowRef}\n selectTimeoutRef={selectTimeoutRef}\n allowSelectRef={allowSelectRef}\n >\n {children}\n {/* {isFormControl ? (\n <BubbleSelect\n ref={setBubbleSelect}\n aria-hidden\n tabIndex={-1}\n name={name}\n autoComplete={autoComplete}\n value={value}\n // enable form autofill\n onChange={(event) => setValue(event.target.value)}\n />\n ) : null} */}\n </SelectProvider>\n )\n}\n\n// Cross browser fixes for pinch-zooming/backdrop-filter \uD83D\uDE44\nconst userAgent = (typeof navigator !== 'undefined' && navigator.userAgent) || ''\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAA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["props"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/select",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.23",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -23,23 +23,23 @@
|
|
|
23
23
|
"lint:fix": "../../node_modules/.bin/rome check --apply-suggested src"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@floating-ui/react-dom": "
|
|
27
|
-
"@floating-ui/react-dom-interactions": "
|
|
28
|
-
"@floating-ui/react-native": "
|
|
26
|
+
"@floating-ui/react-dom": "1.0.0",
|
|
27
|
+
"@floating-ui/react-dom-interactions": "0.8.1",
|
|
28
|
+
"@floating-ui/react-native": "0.8.0",
|
|
29
29
|
"@radix-ui/react-use-previous": "^0.1.1",
|
|
30
|
-
"@tamagui/adapt": "^1.0.
|
|
31
|
-
"@tamagui/compose-refs": "^1.0.
|
|
32
|
-
"@tamagui/core": "^1.0.
|
|
33
|
-
"@tamagui/create-context": "^1.0.
|
|
34
|
-
"@tamagui/dismissable": "^1.0.
|
|
35
|
-
"@tamagui/focus-scope": "^1.0.
|
|
36
|
-
"@tamagui/list-item": "^1.0.
|
|
37
|
-
"@tamagui/portal": "^1.0.
|
|
38
|
-
"@tamagui/separator": "^1.0.
|
|
39
|
-
"@tamagui/stacks": "^1.0.
|
|
40
|
-
"@tamagui/text": "^1.0.
|
|
41
|
-
"@tamagui/use-controllable-state": "^1.0.
|
|
42
|
-
"@tamagui/use-event": "^1.0.
|
|
30
|
+
"@tamagui/adapt": "^1.0.23",
|
|
31
|
+
"@tamagui/compose-refs": "^1.0.23",
|
|
32
|
+
"@tamagui/core": "^1.0.23",
|
|
33
|
+
"@tamagui/create-context": "^1.0.23",
|
|
34
|
+
"@tamagui/dismissable": "^1.0.23",
|
|
35
|
+
"@tamagui/focus-scope": "^1.0.23",
|
|
36
|
+
"@tamagui/list-item": "^1.0.23",
|
|
37
|
+
"@tamagui/portal": "^1.0.23",
|
|
38
|
+
"@tamagui/separator": "^1.0.23",
|
|
39
|
+
"@tamagui/stacks": "^1.0.23",
|
|
40
|
+
"@tamagui/text": "^1.0.23",
|
|
41
|
+
"@tamagui/use-controllable-state": "^1.0.23",
|
|
42
|
+
"@tamagui/use-event": "^1.0.23"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"react": "*",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"react-native": "*"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@tamagui/build": "^1.0.
|
|
50
|
+
"@tamagui/build": "^1.0.23",
|
|
51
51
|
"react": "^18.2.0",
|
|
52
52
|
"react-dom": "^18.2.0",
|
|
53
53
|
"react-native": "*"
|
package/src/Select.tsx
CHANGED
|
@@ -275,6 +275,7 @@ export const SelectItem = React.forwardRef<TamaguiElement, SelectItemProps>(
|
|
|
275
275
|
isSelected={isSelected}
|
|
276
276
|
>
|
|
277
277
|
<ListItem
|
|
278
|
+
tag="div"
|
|
278
279
|
backgrounded
|
|
279
280
|
pressTheme
|
|
280
281
|
cursor=""
|
|
@@ -336,7 +337,7 @@ const SelectItemText = React.forwardRef<TamaguiElement, SelectItemTextProps>(
|
|
|
336
337
|
)
|
|
337
338
|
|
|
338
339
|
// until portals work in sub-trees on RN, use this just for native:
|
|
339
|
-
|
|
340
|
+
useIsomorphicLayoutEffect(() => {
|
|
340
341
|
if (isSelected) {
|
|
341
342
|
context.setSelectedItem(contents)
|
|
342
343
|
}
|
|
@@ -445,6 +446,7 @@ const SelectLabel = React.forwardRef<TamaguiElement, SelectLabelProps>(
|
|
|
445
446
|
const groupContext = useSelectGroupContext(LABEL_NAME, __scopeSelect)
|
|
446
447
|
return (
|
|
447
448
|
<ListItem
|
|
449
|
+
tag="div"
|
|
448
450
|
componentName={LABEL_NAME}
|
|
449
451
|
fontWeight="800"
|
|
450
452
|
id={groupContext.id}
|
|
@@ -545,16 +547,11 @@ export const Select = withStaticProperties(
|
|
|
545
547
|
transition: true,
|
|
546
548
|
})
|
|
547
549
|
|
|
548
|
-
const [activeIndex, setActiveIndex] = React.useState<number | null>(
|
|
550
|
+
const [activeIndex, setActiveIndex] = React.useState<number | null>(0)
|
|
549
551
|
const selectedIndexRef = React.useRef<number | null>(null)
|
|
550
552
|
const activeIndexRef = React.useRef<number | null>(null)
|
|
551
|
-
|
|
552
553
|
const listContentRef = React.useRef<string[]>([])
|
|
553
|
-
|
|
554
|
-
const [selectedIndex, setSelectedIndex] = React.useState(
|
|
555
|
-
Math.max(0, listContentRef.current.indexOf(value))
|
|
556
|
-
)
|
|
557
|
-
|
|
554
|
+
const [selectedIndex, setSelectedIndex] = React.useState(0)
|
|
558
555
|
const [valueNode, setValueNode] = React.useState<HTMLElement | null>(null)
|
|
559
556
|
const [valueNodeHasChildren, setValueNodeHasChildren] = React.useState(false)
|
|
560
557
|
|
package/src/SelectImpl.tsx
CHANGED
|
@@ -15,7 +15,12 @@ import {
|
|
|
15
15
|
useRole,
|
|
16
16
|
useTypeahead,
|
|
17
17
|
} from '@floating-ui/react-dom-interactions'
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
isClient,
|
|
20
|
+
isWeb,
|
|
21
|
+
useIsTouchDevice,
|
|
22
|
+
useIsomorphicLayoutEffect,
|
|
23
|
+
} from '@tamagui/core'
|
|
19
24
|
import * as React from 'react'
|
|
20
25
|
import { flushSync } from 'react-dom'
|
|
21
26
|
|
|
@@ -79,7 +84,7 @@ export const SelectInlineImpl = (props: SelectImplProps) => {
|
|
|
79
84
|
}, [open, setActiveIndex])
|
|
80
85
|
|
|
81
86
|
// close when mouseup outside select
|
|
82
|
-
if (isWeb) {
|
|
87
|
+
if (isWeb && isClient) {
|
|
83
88
|
React.useEffect(() => {
|
|
84
89
|
if (!open) return
|
|
85
90
|
const mouseUp = (e: MouseEvent) => {
|
|
@@ -151,8 +156,8 @@ export const SelectInlineImpl = (props: SelectImplProps) => {
|
|
|
151
156
|
SCROLL_ARROW_THRESHOLD
|
|
152
157
|
|
|
153
158
|
const interactions = useInteractions([
|
|
154
|
-
useClick(context, {
|
|
155
|
-
useDismiss(context, {
|
|
159
|
+
useClick(context, { pointerDown: true }),
|
|
160
|
+
useDismiss(context, { outsidePointerDown: true }),
|
|
156
161
|
useRole(context, { role: 'listbox' }),
|
|
157
162
|
useInnerOffset(context, {
|
|
158
163
|
enabled: !fallback,
|
|
@@ -173,63 +178,64 @@ export const SelectInlineImpl = (props: SelectImplProps) => {
|
|
|
173
178
|
}),
|
|
174
179
|
])
|
|
175
180
|
|
|
176
|
-
const interactionsContext = {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
181
|
+
const interactionsContext = React.useMemo(() => {
|
|
182
|
+
return {
|
|
183
|
+
...interactions,
|
|
184
|
+
getReferenceProps() {
|
|
185
|
+
return interactions.getReferenceProps({
|
|
186
|
+
ref: reference,
|
|
187
|
+
className: 'SelectTrigger',
|
|
188
|
+
onKeyDown(event) {
|
|
189
|
+
if (
|
|
190
|
+
event.key === 'Enter' ||
|
|
191
|
+
(event.key === ' ' && !context.dataRef.current.typing)
|
|
192
|
+
) {
|
|
193
|
+
event.preventDefault()
|
|
194
|
+
setOpen(true)
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
})
|
|
198
|
+
},
|
|
199
|
+
getFloatingProps(props) {
|
|
200
|
+
return interactions.getFloatingProps({
|
|
201
|
+
ref: floating,
|
|
202
|
+
className: 'Select',
|
|
203
|
+
...props,
|
|
204
|
+
style: {
|
|
205
|
+
position: strategy,
|
|
206
|
+
top: y ?? '',
|
|
207
|
+
left: x ?? '',
|
|
208
|
+
outline: 0,
|
|
209
|
+
scrollbarWidth: 'none',
|
|
210
|
+
...floatingStyle.current,
|
|
211
|
+
...props?.style,
|
|
212
|
+
},
|
|
213
|
+
onPointerEnter() {
|
|
214
|
+
setControlledScrolling(false)
|
|
215
|
+
state.current.isMouseOutside = false
|
|
216
|
+
},
|
|
217
|
+
onPointerLeave() {
|
|
218
|
+
state.current.isMouseOutside = true
|
|
219
|
+
},
|
|
220
|
+
onPointerMove() {
|
|
221
|
+
state.current.isMouseOutside = false
|
|
222
|
+
setControlledScrolling(false)
|
|
223
|
+
},
|
|
224
|
+
onKeyDown() {
|
|
225
|
+
setControlledScrolling(true)
|
|
226
|
+
},
|
|
227
|
+
onContextMenu(e) {
|
|
228
|
+
e.preventDefault()
|
|
229
|
+
},
|
|
230
|
+
onScroll(event) {
|
|
231
|
+
// In React 18, the ScrollArrows need to synchronously know this value to prevent
|
|
232
|
+
// painting at the wrong time.
|
|
233
|
+
flushSync(() => setScrollTop(event.currentTarget.scrollTop))
|
|
234
|
+
},
|
|
235
|
+
})
|
|
236
|
+
},
|
|
237
|
+
}
|
|
238
|
+
}, [floating, y, x, interactions])
|
|
233
239
|
|
|
234
240
|
// effects
|
|
235
241
|
|
|
@@ -326,7 +332,7 @@ export const SelectInlineImpl = (props: SelectImplProps) => {
|
|
|
326
332
|
activeIndex={activeIndex}
|
|
327
333
|
canScrollDown={!!showDownArrow}
|
|
328
334
|
canScrollUp={!!showUpArrow}
|
|
329
|
-
controlledScrolling
|
|
335
|
+
controlledScrolling={controlledScrolling}
|
|
330
336
|
dataRef={context.dataRef}
|
|
331
337
|
listRef={listItemsRef}
|
|
332
338
|
blockSelection={blockSelection}
|