From a45fb3dfe8bb8a7ce323464e14147deb5675a9ef Mon Sep 17 00:00:00 2001 From: Pranay Kothapalli Date: Tue, 26 Dec 2023 08:02:27 +0300 Subject: [PATCH] Fix Popper placement and add customRootClass in Popper.js --- src/components/tools/Popper/Popper.js | 29 ++++++++++++------- src/components/ui/Dropdown/Dropdown.js | 2 +- .../ui/Dropdown/Dropdown.stories.js | 13 +++++++-- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/components/tools/Popper/Popper.js b/src/components/tools/Popper/Popper.js index fc15e08f..5ae61fb9 100644 --- a/src/components/tools/Popper/Popper.js +++ b/src/components/tools/Popper/Popper.js @@ -1,7 +1,7 @@ import {useState, useRef} from 'react'; import {customClassSwitcher} from '~/core'; -import {useFloating, useInteractions, useHover, FloatingArrow, arrow, offset, flip, autoPlacement, useRole, useDismiss} from '@floating-ui/react'; +import {useFloating, useInteractions, useHover, FloatingArrow, arrow, offset, flip, autoUpdate, autoPlacement, useRole, useDismiss} from '@floating-ui/react'; // TODO : Use Floating Portal? // TODO : Collisions dont seem to be working as expected, need to investigate @@ -9,11 +9,20 @@ import {useFloating, useInteractions, useHover, FloatingArrow, arrow, offset, fl const ARROW_HEIGHT = 7; const GAP = 2; +/** + * + * + * For Placement https://floating-ui.com/docs/computePosition#placement + + + */ + const Popper = ({ popperName='', customRootClass='', activationStrategy='hover', - className='', placement='top', + className='', + placement='top', children, open=false, hoverDelay=10, @@ -27,21 +36,19 @@ const Popper = ({ const {refs, floatingStyles, context} = useFloating({ placement: placement, + whileElementsMounted: autoUpdate, open: isOpen, + // strategy: 'fixed', middleware: [ arrow({ element: arrowRef, }), offset(ARROW_HEIGHT + GAP), - // autoPlacement({ - // crossAxis: 'center', - // alignment: 'start', - // autoAlignment: true, - // allowedPlacements: ['top', 'bottom', 'left', 'right'], - // padding: 5, - // }), - flip(), - + flip({ + mainAxis: false, + fallbackPlacements: ['right', 'bottom'], + }, + ), ], onOpenChange: setIsOpen, }); diff --git a/src/components/ui/Dropdown/Dropdown.js b/src/components/ui/Dropdown/Dropdown.js index a59b6b77..ccc82083 100644 --- a/src/components/ui/Dropdown/Dropdown.js +++ b/src/components/ui/Dropdown/Dropdown.js @@ -10,7 +10,7 @@ const Dropdown = ({list=[], selected}) => { ; }; return
- }> + }> Dropdown
; diff --git a/src/components/ui/Dropdown/Dropdown.stories.js b/src/components/ui/Dropdown/Dropdown.stories.js index b5fb4493..d8dffdd7 100644 --- a/src/components/ui/Dropdown/Dropdown.stories.js +++ b/src/components/ui/Dropdown/Dropdown.stories.js @@ -7,13 +7,20 @@ export default { title: 'UI/Input/Dropdown', component: Dropdown, render: (args) => -
-
- Dropdown +
+
+
+ Dropdown +
+ {}} label={'Bello'} list={[ {value: 'hello', label: 'hello'}, ]}>Hello + +
+ Dropdown End +
,