Commit 71d2714e authored by Damien Mariotto's avatar Damien Mariotto
Browse files

[Modal] Missing proptypes + fix effects

parent 32f49814
Pipeline #1636 passed with stage
in 55 seconds
......@@ -28,9 +28,9 @@ function Modal({
disableEscapeKeyDown,
...props
}) {
let [exited, setExited] = useState(!props.open);
let [prevOpen, setPrevOpen] = useState(null);
let node = useRef();
const [exited, setExited] = useState(!props.open);
const [prevOpen, setPrevOpen] = useState(null);
const node = useRef();
if (props.open !== prevOpen) {
// getDerivedStateFromProps
......@@ -44,16 +44,12 @@ function Modal({
}
useEffect(() => {
setTimeout(() => {
document.addEventListener('keydown', handleKeyDown);
});
document.addEventListener('keydown', handleKeyDown);
return () => {
setTimeout(() => {
document.removeEventListener('keydown', handleKeyDown);
});
document.removeEventListener('keydown', handleKeyDown);
};
});
}, []);
useEffect(() => {
document.addEventListener('mousedown', handleClickOutside, false);
......@@ -61,7 +57,7 @@ function Modal({
return () => {
document.removeEventListener('mousedown', handleClickOutside, false);
};
});
}, []);
const handleKeyDown = e => {
if (e.key === 'Escape' || e.key === 'Esc' || e.keyCode === 27) {
......@@ -179,11 +175,12 @@ Modal.propTypes = {
/**
* Si `true`, appuyer sur 'Echap' ne déclenche pas la fonction de callback onClose
*/
disableEscapeKeyDown: PropTypes.bool
};
disableEscapeKeyDown: PropTypes.bool,
Modal.defaultTypes = {
open: false
/**
* Callback appelée lors de la fermeture de la boîte de dialogue
*/
onClose: PropTypes.func.isRequired
};
export default withStyles(styles)(Modal);
import React, { Fragment, useState } from 'react';
import { Link } from 'react-router-dom';
import { Fade, Modal, Text, Button, Row, Col } from '@webalt/react';
import { withStyles } from '../../styles';
import { Fade, Modal, Text, Button, Row, Col, withStyles } from '@webalt/react';
const styles = theme => ({
root: {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment