-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
bug fix on input radio #11227
bug fix on input radio #11227
Changes from 5 commits
4ce1fb0
0e15659
6f3a000
aad2f64
03b1b30
69cbb05
25c0fc4
e03b117
9ee15eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -810,6 +810,13 @@ export function updateProperties( | |
lastRawProps: Object, | ||
nextRawProps: Object, | ||
): void { | ||
// Update checked *before* name. | ||
// In the middle of an update, it is possible to have multiple checked. | ||
// When a checked radio tries to change name, browser makes another radio's checked false. | ||
if (tag === 'input') { | ||
ReactDOMFiberInput.updateChecked(domElement, nextRawProps, 'radio'); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm trying to figure out why this is necessary (but it is definitely effective).
@jquense It feels like there's something deeper here that we need to fix. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think updateNamedCousins is called only on the button because of this code |
||
|
||
var wasCustomComponentTag = isCustomComponent(tag, lastRawProps); | ||
var isCustomComponentTag = isCustomComponent(tag, nextRawProps); | ||
// Apply the diff. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,6 +144,24 @@ export function initWrapperState(element: Element, props: Object) { | |
}; | ||
} | ||
|
||
export function updateChecked( | ||
element: Element, | ||
props: Object, | ||
targetType: ?string, | ||
) { | ||
var node = ((element: any): InputWithWrapperState); | ||
if (!targetType || targetType === node.type) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In function updateNamedCousins(rootNode, props) {
var name = props.name;
if (props.type === 'radio' && name != null) {
// ...
}
// ...
} Can you use that check here? That would allow us to remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the code in updateProperties because updateWrapper also calls updateChecked |
||
var checked = props.checked; | ||
if (checked != null) { | ||
DOMPropertyOperations.setValueForProperty( | ||
node, | ||
'checked', | ||
checked || false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kind of a bummer that we have to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also think it's unnecessary. |
||
); | ||
} | ||
} | ||
} | ||
|
||
export function updateWrapper(element: Element, props: Object) { | ||
var node = ((element: any): InputWithWrapperState); | ||
if (__DEV__) { | ||
|
@@ -183,14 +201,7 @@ export function updateWrapper(element: Element, props: Object) { | |
} | ||
} | ||
|
||
var checked = props.checked; | ||
if (checked != null) { | ||
DOMPropertyOperations.setValueForProperty( | ||
node, | ||
'checked', | ||
checked || false, | ||
); | ||
} | ||
updateChecked(element, props); | ||
|
||
var value = props.value; | ||
if (value != null) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind rephrasing this to
should check the correct radio when the selected name moves?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. yours is better