Skip to content

Commit 2d7d029

Browse files
[Modal] Remove the defaultPrevented logic
1 parent d1a7d76 commit 2d7d029

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

packages/material-ui/src/Modal/Modal.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,13 @@ class Modal extends React.Component {
156156
};
157157

158158
handleKeyDown = event => {
159-
// event.defaultPrevented:
159+
// We don't take event.defaultPrevented into account:
160160
//
161-
// Ignore events that have been `event.preventDefault()` marked.
162-
// preventDefault() is meant to stop default behaviours like
161+
// event.preventDefault() is meant to stop default behaviours like
163162
// clicking a checkbox to check it, hitting a button to submit a form,
164163
// and hitting left arrow to move the cursor in a text input etc.
165-
// Only special HTML elements have these default bahaviours.
166-
//
167-
// To remove in v4.
168-
if (event.key !== 'Escape' || !this.isTopModal() || event.defaultPrevented) {
164+
// Only special HTML elements have these default behaviors.
165+
if (event.key !== 'Escape' || !this.isTopModal()) {
169166
return;
170167
}
171168

packages/material-ui/src/Modal/Modal.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,15 @@ describe('<Modal />', () => {
324324
assert.strictEqual(onCloseSpy.callCount, 0);
325325
});
326326

327-
it('should not be call when defaultPrevented', () => {
327+
it('should be call when defaultPrevented', () => {
328328
topModalStub.returns(true);
329329
wrapper.setProps({ disableEscapeKeyDown: true, manager: { isTopModal: topModalStub } });
330330
event = { key: 'Escape', defaultPrevented: true };
331331

332332
instance.handleKeyDown(event);
333333
assert.strictEqual(topModalStub.callCount, 1);
334-
assert.strictEqual(onEscapeKeyDownSpy.callCount, 0);
335-
assert.strictEqual(onCloseSpy.callCount, 0);
334+
assert.strictEqual(onEscapeKeyDownSpy.callCount, 1);
335+
assert.strictEqual(onCloseSpy.callCount, 1);
336336
});
337337
});
338338

0 commit comments

Comments
 (0)