fix(SW-415): Close on click on infoIcon
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { useRef, useState } from "react"
|
import { useRef, useState } from "react"
|
||||||
import { Button, DialogTrigger } from "react-aria-components"
|
import { Button } from "react-aria-components"
|
||||||
|
|
||||||
import { CheckIcon, InfoCircleIcon } from "@/components/Icons"
|
import { CheckIcon, InfoCircleIcon } from "@/components/Icons"
|
||||||
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
||||||
@@ -26,6 +26,7 @@ export default function FlexibilityOption({
|
|||||||
const [rootDiv, setRootDiv] = useState<Element | undefined>(undefined)
|
const [rootDiv, setRootDiv] = useState<Element | undefined>(undefined)
|
||||||
const [isPopoverOpen, setIsPopoverOpen] = useState(false)
|
const [isPopoverOpen, setIsPopoverOpen] = useState(false)
|
||||||
let triggerRef = useRef<HTMLButtonElement>(null)
|
let triggerRef = useRef<HTMLButtonElement>(null)
|
||||||
|
const buttonClickedRef = useRef(false)
|
||||||
|
|
||||||
function setRef(node: Element | null) {
|
function setRef(node: Element | null) {
|
||||||
if (node) {
|
if (node) {
|
||||||
@@ -61,11 +62,13 @@ export default function FlexibilityOption({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function togglePopover() {
|
function togglePopover() {
|
||||||
console.log("Toggle Popover called")
|
buttonClickedRef.current = !buttonClickedRef.current
|
||||||
setIsPopoverOpen((prevState) => !prevState)
|
setIsPopoverOpen(buttonClickedRef.current)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(isPopoverOpen)
|
function handlePopoverChange(isOpen: boolean) {
|
||||||
|
setIsPopoverOpen(isOpen)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<label>
|
<label>
|
||||||
@@ -80,7 +83,9 @@ export default function FlexibilityOption({
|
|||||||
<Button
|
<Button
|
||||||
aria-label="Help"
|
aria-label="Help"
|
||||||
className={styles.button}
|
className={styles.button}
|
||||||
onPress={togglePopover}
|
onPress={() => {
|
||||||
|
togglePopover()
|
||||||
|
}}
|
||||||
ref={triggerRef}
|
ref={triggerRef}
|
||||||
>
|
>
|
||||||
<InfoCircleIcon
|
<InfoCircleIcon
|
||||||
@@ -104,7 +109,7 @@ export default function FlexibilityOption({
|
|||||||
UNSTABLE_portalContainer={rootDiv}
|
UNSTABLE_portalContainer={rootDiv}
|
||||||
triggerRef={triggerRef}
|
triggerRef={triggerRef}
|
||||||
isOpen={isPopoverOpen}
|
isOpen={isPopoverOpen}
|
||||||
onOpenChange={setIsPopoverOpen}
|
onOpenChange={handlePopoverChange}
|
||||||
>
|
>
|
||||||
<Caption
|
<Caption
|
||||||
color="uiTextHighContrast"
|
color="uiTextHighContrast"
|
||||||
|
|||||||
Reference in New Issue
Block a user