Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paragon
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
paragon
Commits
045d2adf
Commit
045d2adf
authored
Dec 10, 2017
by
Ari Rizzitano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor modal to use portals
parent
f9221d99
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
13 deletions
+24
-13
src/Dropdown/Dropdown.scss
+0
-12
src/Modal/index.jsx
+24
-1
No files found.
src/Dropdown/Dropdown.scss
View file @
045d2adf
@import
"~bootstrap/scss/_dropdown"
;
@import
"~bootstrap/scss/_dropdown"
;
// Trying to patch this upstream, then this can
// be removed.
// https://github.com/twbs/bootstrap/pull/23990
.show
{
>
a
:focus
{
outline-width
:
2px
;
outline-style
:
solid
;
outline-color
:
Highlight
;
outline
:
-
webkit-focus-ring-color
auto
5px
;
}
}
src/Modal/index.jsx
View file @
045d2adf
import
React
from
'react'
;
import
React
from
'react'
;
import
ReactDOM
from
'react-dom'
;
import
classNames
from
'classnames'
;
import
classNames
from
'classnames'
;
import
PropTypes
from
'prop-types'
;
import
PropTypes
from
'prop-types'
;
...
@@ -6,6 +7,9 @@ import styles from './Modal.scss';
...
@@ -6,6 +7,9 @@ import styles from './Modal.scss';
import
Button
,
{
buttonPropTypes
}
from
'../Button'
;
import
Button
,
{
buttonPropTypes
}
from
'../Button'
;
import
newId
from
'../utils/newId'
;
import
newId
from
'../utils/newId'
;
const
modalRootId
=
'modal-root'
;
let
modalRoot
=
document
.
getElementById
(
modalRootId
);
class
Modal
extends
React
.
Component
{
class
Modal
extends
React
.
Component
{
constructor
(
props
)
{
constructor
(
props
)
{
super
(
props
);
super
(
props
);
...
@@ -16,6 +20,13 @@ class Modal extends React.Component {
...
@@ -16,6 +20,13 @@ class Modal extends React.Component {
this
.
setCloseButton
=
this
.
setCloseButton
.
bind
(
this
);
this
.
setCloseButton
=
this
.
setCloseButton
.
bind
(
this
);
this
.
headerId
=
newId
();
this
.
headerId
=
newId
();
this
.
el
=
document
.
createElement
(
'div'
);
if
(
!
modalRoot
)
{
modalRoot
=
document
.
createElement
(
'div'
);
modalRoot
.
id
=
modalRootId
;
document
.
body
.
appendChild
(
modalRoot
);
}
this
.
state
=
{
this
.
state
=
{
open
:
props
.
open
,
open
:
props
.
open
,
...
@@ -23,6 +34,7 @@ class Modal extends React.Component {
...
@@ -23,6 +34,7 @@ class Modal extends React.Component {
}
}
componentDidMount
()
{
componentDidMount
()
{
modalRoot
.
appendChild
(
this
.
el
);
if
(
this
.
xButton
)
{
if
(
this
.
xButton
)
{
this
.
xButton
.
focus
();
this
.
xButton
.
focus
();
}
}
...
@@ -40,6 +52,10 @@ class Modal extends React.Component {
...
@@ -40,6 +52,10 @@ class Modal extends React.Component {
}
}
}
}
componentWillUnmount
()
{
modalRoot
.
removeChild
(
this
.
el
);
}
setXButton
(
input
)
{
setXButton
(
input
)
{
this
.
xButton
=
input
;
this
.
xButton
=
input
;
}
}
...
@@ -98,7 +114,7 @@ class Modal extends React.Component {
...
@@ -98,7 +114,7 @@ class Modal extends React.Component {
return
body
;
return
body
;
}
}
render
()
{
render
Modal
()
{
const
{
open
}
=
this
.
state
;
const
{
open
}
=
this
.
state
;
return
(
return
(
...
@@ -147,6 +163,13 @@ class Modal extends React.Component {
...
@@ -147,6 +163,13 @@ class Modal extends React.Component {
</
div
>
</
div
>
);
);
}
}
render
()
{
return
ReactDOM
.
createPortal
(
this
.
renderModal
(),
this
.
el
,
);
}
}
}
Modal
.
propTypes
=
{
Modal
.
propTypes
=
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment