-
Notifications
You must be signed in to change notification settings - Fork 47.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switching the name property preserves radio selection
Fixes a case where changing the name and checked value of a radio button in the same update would lead to checking the wrong radio input. Also adds a DOM test fixture for related issue. Related issues: #7630
- Loading branch information
Showing
5 changed files
with
124 additions
and
8 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
fixtures/dom/src/components/fixtures/input-change-events/RadioNameChangeFixture.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const React = window.React; | ||
const noop = n => n; | ||
|
||
class RadioNameChangeFixture extends React.Component { | ||
state = { | ||
updated: false, | ||
}; | ||
onClick = () => { | ||
this.setState(state => { | ||
return {updated: !state.updated}; | ||
}); | ||
}; | ||
render() { | ||
const {updated} = this.state; | ||
const radioName = updated ? 'firstName' : 'secondName'; | ||
return ( | ||
<div> | ||
<label> | ||
<input | ||
type="radio" | ||
name={radioName} | ||
onChange={noop} | ||
checked={updated === true} | ||
/> | ||
First Radio | ||
</label> | ||
|
||
<label> | ||
<input | ||
type="radio" | ||
name={radioName} | ||
onChange={noop} | ||
checked={updated === false} | ||
/> | ||
Second Radio | ||
</label> | ||
|
||
<div> | ||
<button type="button" onClick={this.onClick}>Toggle</button> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default RadioNameChangeFixture; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters