Skip to content

Commit

Permalink
Components: Reorder component lifecycle as first class members
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Jul 4, 2018
1 parent 9ee5b83 commit 1a0bf75
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions components/modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,6 @@ class Modal extends Component {
this.setHeadingId( props );
}

/**
* Prepares the DOM for the modals to be rendered.
*
* Every modal is mounted in a separate div appended to a parent div
* that is appended to the document body.
*
* The parent div will be created if it does not yet exist, and the
* separate div for this specific modal will be appended to that.
*/
prepareDOM() {
if ( ! parentElement ) {
parentElement = document.createElement( 'div' );
document.body.appendChild( parentElement );
}
this.node = document.createElement( 'div' );
parentElement.appendChild( this.node );
}

/**
* Sets the heading id to the aria.labelledby prop or a unique id when
* the prop is unavailable.
*
* @param {Object} props The component's props.
*/
setHeadingId( props ) {
this.headingId = props.aria.labelledby || uniqueId( 'modal-heading-' );
}

/**
* Removes the specific mounting point for this modal from the DOM.
*/
cleanDOM() {
parentElement.removeChild( this.node );
}

/**
* Appends the modal's node to the DOM, so the portal can render the
* modal in it. Also calls the openFirstModal when this is the first modal to be
Expand Down Expand Up @@ -103,6 +68,41 @@ class Modal extends Component {
this.cleanDOM();
}

/**
* Prepares the DOM for the modals to be rendered.
*
* Every modal is mounted in a separate div appended to a parent div
* that is appended to the document body.
*
* The parent div will be created if it does not yet exist, and the
* separate div for this specific modal will be appended to that.
*/
prepareDOM() {
if ( ! parentElement ) {
parentElement = document.createElement( 'div' );
document.body.appendChild( parentElement );
}
this.node = document.createElement( 'div' );
parentElement.appendChild( this.node );
}

/**
* Sets the heading id to the aria.labelledby prop or a unique id when
* the prop is unavailable.
*
* @param {Object} props The component's props.
*/
setHeadingId( props ) {
this.headingId = props.aria.labelledby || uniqueId( 'modal-heading-' );
}

/**
* Removes the specific mounting point for this modal from the DOM.
*/
cleanDOM() {
parentElement.removeChild( this.node );
}

/**
* Prepares the DOM for this modal and any additional modal to be mounted.
*
Expand Down

0 comments on commit 1a0bf75

Please sign in to comment.