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

Use the same value synchronization function on number blur #11746

Merged
merged 1 commit into from
Dec 2, 2017
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
2 changes: 1 addition & 1 deletion packages/react-dom/src/client/ReactDOMFiberInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ function updateNamedCousins(rootNode, props) {
// when the user is inputting text
//
// https://github.com/facebook/react/issues/7253
function synchronizeDefaultValue(
export function synchronizeDefaultValue(
node: InputWithWrapperState,
type: ?string,
value: *,
Expand Down
6 changes: 2 additions & 4 deletions packages/react-dom/src/events/ChangeEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import getEventTarget from './getEventTarget';
import isEventSupported from './isEventSupported';
import {getNodeFromInstance} from '../client/ReactDOMComponentTree';
import * as inputValueTracking from '../client/inputValueTracking';
import {synchronizeDefaultValue} from '../client/ReactDOMFiberInput';

var eventTypes = {
change: {
Expand Down Expand Up @@ -235,10 +236,7 @@ function handleControlledInputBlur(inst, node) {
}

// If controlled, assign the value attribute to the current value on blur
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment misleading now?

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 don't think so. Though the controlled input guard triggers above this line. It is not apart of this specific block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But you asked! So we could probably improve it. Something like:

// Focused number inputs do not update their defaultValue on change. This
// avoids unexpected value changes in Chrome while the user is typing. On blur,
// we need to synchronize the defaultValue to match standard input behavior.

let value = '' + node.value;
if (node.getAttribute('value') !== value) {
node.setAttribute('value', value);
}
synchronizeDefaultValue(node, 'number', node.value);
}

/**
Expand Down