Skip to content

Commit

Permalink
fix(Modal): update zindex when prop is changed (#937)
Browse files Browse the repository at this point in the history
  • Loading branch information
lslv1243 authored and TheSharpieOne committed Apr 3, 2018
1 parent 4dea4a6 commit 01667c1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ class Modal extends React.Component {
if (this.props.autoFocus && this.state.isOpen && !prevState.isOpen) {
this.setFocus();
}

if (this._element && prevProps.zIndex !== this.props.zIndex) {
this._element.style.zIndex = this.props.zIndex;
}
}

componentWillUnmount() {
Expand Down
13 changes: 12 additions & 1 deletion src/__tests__/Modal.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { mount } from 'enzyme';
import { mount, shallow } from 'enzyme';
import { Modal, ModalBody } from '../';

describe('Modal', () => {
Expand Down Expand Up @@ -737,4 +737,15 @@ describe('Modal', () => {
expect(onEnter).not.toHaveBeenCalled();
expect(onExit).toHaveBeenCalled();
});

it('should update element z index when prop changes', () => {
const wrapper = shallow(
<Modal isOpen zIndex={0}>
Yo!
</Modal>
);
expect(wrapper.instance()._element.style.zIndex).toBe('0');
wrapper.setProps({ zIndex: 1 });
expect(wrapper.instance()._element.style.zIndex).toBe('1');
});
});

0 comments on commit 01667c1

Please sign in to comment.