-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6215 from nhunzaker/nh-fix-disabled-inputs
Disabled inputs should not respond to clicks in IE
- Loading branch information
Showing
7 changed files
with
166 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule DisabledInputUtils | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var disableableMouseListenerNames = { | ||
onClick: true, | ||
onDoubleClick: true, | ||
onMouseDown: true, | ||
onMouseMove: true, | ||
onMouseUp: true, | ||
|
||
onClickCapture: true, | ||
onDoubleClickCapture: true, | ||
onMouseDownCapture: true, | ||
onMouseMoveCapture: true, | ||
onMouseUpCapture: true, | ||
}; | ||
|
||
/** | ||
* Implements a native component that does not receive mouse events | ||
* when `disabled` is set. | ||
*/ | ||
var DisabledInputUtils = { | ||
getNativeProps: function(inst, props) { | ||
if (!props.disabled) { | ||
return props; | ||
} | ||
|
||
// Copy the props, except the mouse listeners | ||
var nativeProps = {}; | ||
for (var key in props) { | ||
if (!disableableMouseListenerNames[key] && props.hasOwnProperty(key)) { | ||
nativeProps[key] = props[key]; | ||
} | ||
} | ||
|
||
return nativeProps; | ||
}, | ||
}; | ||
|
||
module.exports = DisabledInputUtils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/renderers/dom/client/wrappers/__tests__/DisabledInputUtil-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* Copyright 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @emails react-core | ||
*/ | ||
|
||
'use strict'; | ||
|
||
|
||
describe('DisabledInputUtils', function() { | ||
var React; | ||
var ReactDOM; | ||
var ReactTestUtils; | ||
|
||
var elements = ['button', 'input', 'select', 'textarea']; | ||
|
||
function expectClickThru(element) { | ||
onClick.mockClear(); | ||
ReactTestUtils.Simulate.click(ReactDOM.findDOMNode(element)); | ||
expect(onClick.mock.calls.length).toBe(1); | ||
} | ||
|
||
function expectNoClickThru(element) { | ||
onClick.mockClear(); | ||
ReactTestUtils.Simulate.click(ReactDOM.findDOMNode(element)); | ||
expect(onClick.mock.calls.length).toBe(0); | ||
} | ||
|
||
function mounted(element) { | ||
element = ReactTestUtils.renderIntoDocument(element); | ||
return element; | ||
} | ||
|
||
var onClick = jest.genMockFn(); | ||
|
||
elements.forEach(function(tagName) { | ||
|
||
describe(tagName, function() { | ||
|
||
beforeEach(function() { | ||
React = require('React'); | ||
ReactDOM = require('ReactDOM'); | ||
ReactTestUtils = require('ReactTestUtils'); | ||
}); | ||
|
||
it('should forward clicks when it starts out not disabled', function() { | ||
var element = React.createElement(tagName, { | ||
onClick: onClick, | ||
}); | ||
|
||
expectClickThru(mounted(element)); | ||
}); | ||
|
||
it('should not forward clicks when it starts out disabled', function() { | ||
var element = React.createElement(tagName, { | ||
onClick: onClick, | ||
disabled: true, | ||
}); | ||
|
||
expectNoClickThru(mounted(element)); | ||
}); | ||
|
||
it('should forward clicks when it becomes not disabled', function() { | ||
var container = document.createElement('div'); | ||
var element = ReactDOM.render( | ||
React.createElement(tagName, { onClick: onClick, disabled: true }), | ||
container | ||
); | ||
element = ReactDOM.render( | ||
React.createElement(tagName, { onClick: onClick }), | ||
container | ||
); | ||
expectClickThru(element); | ||
}); | ||
|
||
it('should not forward clicks when it becomes disabled', function() { | ||
var container = document.createElement('div'); | ||
var element = ReactDOM.render( | ||
React.createElement(tagName, { onClick: onClick }), | ||
container | ||
); | ||
element = ReactDOM.render( | ||
React.createElement(tagName, { onClick: onClick, disabled: true }), | ||
container | ||
); | ||
expectNoClickThru(element); | ||
}); | ||
|
||
it('should work correctly if the listener is changed', function() { | ||
var container = document.createElement('div'); | ||
var element = ReactDOM.render( | ||
React.createElement(tagName, { onClick: onClick, disabled: true }), | ||
container | ||
); | ||
element = ReactDOM.render( | ||
React.createElement(tagName, { onClick: onClick, disabled: false }), | ||
container | ||
); | ||
expectClickThru(element); | ||
}); | ||
}); | ||
}); | ||
}); |
93 changes: 0 additions & 93 deletions
93
src/renderers/dom/client/wrappers/__tests__/ReactDOMButton-test.js
This file was deleted.
Oops, something went wrong.