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

Add support for "invalid" event within Form elements #5187

Merged
merged 1 commit into from
Oct 17, 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
8 changes: 8 additions & 0 deletions src/renderers/dom/client/eventPlugins/SimpleEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ var eventTypes = {
captured: keyOf({onInputCapture: true}),
},
},
invalid: {
phasedRegistrationNames: {
bubbled: keyOf({onInvalid: true}),
captured: keyOf({onInvalidCapture: true}),
},
},
keyDown: {
phasedRegistrationNames: {
bubbled: keyOf({onKeyDown: true}),
Expand Down Expand Up @@ -404,6 +410,7 @@ var topLevelEventsToDispatchConfig = {
topError: eventTypes.error,
topFocus: eventTypes.focus,
topInput: eventTypes.input,
topInvalid: eventTypes.invalid,
topKeyDown: eventTypes.keyDown,
topKeyPress: eventTypes.keyPress,
topKeyUp: eventTypes.keyUp,
Expand Down Expand Up @@ -480,6 +487,7 @@ var SimpleEventPlugin = {
case topLevelTypes.topEnded:
case topLevelTypes.topError:
case topLevelTypes.topInput:
case topLevelTypes.topInvalid:
case topLevelTypes.topLoad:
case topLevelTypes.topLoadedData:
case topLevelTypes.topLoadedMetadata:
Expand Down
32 changes: 28 additions & 4 deletions src/renderers/dom/shared/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,17 @@ function trapBubbledEventsLocal() {
),
];
break;
case 'input':
case 'select':
case 'textarea':
inst._wrapperState.listeners = [
ReactBrowserEventEmitter.trapBubbledEvent(
EventConstants.topLevelTypes.topInvalid,
'invalid',
node
),
];
break;
}
}

Expand Down Expand Up @@ -557,15 +568,13 @@ ReactDOMComponent.Mixin = {
case 'form':
case 'video':
case 'audio':
this._wrapperState = {
listeners: null,
};
transaction.getReactMountReady().enqueue(trapBubbledEventsLocal, this);
this._setupTrapBubbledEventsLocal(transaction);
break;
case 'button':
props = ReactDOMButton.getNativeProps(this, props, nativeParent);
break;
case 'input':
this._setupTrapBubbledEventsLocal(transaction);
ReactDOMInput.mountWrapper(this, props, nativeParent);
props = ReactDOMInput.getNativeProps(this, props);
break;
Expand All @@ -574,10 +583,12 @@ ReactDOMComponent.Mixin = {
props = ReactDOMOption.getNativeProps(this, props);
break;
case 'select':
this._setupTrapBubbledEventsLocal(transaction);
ReactDOMSelect.mountWrapper(this, props, nativeParent);
props = ReactDOMSelect.getNativeProps(this, props);
break;
case 'textarea':
this._setupTrapBubbledEventsLocal(transaction);
ReactDOMTextarea.mountWrapper(this, props, nativeParent);
props = ReactDOMTextarea.getNativeProps(this, props);
break;
Expand Down Expand Up @@ -686,6 +697,19 @@ ReactDOMComponent.Mixin = {
return mountImage;
},

/**
* Setup this component to trap non-bubbling events locally
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this description suffices but I didn't know how else to describe what it does!

*
* @private
* @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
*/
_setupTrapBubbledEventsLocal: function(transaction) {
this._wrapperState = {
listeners: null,
};
transaction.getReactMountReady().enqueue(trapBubbledEventsLocal, this);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mountWrapper calls in input, select, and textarea should include the listeners property in their _wrapperState to avoid changing the hidden class when the assignment is made. This would also be better just as a free function – we're trying to get away from OO in the core anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spicyj Makes sense - probably worth raising a separate issue for this as this PR is now merged

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's merged. I was hoping that one of you would want to post a PR to fix it but I did it myself in #5213.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool - thank you!

},

/**
* Creates markup for the open tag and all attributes.
*
Expand Down
1 change: 1 addition & 0 deletions src/renderers/shared/event/EventConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var topLevelTypes = keyMirror({
topError: null,
topFocus: null,
topInput: null,
topInvalid: null,
topKeyDown: null,
topKeyPress: null,
topKeyUp: null,
Expand Down