diff --git a/packages/help/src/__snapshots__/Help.spec.js.snap b/packages/help/src/__snapshots__/Help.spec.js.snap index fe51af154..a228943b9 100644 --- a/packages/help/src/__snapshots__/Help.spec.js.snap +++ b/packages/help/src/__snapshots__/Help.spec.js.snap @@ -1,12 +1,14 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[` Render Should render Help component 1`] = ` - - + `; diff --git a/packages/popover/src/Popover.js b/packages/popover/src/Popover.js index 917c0a3af..e3b004ad1 100644 --- a/packages/popover/src/Popover.js +++ b/packages/popover/src/Popover.js @@ -1,4 +1,4 @@ -import React, { useEffect, useRef, useState } from 'react'; +import React, { useRef, useState } from 'react'; import PropTypes from 'prop-types'; import { Constants } from '@axa-fr/react-toolkit-core'; import PopoverBase from './PopoverBase'; @@ -30,48 +30,65 @@ export const PopoverClick = props => { const wrapperRef = useRef(null); const [isOpen, setOpen] = useState(false); const [isHover, setHover] = useState(false); + const [isPopoverHover, setPopoverHover] = useState(false); - useEffect(() => { - const handleClickOutside = event => { - if (wrapperRef.current && !wrapperRef.current.contains(event.target)) { - setOpen(false); - } - }; - - document.addEventListener('click', handleClickOutside); - return () => { + const handleClickOutside = event => { + if (wrapperRef.current && !wrapperRef.current.contains(event.target)) { + setOpen(false); document.removeEventListener('click', handleClickOutside); - }; - }, [wrapperRef]); + } + }; + + const handleClick = event => { + if (isPopoverHover) { + event.stopPropagation(); + return; + } - const click = () => { - setOpen(!isOpen && isHover); + const shouldOpen = !isOpen && isHover; + setOpen(shouldOpen); + + if (shouldOpen) { + document.addEventListener('click', handleClickOutside); + } }; - const enter = () => { + const handleMouseEnter = () => { setHover(true); }; - const leave = () => { + const handleMouseLeave = () => { setHover(false); }; + const handleMouseEnterPopover = () => { + setPopoverHover(true); + }; + + const handleMouseLeavePopover = () => { + setPopoverHover(false); + }; + return ( - + ); }; @@ -79,16 +96,19 @@ export const PopoverOver = props => { const { children, placement, className, classModifier } = props; const [isOpen, setOpen] = useState(false); - const enter = () => { + const handleMouseEnter = () => { setOpen(true); }; - const leave = () => { + const handleMouseLeave = () => { setOpen(false); }; return ( - +
{ classModifier={classModifier}> {children} - +
); }; diff --git a/packages/popover/src/PopoverBase.js b/packages/popover/src/PopoverBase.js index 8ecb9ab12..2fccd80bd 100644 --- a/packages/popover/src/PopoverBase.js +++ b/packages/popover/src/PopoverBase.js @@ -74,7 +74,7 @@ export const AnimatedPopover = props => { const componentClassName = ClassManager.getComponentClassName( className, classModifier, - defaultClassName, + defaultClassName ); const [referenceElement, setReferenceElement] = useState(null); @@ -82,7 +82,12 @@ export const AnimatedPopover = props => { const [arrowElement, setArrowElement] = useState(null); const { styles, attributes } = usePopper(referenceElement, popperElement, { modifiers: [ - { name: 'arrow', options: { element: arrowElement } }, + { + name: 'arrow', + options: { + element: arrowElement, + }, + }, { name: 'offset', options: { @@ -111,9 +116,7 @@ export const AnimatedPopover = props => { data-popper-placement={placement} className="af-popover__container-pop" {...attributes.popper}> -
- {children} -
+
{children}
.af-popover__arrow { - bottom: -4px; + bottom: $arrow-offset; } [data-popper-placement^='bottom'] > .af-popover__arrow { - top: -4px; + top: $arrow-offset; } [data-popper-placement^='right'] > .af-popover__arrow { - left: -12px; + left: $arrow-offset; } [data-popper-placement^='left'] > .af-popover__arrow { - right: 4px; + right: $arrow-offset; } }