material-tailwind icon indicating copy to clipboard operation
material-tailwind copied to clipboard

Are "dismiss" options on Dialog really working?

Open stas-kh opened this issue 2 years ago • 8 comments

I'm trying to configure my Dialogs to not close automatically when clicked outside. I found that there is a dismiss option on the Dialog component, but passing falsy options to its events like referencePointerDown or outsidePointerDown doesn't give me desired results.

Example:

<Dialog
  open={open}
  handler={handleOpen}
  dismiss={{
    enabled: true,
    escapeKey: true,
    referencePointerDown: false,
    outsidePointerDown: false,
    ancestorScroll: false,
    bubbles: false,
  }}
>

Can you help me to understand what should be passed there to close the dialog only when "Escape" button is pressed?

stas-kh avatar Mar 03 '23 15:03 stas-kh

Hey @stas-kh,

It's because of some major changes to floating-ui library here is a quick fix for you and I'll fix this issue on the upcoming update.

import { Fragment, useState } from "react";
import {
  Button,
  Dialog,
  DialogHeader,
  DialogBody,
  DialogFooter,
} from "@material-tailwind/react";

export default function Example() {
  const [open, setOpen] = useState(false);

  const handleOpen = () => setOpen(!open);

  return (
    <Fragment>
      <Button onClick={handleOpen} variant="gradient">
        Open Dialog
      </Button>
      <Dialog
        open={open}
        handler={handleOpen}
        dismiss={{
          outsidePress: false,
        } as any}
      >
        <DialogHeader>Its a simple dialog.</DialogHeader>
        <DialogBody divider>
          Lorem, ipsum dolor sit amet consectetur adipisicing elit. Accusamus ad
          reprehenderit omnis perspiciatis aut odit! Unde architecto
          perspiciatis, dolorum dolorem iure quia saepe autem accusamus eum
          praesentium magni corrupti explicabo!
        </DialogBody>
        <DialogFooter>
          <Button
            variant="text"
            color="red"
            onClick={handleOpen}
            className="mr-1"
          >
            <span>Cancel</span>
          </Button>
          <Button variant="gradient" color="green" onClick={handleOpen}>
            <span>Confirm</span>
          </Button>
        </DialogFooter>
      </Dialog>
    </Fragment>
  );
}

Cheers, Sajad

sajadevo avatar Mar 06 '23 05:03 sajadevo

Hello, @sajadevo. Is Dismiss still not working? Cause I tried with the Menu component, but it isn't responding to the properties.

ggquicky avatar Apr 14 '23 22:04 ggquicky

Hey there,

It's working if you use the following pattern:

interface Props {
  enabled?: boolean;
  escapeKey?: boolean;
  referencePress?: boolean;
  referencePressEvent?: 'pointerdown' | 'mousedown' | 'click';
  outsidePress?: boolean | ((event: MouseEvent) => boolean);
  outsidePressEvent?: 'pointerdown' | 'mousedown' | 'click';
  ancestorScroll?: boolean;
  bubbles?:
    | boolean
    | {escapeKey?: boolean; outsidePress?: boolean};
}

Regards, Sajad

sajadevo avatar Apr 24 '23 07:04 sajadevo

Hello again @sajadevo the props are working but I have a warning on react console:

Warning: Failed prop type: The prop dismiss.isRequired is marked as required in MaterialTailwind.MenuCore, but its value is undefined.

<Menu
            ref={ref as React.Ref<HTMLButtonElement>}
            placement="right-start"
            dismiss={{
              enabled: true,
              escapeKey: false,
              referencePress: true,
              referencePressEvent: "click",
              outsidePress: true,
              outsidePressEvent: "click",
              ancestorScroll: true,
              bubbles: {
                escapeKey: true,
                outsidePress: false,
              },
            }}
          >

image

ggquicky avatar May 26 '23 16:05 ggquicky

Hi, i'm facing a similar issue using a dismiss prop in a menu element.

For "@material-tailwind/react": "^2.0.6"

ryanchua00 avatar Jul 28 '23 05:07 ryanchua00

I also, when i use menu and set dissmiss as dismiss={{ itemPress: true }} it starts throwing the error : app-index.js:31 Warning: Failed prop type: The prop dismiss.isRequired is marked as required in MaterialTailwind.Menu, but its value is undefined image image

SrOliver202023 avatar Sep 03 '23 11:09 SrOliver202023

Same warning here, any update on this?

import React, { PropsWithChildren } from 'react';
import { Menu, MenuList, MenuHandler } from '@material-tailwind/react';

export const FilterDropDown: React.FC<
  PropsWithChildren<{
    root?: React.ReactNode;
  }>
> = ({ children, root }) => {
  return (
    <div data-testid="filterDropDownTrigger">
      <Menu placement="bottom" dismiss={{ outsidePress: true }}>
        <MenuHandler >
          <div>{root}</div>
        </MenuHandler>
        <MenuList>{children}</MenuList>
      </Menu>
    </div>
  );
};

export default FilterDropDown;

Warning in console

Warning: Failed prop type: The prop `dismiss.isRequired` is marked as required in `MaterialTailwind.MenuCore`, but its value is `undefined`.
node_modules/@material-tailwind/react/components/Menu/MenuCore.js/MenuCore<@http://localhost:4200/....

denislutz avatar Oct 10 '23 11:10 denislutz

dismiss={{ outsidePress: false }} works for me to stop the Dialog from closing when clicking the backdrop.
Using     "@material-tailwind/react": "^2.1.7"

seminip avatar Jan 19 '24 15:01 seminip