Skip to content

Commit f9b8e15

Browse files
author
Erin Doyle
committed
Replaced Modal with use of react-modal, an already accessible Modal component from reactjs.
1 parent c0c9494 commit f9b8e15

File tree

7 files changed

+71
-67
lines changed

7 files changed

+71
-67
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"prop-types": "^15.6.2",
77
"react": "^16.4.2",
88
"react-dom": "^16.4.2",
9+
"react-modal": "^3.5.1",
910
"react-router-dom": "^4.3.1",
1011
"react-scripts": "1.1.4"
1112
},

public/app.css

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ a {
7070
color: #3951b1;
7171
}
7272

73-
.modal.show {
74-
display: inherit;
73+
.dialog-modal {
74+
position: absolute;
75+
top: 40px;
76+
left: 40px;
77+
right: 40px;
78+
bottom: 40px;
79+
}
80+
81+
.modal-overlay {
82+
position: fixed;
83+
top: 0;
84+
left: 0;
85+
right: 0;
86+
bottom: 0;
87+
background-color: rgba(77, 77, 77, 0.9);
7588
}

public/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
You need to enable JavaScript to run this app.
3232
</noscript>
3333
<div id="app-root"></div>
34-
<div id="modal-root"></div>
3534
<!--
3635
This HTML file is a template.
3736
If you open it directly in the browser, you will see an empty page.

src/primitives/Modal.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/wishlist/MovieEditor.js

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
3+
import Modal from 'react-modal';
34

4-
import Modal from '../primitives/Modal';
55

6+
// Make sure to bind modal to your appElement (http://reactcommunity.org/react-modal/accessibility/)
7+
Modal.setAppElement('#app-root');
68

79
class MovieEditor extends Component {
810
constructor(props) {
@@ -37,42 +39,53 @@ class MovieEditor extends Component {
3739
}
3840

3941
render() {
42+
const { isOpen } = this.props;
4043
const { notes } = this.state;
4144

4245
return (
43-
<Modal>
44-
<div className="modal fade show">
45-
<div className="modal-dialog modal-dialog-centered">
46-
<div className="modal-content">
47-
<div className="modal-header">
48-
<h5 className="modal-title">Edit Movie</h5>
49-
<button type="button" className="close" onClick={this.handleClose}>
50-
<span>&times;</span>
51-
</button>
52-
</div>
53-
<div className="modal-body">
54-
<div className="form-group">
55-
<label>Notes:</label>
56-
<textarea className="form-control" value={notes} onChange={this.handleChangeNotes} />
57-
</div>
58-
</div>
59-
<div className="modal-footer">
60-
<button type="button" className="btn btn-primary" onClick={this.handleSave}>Save</button>
46+
<Modal
47+
role="dialog"
48+
isOpen={isOpen}
49+
onRequestClose={this.handleClose}
50+
className="dialog-modal"
51+
overlayClassName="modal-overlay"
52+
aria={{
53+
labelledby: "modal-title"
54+
}}
55+
shouldFocusAfterRender={true}
56+
shouldCloseOnOverlayClick={true}
57+
>
58+
<div className="modal-dialog modal-dialog-centered">
59+
<div className="modal-content">
60+
<div className="modal-header">
61+
<h5 id="modal-title" className="modal-title">Edit Movie</h5>
62+
<button type="button" className="close" onClick={this.handleClose}>
63+
<span>&times;</span>
64+
</button>
65+
</div>
66+
<div className="modal-body">
67+
<div className="form-group">
68+
<label>Notes:</label>
69+
<textarea className="form-control" value={notes} onChange={this.handleChangeNotes} />
6170
</div>
6271
</div>
72+
<div className="modal-footer">
73+
<button type="button" className="btn btn-primary" onClick={this.handleSave}>Save</button>
74+
</div>
6375
</div>
6476
</div>
65-
<div className="modal-backdrop fade show" />
6677
</Modal>
6778
);
6879
}
6980
}
7081

7182
MovieEditor.defaultTypes = {
83+
isOpen: false,
7284
movie: {}
7385
};
7486

7587
MovieEditor.propTypes = {
88+
isOpen: PropTypes.bool,
7689
movie: PropTypes.object,
7790
updateMovie: PropTypes.func.isRequired
7891
};

src/wishlist/MovieWishlist.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@ class MovieWishlist extends Component {
9292
/>
9393
</div>
9494

95-
{ showEditor
96-
? <MovieEditor movie={movieInEditing} updateMovie={this.handleUpdateMovie} />
97-
: null
98-
}
95+
<MovieEditor
96+
movie={movieInEditing}
97+
updateMovie={this.handleUpdateMovie}
98+
isOpen={showEditor}
99+
/>
99100
</Fragment>
100101

101102
// No movies yet in the WishList

yarn.lock

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,6 +2647,10 @@ execa@^0.7.0:
26472647
signal-exit "^3.0.0"
26482648
strip-eof "^1.0.0"
26492649

2650+
exenv@^1.2.0:
2651+
version "1.2.2"
2652+
resolved "https://registry.yarnpkg.com/exenv/-/exenv-1.2.2.tgz#2ae78e85d9894158670b03d47bec1f03bd91bb9d"
2653+
26502654
expand-brackets@^0.1.4:
26512655
version "0.1.5"
26522656
resolved "https://registry.yarnpkg.com/expand-brackets/-/expand-brackets-0.1.5.tgz#df07284e342a807cd733ac5af72411e581d1177b"
@@ -5783,6 +5787,19 @@ react-error-overlay@^4.0.0:
57835787
version "4.0.0"
57845788
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-4.0.0.tgz#d198408a85b4070937a98667f500c832f86bd5d4"
57855789

5790+
react-lifecycles-compat@^3.0.0:
5791+
version "3.0.4"
5792+
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
5793+
5794+
react-modal@^3.5.1:
5795+
version "3.5.1"
5796+
resolved "https://registry.yarnpkg.com/react-modal/-/react-modal-3.5.1.tgz#33d38527def90ea324848f7d63e53acc4468a451"
5797+
dependencies:
5798+
exenv "^1.2.0"
5799+
prop-types "^15.5.10"
5800+
react-lifecycles-compat "^3.0.0"
5801+
warning "^3.0.0"
5802+
57865803
react-router-dom@^4.3.1:
57875804
version "4.3.1"
57885805
resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-4.3.1.tgz#4c2619fc24c4fa87c9fd18f4fb4a43fe63fbd5c6"

0 commit comments

Comments
 (0)