Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

Commit

Permalink
refactor(Modal): query offsetWidth and offsetHeight before focusi…
Browse files Browse the repository at this point in the history
…ng button
  • Loading branch information
emyarod committed Jun 14, 2018
1 parent 384386c commit e8dc8e2
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/components/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,25 @@ export default class Modal extends Component {
}
};

focusButton = e => {
const modalIsVisible =
this.props.open &&
(e.propertyName === 'opacity' || e.propertyName === 'visibility');
if (this.button && modalIsVisible) {
focusButton = () => {
if (this.button) {
this.button.current.focus();
}
};

handleTransitionEnd = evt => {
if (!evt.target.classList.contains('bx--modal')) {
return;
}
const modalIsVisible =
evt.target.offsetHeight &&
evt.target.offsetWidth &&
evt.propertyName === 'opacity';
if (this.props.open && modalIsVisible) {
this.focusButton();
}
};

render() {
const {
modalHeading,
Expand Down Expand Up @@ -153,7 +163,7 @@ export default class Modal extends Component {
className={modalClasses}
role="presentation"
tabIndex={-1}
onTransitionEnd={this.focusButton}>
onTransitionEnd={this.handleTransitionEnd}>
{modalBody}
</div>
);
Expand Down

0 comments on commit e8dc8e2

Please sign in to comment.