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

outside click on dialog modal does not dismiss it.

Open jasan-s opened this issue 10 years ago • 9 comments

Problem description

I can click ESC or click the OK(Flat button) and the modal dialog is dismissed however clicking on outside does not trigger onRequestClose. I have set the modal to false according to the docs. What I'm i doing wrong.

Steps to reproduce

  const { handleSubmit, pristine, reset, submitting } = props
  const actions = [
    <FlatButton
        label='Ok'
        primary={true}
        keyboardFocused={true}
        onClick={props.closeModal}/>
  ]
  return (
    <div>
        <RaisedButton label='Duck' onClick= {props.openModal} />

        <div>

            <form onSubmit= {handleSubmit}>
                 <Field name ='duck' component = {(duck) =>
        <Dialog
          title="Dialog With Actions"
          actions={actions}
          modal={false}
          open={props.isOpen}
          onRequestClose={props.closeModal} >
          Only actions can close this dialog.
        </Dialog>}/>
            </form>
        </div>
    </div>
  )

Versions

  • Material-UI: latest release
  • React: latest release
  • Browser: chrome latest release

jasan-s avatar Jun 22 '16 05:06 jasan-s

I fix it, now pr

stephenkingsley avatar Jun 24 '16 12:06 stephenkingsley

react-tap-event-plugin?

http://www.material-ui.com/#/get-started/installation

mbrookes avatar Jun 24 '16 15:06 mbrookes

@jasan-s you must be use react-tap-event-plugin

stephenkingsley avatar Jun 30 '16 07:06 stephenkingsley

@jasan-s is it working now?

nehalbhanushali avatar Jun 30 '16 16:06 nehalbhanushali

@stephenkingsley i'm using lated npm module for this lib. and it doesn't use es6 classes. I ll try to figure out how i can make those changes in that module. @mbrookes I tried using onTouchTap and it works fine for non-touch devices but on touch devices the tap registers twice, so the modal open and closes right away. that is why i stuck to just onCLick

jasan-s avatar Jun 30 '16 17:06 jasan-s

I did use react-tap-event-plugin, my issue is that I can dismiss the dialog when I set modal to false, but I can NOT dismiss it when set modal to true. It seems like to act as the opposite way according to the doc.

longmfe avatar Jul 04 '16 07:07 longmfe

I can dismiss the dialog when I set modal to false, but I can NOT dismiss it when set modal to true. It seems like to act as the opposite way according to the doc.

http://www.material-ui.com/#/components/dialog "A modal dialog can only be closed by selecting one of the actions."

We could argue the toss about whether that's the correct use of the term "modal", but the behaviour you describe matches the documentation.

mbrookes avatar Jul 04 '16 09:07 mbrookes

I think we can close this issue then

aahan96 avatar Aug 16 '16 21:08 aahan96

i made a custom solution for this if anyone interested it worked for me without installing any addtional packages i created a custom fixed div inside the modal with full width and height and give it lower zindex than all the other elements in the modal

<CustomDialog
                onClose={handleClose}
                aria-labelledby={title}
                open={open}
                width={isSmallOrMediumScreen ? "93%" : width}
                TransitionComponent={Transition}
                onClick={onClick}
                ref={ref}
                keepMounted={keepMounted}
                height={height && isSmallOrMediumScreen ? height : 'auto'}
            >
                <div
                    className="fixed top-0 left-0 w-full h-full  z-[1]"
                    onClick={handleClose}
                />
                <DialogTitle id={title} className="z-[2]">
                    <CloseButton aria-label="close" onClick={handleClose}>
                        <FaArrowLeft
                            style={{fontSize: '20px'}}
                        />
                    </CloseButton>
                    <span style={{color: '#F8775D', fontWeight: '700', paddingRight: '10px'}}>{title}</span>
                </DialogTitle>
                <DialogContent dividers className="z-[2]">{children}</DialogContent>
                {firstButton && secondButton && (
                    <DialogActions
                        className="z-[2]"
                    sx={{
                        display: 'flex',
                        gap: '10px',
                        margin: '10px',
                        }}
                    >
                        <Button autoFocus className="z-[2]" onClick={firstButtonAction} color="primary">
                            {firstButton}
                        </Button>
                        <Button autoFocus className="z-[2]" onClick={secondButtonAction} color="primary">
                            {secondButton}
                        </Button>
                    </DialogActions>
                )}
            </CustomDialog>

shadyshanab avatar Nov 29 '24 22:11 shadyshanab