0

I have the following 'Button' component:

<Button
  variant="contained"
  label="START"
  color="secondary"
  size="large"
  onClick={handleClick}
/>

Which when pressed opens the following Confirm dialogue box:

<Confirm
  isOpen={open}
  title="Update View Count"
  content="Are you sure you want to update these posts?"
  onConfirm={handleConfirm}
  onClose={handleDialogClose}
/>

Once confirmed, I would like to open a URL on a new tab. I am currently using the redirect() function to open it, however it opens it on the same tab. I know I can use target="_blank" in the 'Button' component but that opens the URL before the confirmation.

  const redirect = useRedirect();
  const handleClick = () => setOpen(true);
  const handleDialogClose = () => setOpen(false);
  const handleConfirm = () => {
      redirect("www.google.com");
      setOpen(false);
  };
Eshaan Gupta
  • 614
  • 8
  • 25

1 Answers1

1

You can try something like this on opening in new window

  const handleConfirm = () => {
    setOpen(false);
    window.open(url, '_blank').focus();
  };