Skip to content

Commit

Permalink
fixed double click error issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigkill32 committed Jan 13, 2020
1 parent f5151f2 commit d52db58
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 32 deletions.
102 changes: 102 additions & 0 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"prop-types": "^15.6.2",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-router-dom": "^5.1.2",
"react-scripts": "^1.1.4",
"react-stateless-modal": "file:.."
},
Expand Down
60 changes: 38 additions & 22 deletions example/src/App.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React, { Component } from 'react';
import { openModal, Modal, closeModal } from 'react-stateless-modal';
import './test.css';
import closeSrc from './twitter.svg'
import closeSrc from './twitter.svg';
import { Route, Link } from 'react-router-dom';
import Landing from './landing';

export default class App extends Component {

state = {
open: false
}
};

openModal = () => {
openModal({
Expand All @@ -20,26 +21,33 @@ export default class App extends Component {
</p>
),
footer: () => (
<button onClick={this.openInnerModal}>Open Inner Modal</button>
<div>
<button onClick={this.openInnerModal}>Open Inner Modal</button>
<Link to="/landing">landing</Link>
</div>
),
// containerId: 'modals',
animation: {name: 'zoom-in', duration: '250ms'},
animation: { name: 'zoom-in', duration: '250ms' }
});
};

openInnerModal = () => {
openModal({
head: 'Inner Heading',
body: () => <p>Inner Body Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam
pulvinar risus non risus hendrerit venenatis. Pellentesque sit amet
hendrerit risus, sed porttitor quam Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam
pulvinar risus non risus hendrerit venenatis. Pellentesque sit amet
hendrerit risus, sed porttitor quam Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam
body: () => (
<p>
Inner Body Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nullam pulvinar risus non risus hendrerit venenatis. Pellentesque sit
amet hendrerit risus, sed porttitor quam Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nullam pulvinar risus non risus hendrerit
venenatis. Pellentesque sit amet hendrerit risus, sed porttitor quam
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam
pulvinar risus non risus hendrerit venenatis. Pellentesque sit amet
hendrerit risus, sed porttitor quam</p>,
hendrerit risus, sed porttitor quam
</p>
),
footer: () => <button onClick={this.inner}>Inner</button>,
closeIcon: { src: closeSrc, alt:'close' },
classNames: {overlay: 'overlay', modal: 'mod', closeIcon: 'ico'},
closeIcon: { src: closeSrc, alt: 'close' },
classNames: { overlay: 'overlay', modal: 'mod', closeIcon: 'ico' },
modalId: 69420,
disableOverlayClick: true
});
Expand All @@ -52,26 +60,34 @@ export default class App extends Component {
closeOnEscape: false,
footer: () => <button onClick={closeModal}>close</button>,
modalId: 42069
})
}
});
};

handleClose = () => {
this.setState({open: false})
}
this.setState({ open: false });
};

handleOpen = () => {
this.setState({open: true})
}
this.setState({ open: true });
};

render() {
const {open} = this.state;
const { open } = this.state;
return (
<div>
<Route path="/landing" component={Landing} />
<h1>Modal demo</h1>
<button onClick={this.openModal}>Open Modal via function mode</button>
<button onClick={this.handleOpen}>Open Modal via Component mode</button>
{/* <Modal head="head" onClose={this.handleClose} open={open} animation={{ name: "bounce", duration: "500ms" }}/> */}
<Modal onClose={this.handleClose} open={open} head="Test" body={() => <button onClick={closeModal}>close</button>} disableOverlayClick={true}/>
<Modal
onClose={this.handleClose}
open={open}
head="Test"
body={() => <button onClick={closeModal}>close</button>}
disableOverlayClick={true}
footer={() => <Link to="/landing">landing</Link>}
/>
</div>
);
}
Expand Down
17 changes: 11 additions & 6 deletions example/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import React from 'react'
import ReactDOM from 'react-dom'
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import './index.css';
import App from './App';

import './index.css'
import App from './App'

ReactDOM.render(<App />, document.getElementById('root'))
ReactDOM.render(
<BrowserRouter>
<App />
</BrowserRouter>,
document.getElementById('root')
);
9 changes: 9 additions & 0 deletions example/src/landing.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

const Landing = () => {
return (
<h1>Landing page</h1>
);
}

export default Landing;
10 changes: 6 additions & 4 deletions src/components/cbModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ class CBModal extends Component {

unmountModal = (id) => {
const element = document.querySelector(`#app-modal-${id}`);
element.parentNode.removeChild(element);
CBModal.instances.pop();
if (CBModal.instances.length === 0) {
document.removeEventListener('keydown', this.handleKeyDown, false);
if (element) {
element.parentNode.removeChild(element);
CBModal.instances.pop();
if (CBModal.instances.length === 0) {
document.removeEventListener('keydown', this.handleKeyDown, false);
}
}
};

Expand Down

0 comments on commit d52db58

Please sign in to comment.