trigger icon indicating copy to clipboard operation
trigger copied to clipboard

Close trigger on `button click`

Open kevalsavani opened this issue 2 years ago • 4 comments

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>;

kevalsavani avatar Jul 15 '22 13:07 kevalsavani

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

Don-ixu avatar Jul 16 '22 03:07 Don-ixu

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

kevalsavani avatar Jul 17 '22 04:07 kevalsavani

@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.

kevalsavani avatar Jul 18 '22 10:07 kevalsavani

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

cybercarrot avatar Jul 19 '22 13:07 cybercarrot