Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close trigger on button click #303

Open
kevalsavani opened this issue Jul 15, 2022 · 4 comments
Open

Close trigger on button click #303

kevalsavani opened this issue Jul 15, 2022 · 4 comments

Comments

@kevalsavani
Copy link

How can I close the trigger popup on the external click, there is a use-case in code
Here is the code.

<Trigger
  action={["click"]}
  popup={
    <div>
      <p>This is a sample code</p>
      <p>
        <button
          onClick={() => {
            // Code to close the trigger on button click
          }}
        >
          Close trigger
        </button>
      </p>
    </div>
  }
  popupAlign={{
    points: ["tl", "cr"],
    offset: [10, 10],
    overflow: {
      adjustX: 1,
      adjustY: 1,
    },
  }}
>
  Show Trigger
</Trigger>;

@Don-ixu
Copy link

Don-ixu commented Jul 16, 2022

I have the same problem, do you know how to solve it?

@kevalsavani
Copy link
Author

I tried couple of ways but did not found any particular solution.

@kevalsavani
Copy link
Author

@Don-ixu I have found a way to show and hide the popup, use props popupVisible as boolean.

However I still don't see any props to close the modal when user clicks outside of the popup, tho I have used third party package but if we get that in-build it will be easy for us.

@cybercarrot
Copy link

const [visible, setVisible] = useState(false);

<Trigger
  action={["click"]}
  popup={
    <div>
      <p>This is a sample code</p>
      <p>
        <button
          onClick={() => {
            // Code to close the trigger on button click
          }}
        >
          Close trigger
        </button>
      </p>
    </div>
  }
  popupAlign={{
    points: ["tl", "cr"],
    offset: [10, 10],
    overflow: {
      adjustX: 1,
      adjustY: 1,
    },
  }}
 popupVisible={visible}
 onPopupVisibleChange={(a) => {
   setVisible(a);
 }}
>
  Show Trigger
</Trigger>;

this works,but should pass setVisible(false) to popup inside, wonder a better solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants