@tamagui/popover 1.75.9 → 1.76.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/src/Popover.tsx CHANGED
@@ -43,7 +43,6 @@ import { Sheet, SheetController } from '@tamagui/sheet'
43
43
  import { YStack, YStackProps } from '@tamagui/stacks'
44
44
  import { useControllableState } from '@tamagui/use-controllable-state'
45
45
  import * as React from 'react'
46
- import { Freeze } from 'react-freeze'
47
46
  import { Platform, ScrollView } from 'react-native'
48
47
 
49
48
  import { useFloatingContext } from './useFloatingContext'
@@ -55,6 +54,16 @@ export type PopoverProps = PopperProps & {
55
54
  defaultOpen?: boolean
56
55
  onOpenChange?: (open: boolean) => void
57
56
  keepChildrenMounted?: boolean
57
+
58
+ /**
59
+ * Enable staying open while mouseover
60
+ */
61
+ hoverable?: boolean
62
+
63
+ /**
64
+ * Disable focusing behavior on open
65
+ */
66
+ disableFocus?: boolean
58
67
  }
59
68
 
60
69
  type ScopedPopoverProps<P> = ScopedProps<P, 'Popover'>
@@ -409,54 +418,30 @@ const PopoverContentImpl = React.forwardRef<
409
418
  setIsFullyHidden(true)
410
419
  }}
411
420
  >
412
- <FreezeToLastContents
413
- // freeze if fully hidden but fallback to last contents
414
- // if keepChildrenMounted then mount it on the first
415
- freeze={freeze}
421
+ <PopperContent
422
+ __scopePopper={__scopePopover || POPOVER_SCOPE}
423
+ key={context.contentId}
424
+ data-state={getState(open)}
425
+ id={context.contentId}
426
+ ref={forwardedRef}
427
+ {...contentProps}
416
428
  >
417
- <PopperContent
418
- __scopePopper={__scopePopover || POPOVER_SCOPE}
419
- key={context.contentId}
420
- data-state={getState(open)}
421
- id={context.contentId}
422
- ref={forwardedRef}
423
- {...contentProps}
429
+ <RemoveScroll
430
+ enabled={disableRemoveScroll ? false : open}
431
+ allowPinchZoom
432
+ // causes lots of bugs on touch web on site
433
+ removeScrollBar={false}
434
+ style={{
435
+ display: 'contents',
436
+ }}
424
437
  >
425
- <RemoveScroll
426
- enabled={disableRemoveScroll ? false : open}
427
- allowPinchZoom
428
- // causes lots of bugs on touch web on site
429
- removeScrollBar={false}
430
- style={{
431
- display: 'contents',
432
- }}
433
- >
434
- <FocusScope
435
- loop
436
- enabled={disableFocusScope ? false : open}
437
- trapped={trapFocus}
438
- onMountAutoFocus={onOpenAutoFocus}
439
- onUnmountAutoFocus={onCloseAutoFocus}
440
- >
441
- {contents}
442
- </FocusScope>
443
- </RemoveScroll>
444
- </PopperContent>
445
- </FreezeToLastContents>
438
+ {contents}
439
+ </RemoveScroll>
440
+ </PopperContent>
446
441
  </Animate>
447
442
  )
448
443
  })
449
444
 
450
- const FreezeToLastContents = (props: { freeze: boolean; children: any }) => {
451
- const last = React.useRef()
452
-
453
- if (!props.freeze) {
454
- last.current = props.children
455
- }
456
-
457
- return <Freeze placeholder={last.current} {...props} />
458
- }
459
-
460
445
  /* -------------------------------------------------------------------------------------------------
461
446
  * PopoverClose
462
447
  * -----------------------------------------------------------------------------------------------*/
@@ -515,6 +500,8 @@ export const Popover = withStaticProperties(
515
500
  onOpenChange,
516
501
  __scopePopover,
517
502
  keepChildrenMounted,
503
+ hoverable,
504
+ disableFocus,
518
505
  ...restProps
519
506
  } = props
520
507
 
@@ -534,9 +521,15 @@ export const Popover = withStaticProperties(
534
521
  onChange: onOpenChange,
535
522
  })
536
523
 
537
- const breakpointActive = useSheetBreakpointActive(sheetBreakpoint)
524
+ const sheetActive = useSheetBreakpointActive(sheetBreakpoint)
538
525
 
539
- const floatingContext = useFloatingContext({ open, setOpen, breakpointActive }) as any
526
+ const floatingContext = useFloatingContext({
527
+ open,
528
+ setOpen,
529
+ disable: sheetActive,
530
+ hoverable,
531
+ disableFocus: disableFocus,
532
+ }) as any
540
533
 
541
534
  const popoverContext = {
542
535
  id,
@@ -544,10 +537,10 @@ export const Popover = withStaticProperties(
544
537
  contentId: React.useId(),
545
538
  triggerRef,
546
539
  open,
547
- breakpointActive,
540
+ breakpointActive: sheetActive,
548
541
  onOpenChange: setOpen,
549
542
  onOpenToggle: useEvent(() => {
550
- if (open && breakpointActive) {
543
+ if (open && sheetActive) {
551
544
  return
552
545
  }
553
546
  setOpen(!open)
@@ -1,10 +1,24 @@
1
1
  import type { UseFloatingOptions } from '@floating-ui/react'
2
- import { useDismiss, useFloating, useInteractions, useRole } from '@floating-ui/react'
2
+ import {
3
+ safePolygon,
4
+ useDismiss,
5
+ useFloating,
6
+ useFocus,
7
+ useHover,
8
+ useInteractions,
9
+ useRole,
10
+ } from '@floating-ui/react'
3
11
  import { useCallback } from 'react'
4
12
 
5
13
  // Custom floating context to override the Popper on web
6
- export const useFloatingContext = ({ open, setOpen, breakpointActive }) =>
7
- useCallback(
14
+ export const useFloatingContext = ({
15
+ open,
16
+ setOpen,
17
+ disable,
18
+ disableFocus,
19
+ hoverable,
20
+ }) => {
21
+ return useCallback(
8
22
  (props: UseFloatingOptions) => {
9
23
  const floating = useFloating({
10
24
  ...props,
@@ -12,13 +26,24 @@ export const useFloatingContext = ({ open, setOpen, breakpointActive }) =>
12
26
  onOpenChange: setOpen,
13
27
  }) as any
14
28
  const { getReferenceProps, getFloatingProps } = useInteractions([
15
- // useFocus(floating.context, {
16
- // enabled: !breakpointActive,
17
- // keyboardOnly: true,
18
- // }),
29
+ hoverable
30
+ ? useHover(floating.context, {
31
+ enabled: !disable && hoverable,
32
+ handleClose: safePolygon({
33
+ requireIntent: true,
34
+ blockPointerEvents: true,
35
+ }),
36
+ })
37
+ : useHover(floating.context, {
38
+ enabled: false,
39
+ }),
40
+ useFocus(floating.context, {
41
+ enabled: !disable && !disableFocus,
42
+ keyboardOnly: true,
43
+ }),
19
44
  useRole(floating.context, { role: 'dialog' }),
20
45
  useDismiss(floating.context, {
21
- enabled: !breakpointActive,
46
+ enabled: !disable,
22
47
  }),
23
48
  ])
24
49
  return {
@@ -28,5 +53,6 @@ export const useFloatingContext = ({ open, setOpen, breakpointActive }) =>
28
53
  getFloatingProps,
29
54
  }
30
55
  },
31
- [open, setOpen, breakpointActive]
56
+ [open, setOpen, disable, disableFocus, hoverable]
32
57
  )
58
+ }
@@ -12,6 +12,14 @@ export type PopoverProps = PopperProps & {
12
12
  defaultOpen?: boolean;
13
13
  onOpenChange?: (open: boolean) => void;
14
14
  keepChildrenMounted?: boolean;
15
+ /**
16
+ * Enable staying open while mouseover
17
+ */
18
+ hoverable?: boolean;
19
+ /**
20
+ * Disable focusing behavior on open
21
+ */
22
+ disableFocus?: boolean;
15
23
  };
16
24
  type ScopedPopoverProps<P> = ScopedProps<P, 'Popover'>;
17
25
  type PopoverContextValue = {
@@ -1 +1 @@
1
- {"version":3,"file":"Popover.d.ts","sourceRoot":"","sources":["../src/Popover.tsx"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,CAAA;AAM9B,OAAO,EAEL,WAAW,EACX,UAAU,EAEV,UAAU,EACV,cAAc,EAWf,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEvD,OAAO,EAAc,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,EAIL,gBAAgB,EAGhB,kBAAkB,EAElB,WAAW,EAEZ,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAgB,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAExE,OAAO,EAAU,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAErD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAY,UAAU,EAAE,MAAM,cAAc,CAAA;AAMnD,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG;IACvC,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACtC,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAC9B,CAAA;AAED,KAAK,kBAAkB,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,E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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmGnB,CAAA"}
@@ -1,7 +1,9 @@
1
1
  import type { UseFloatingOptions } from '@floating-ui/react';
2
- export declare const useFloatingContext: ({ open, setOpen, breakpointActive }: {
2
+ export declare const useFloatingContext: ({ open, setOpen, disable, disableFocus, hoverable, }: {
3
3
  open: any;
4
4
  setOpen: any;
5
- breakpointActive: any;
5
+ disable: any;
6
+ disableFocus: any;
7
+ hoverable: any;
6
8
  }) => (props: UseFloatingOptions) => any;
7
9
  //# sourceMappingURL=useFloatingContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFloatingContext.d.ts","sourceRoot":"","sources":["../src/useFloatingContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAK5D,eAAO,MAAM,kBAAkB;;;;cAEnB,kBAAkB,QAwB3B,CAAA"}
1
+ {"version":3,"file":"useFloatingContext.d.ts","sourceRoot":"","sources":["../src/useFloatingContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAa5D,eAAO,MAAM,kBAAkB;;;;;;cAQnB,kBAAkB,QAoC7B,CAAA"}