Skip to content

Popover Mechanism and triggerRef usability #3408

Answered by wingkwong
Berdugo1994 asked this question in Help
Discussion options

You must be logged in to vote

you may try the following

import React from "react";
import {
  Popover,
  PopoverTrigger,
  PopoverContent,
  Button,
} from "@nextui-org/react";

export default function App() {
  const [loggedOpen, setLoggedOpen] = React.useState<boolean>(false);
  const triggerRef = React.useRef(null);
  return (
    <div>
      <Popover
        isOpen={loggedOpen}
        shouldCloseOnInteractOutside={(element) => {
          console.log("OUTSIDE");
          const trigger = triggerRef?.current;

          if (!trigger || !trigger.contains(element)) {
            setLoggedOpen(false);
            return false;
          }
          return true;
        }}
      >
        <PopoverTrigger
          onC…

Replies: 4 comments 8 replies

Comment options

You must be logged in to vote
3 replies
@Berdugo1994
Comment options

@wingkwong
Comment options

@Berdugo1994
Comment options

Comment options

You must be logged in to vote
3 replies
@Berdugo1994
Comment options

@wingkwong
Comment options

@Berdugo1994
Comment options

Comment options

You must be logged in to vote
2 replies
@wingkwong
Comment options

Answer selected by Berdugo1994
@Berdugo1994
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants