Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ReactDOMButton #4030

Merged
merged 1 commit into from
Jun 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 15 additions & 27 deletions src/renderers/dom/client/wrappers/ReactDOMButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,40 @@

'use strict';

var AutoFocusUtils = require('AutoFocusUtils');
var ReactBrowserComponentMixin = require('ReactBrowserComponentMixin');
var ReactClass = require('ReactClass');
var ReactElement = require('ReactElement');

var keyMirror = require('keyMirror');

var button = ReactElement.createFactory('button');

var mouseListenerNames = keyMirror({
var mouseListenerNames = {
onClick: true,
onDoubleClick: true,
onMouseDown: true,
onMouseMove: true,
onMouseUp: true,

onClickCapture: true,
onDoubleClickCapture: true,
onMouseDownCapture: true,
onMouseMoveCapture: true,
onMouseUpCapture: true,
});
};

/**
* Implements a <button> native component that does not receive mouse events
* when `disabled` is set.
*/
var ReactDOMButton = ReactClass.createClass({
displayName: 'ReactDOMButton',
tagName: 'BUTTON',

mixins: [AutoFocusUtils.Mixin, ReactBrowserComponentMixin],

render: function() {
var props = {};
var ReactDOMButton = {
getNativeProps: function(inst, props, context) {
if (!props.disabled) {
return props;
}

// Copy the props; except the mouse listeners if we're disabled
for (var key in this.props) {
if (this.props.hasOwnProperty(key) &&
(!this.props.disabled || !mouseListenerNames[key])) {
props[key] = this.props[key];
// Copy the props, except the mouse listeners
var nativeProps = {};
for (var key in props) {
if (props.hasOwnProperty(key) && !mouseListenerNames[key]) {
nativeProps[key] = props[key];
}
}

return button(props, this.props.children);
return nativeProps;
},

});
};

module.exports = ReactDOMButton;
9 changes: 9 additions & 0 deletions src/renderers/dom/shared/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var DOMPropertyOperations = require('DOMPropertyOperations');
var ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
var ReactComponentBrowserEnvironment =
require('ReactComponentBrowserEnvironment');
var ReactDOMButton = require('ReactDOMButton');
var ReactDOMInput = require('ReactDOMInput');
var ReactDOMTextarea = require('ReactDOMTextarea');
var ReactMount = require('ReactMount');
Expand Down Expand Up @@ -284,6 +285,9 @@ ReactDOMComponent.Mixin = {
var props = this._currentElement.props;

switch (this._tag) {
case 'button':
props = ReactDOMButton.getNativeProps(this, props, context);
break;
case 'input':
ReactDOMInput.mountWrapper(this, props);
props = ReactDOMInput.getNativeProps(this, props, context);
Expand All @@ -309,6 +313,7 @@ ReactDOMComponent.Mixin = {
var tagContent = this._createContentMarkup(transaction, props, context);

switch (this._tag) {
case 'button':
case 'input':
case 'textarea':
if (props.autoFocus) {
Expand Down Expand Up @@ -465,6 +470,10 @@ ReactDOMComponent.Mixin = {
var nextProps = this._currentElement.props;

switch (this._tag) {
case 'button':
lastProps = ReactDOMButton.getNativeProps(this, lastProps);
nextProps = ReactDOMButton.getNativeProps(this, nextProps);
break;
case 'input':
ReactDOMInput.updateWrapper(this);
lastProps = ReactDOMInput.getNativeProps(this, lastProps);
Expand Down
2 changes: 0 additions & 2 deletions src/renderers/dom/shared/ReactDefaultInjection.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ var ReactComponentBrowserEnvironment =
require('ReactComponentBrowserEnvironment');
var ReactDefaultBatchingStrategy = require('ReactDefaultBatchingStrategy');
var ReactDOMComponent = require('ReactDOMComponent');
var ReactDOMButton = require('ReactDOMButton');
var ReactDOMForm = require('ReactDOMForm');
var ReactDOMImg = require('ReactDOMImg');
var ReactDOMIDOperations = require('ReactDOMIDOperations');
Expand Down Expand Up @@ -110,7 +109,6 @@ function inject() {
ReactInjection.Class.injectMixin(ReactBrowserComponentMixin);

ReactInjection.NativeComponent.injectComponentClasses({
'button': ReactDOMButton,
'form': ReactDOMForm,
'iframe': ReactDOMIframe,
'img': ReactDOMImg,
Expand Down