Skip to content

Commit aab0cc9

Browse files
sjolicoeurpivotal
authored andcommitted
close modal on mousedown on the .modal [#152286689]
1 parent 6765033 commit aab0cc9

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

spec/pivotal-ui-react/modals/modals_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ describe('BaseModal', () => {
202202

203203
it('is triggered when the backdrop is clicked', () => {
204204
result = renderIntoDom({show: true, onHide, animation: false});
205-
$('.modal').click();
205+
$('.modal').simulate('mouseDown');
206206
expect(onHide).toHaveBeenCalledWith(jasmine.anything());
207207
});
208208

src/react/modals/modals.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const privates = new WeakMap();
1212
function bodyNotAllowedToScroll(document) {
1313
if (typeof document !== 'object') return;
1414
const body = document.getElementsByTagName('body')[0];
15-
if(!body.classList.contains('pui-no-scroll')) {
15+
if (!body.classList.contains('pui-no-scroll')) {
1616
body.classList.add('pui-no-scroll');
1717
}
1818
}
@@ -40,7 +40,8 @@ export class BaseModal extends mixin(React.PureComponent).with(Animation) {
4040
acquireFocus: true,
4141
animation: true,
4242
keyboard: true,
43-
onHide: () => {},
43+
onHide: () => {
44+
},
4445
getDocument: () => global.document
4546
};
4647

@@ -59,13 +60,13 @@ export class BaseModal extends mixin(React.PureComponent).with(Animation) {
5960
}
6061

6162
modalClicked = e => {
62-
if(!this.dialog) return;
63-
if(this.dialog.contains(e.target)) return;
63+
if (!this.dialog) return;
64+
if (this.dialog.contains(e.target)) return;
6465
this.props.onHide(e);
6566
};
6667

6768
onKeyDown = e => {
68-
if(this.props.keyboard && e.keyCode === ESC_KEY) {
69+
if (this.props.keyboard && e.keyCode === ESC_KEY) {
6970
this.props.onHide(e);
7071
}
7172
};
@@ -115,22 +116,22 @@ export class BaseModal extends mixin(React.PureComponent).with(Animation) {
115116

116117
privates.set(this, {...privates.get(this), fractionShown});
117118

118-
if(oldFractionShown < 1 && fractionShown === 1) {
119+
if (oldFractionShown < 1 && fractionShown === 1) {
119120
if (acquireFocus) this.focus();
120121
onEntered && onEntered();
121122
}
122123

123-
if(oldFractionShown > 0 && fractionShown === 0) {
124+
if (oldFractionShown > 0 && fractionShown === 0) {
124125
onExited && onExited();
125126
}
126127

127-
if(fractionShown === 0 && !show) return null;
128+
if (fractionShown === 0 && !show) return null;
128129

129130
const props = mergeProps(modalProps, {
130131
className: 'modal fade in',
131132
role: 'dialog',
132133
style: {display: 'block'},
133-
onClick: this.modalClicked,
134+
onMouseDown: this.modalClicked,
134135
tabIndex: -1
135136
});
136137

@@ -144,15 +145,16 @@ export class BaseModal extends mixin(React.PureComponent).with(Animation) {
144145
return (
145146
<div className="modal-wrapper" role="dialog">
146147
<div className="modal-backdrop fade in" style={{opacity: fractionShown * 0.8}} onClick={onHide}/>
147-
<div {...props} ref={ref => this.modal = ref}>
148-
<div className={classnames('modal-dialog', dialogClassName, {[modalSizeClass]: modalSize})} style={dialogStyle} ref={ref => this.dialog = ref}>
149-
<div className="modal-content">
150-
<div className="modal-header">
151-
<h3 className="modal-title em-high">{title}</h3>
152-
<div className="modal-close">
153-
<button className="btn btn-icon" onClick={onHide}>
154-
<Icon src="close"/>
155-
</button>
148+
<div {...props} ref={ref => this.modal = ref}>
149+
<div className={classnames('modal-dialog', dialogClassName, {[modalSizeClass]: modalSize})}
150+
style={dialogStyle} ref={ref => this.dialog = ref}>
151+
<div className="modal-content">
152+
<div className="modal-header">
153+
<h3 className="modal-title em-high">{title}</h3>
154+
<div className="modal-close">
155+
<button className="btn btn-icon" onClick={onHide}>
156+
<Icon src="close"/>
157+
</button>
156158
</div>
157159
</div>
158160
{children}

0 commit comments

Comments
 (0)