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

Fix event handling when input name='nodeName' #6311

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 5 additions & 9 deletions src/renderers/dom/client/ReactInputSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ function isInDocument(node) {
var ReactInputSelection = {

hasSelectionCapabilities: function(elem) {
var nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase();
return nodeName && (
(nodeName === 'input' && elem.type === 'text') ||
nodeName === 'textarea' ||
elem.contentEditable === 'true'
);
return elem instanceof window.HTMLTextAreaElement ||
(elem instanceof window.HTMLInputElement && elem.type === 'text') ||
elem.contentEditable === 'true';
},

getSelectionInformation: function() {
Expand Down Expand Up @@ -85,8 +82,7 @@ var ReactInputSelection = {
start: input.selectionStart,
end: input.selectionEnd,
};
} else if (document.selection &&
(input.nodeName && input.nodeName.toLowerCase() === 'input')) {
} else if (document.selection && input instanceof window.HTMLInputElement) {
// IE8 input.
var range = document.selection.createRange();
// There can only be one selection per document in IE, so it must
Expand Down Expand Up @@ -122,7 +118,7 @@ var ReactInputSelection = {
input.selectionStart = start;
input.selectionEnd = Math.min(end, input.value.length);
} else if (document.selection &&
(input.nodeName && input.nodeName.toLowerCase() === 'input')) {
input instanceof window.HTMLInputElement) {
var range = input.createTextRange();
range.collapse(true);
range.moveStart('character', start);
Expand Down
7 changes: 3 additions & 4 deletions src/renderers/dom/client/eventPlugins/ChangeEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ var activeElementValueProp = null;
* SECTION: handle `change` event
*/
function shouldUseChangeEvent(elem) {
var nodeName = elem.nodeName && elem.nodeName.toLowerCase();
return (
nodeName === 'select' ||
(nodeName === 'input' && elem.type === 'file')
elem instanceof window.HTMLSelectElement ||
(elem instanceof window.HTMLInputElement && elem.type === 'file')
);
}

Expand Down Expand Up @@ -307,7 +306,7 @@ function shouldUseClickEvent(elem) {
// This approach works across all browsers, whereas `change` does not fire
// until `blur` in IE8.
return (
(elem.nodeName && elem.nodeName.toLowerCase() === 'input') &&
(elem instanceof window.HTMLInputElement) &&
(elem.type === 'checkbox' || elem.type === 'radio')
);
}
Expand Down
7 changes: 3 additions & 4 deletions src/shared/utils/isTextInputElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ var supportedInputTypes = {
};

function isTextInputElement(elem) {
var nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase();
return nodeName && (
(nodeName === 'input' && supportedInputTypes[elem.type]) ||
nodeName === 'textarea'
return (
elem instanceof window.HTMLTextAreaElement ||
(elem instanceof window.HTMLInputElement && supportedInputTypes[elem.type])
);
}

Expand Down