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 uncontrolled radios #10156

Merged
merged 6 commits into from
Jul 13, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add fixture
  • Loading branch information
jquense committed Jul 12, 2017
commit ce70f13629f8044b7df42c728095f514bf02dba3
4 changes: 2 additions & 2 deletions fixtures/dom/public/react-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ var query = parseQuery(window.location.search);
var version = query.version || 'local';

if (version !== 'local') {
REACT_PATH = 'https://unpkg.com/react@' + version + '/dist/react.min.js';
DOM_PATH = 'https://unpkg.com/react-dom@' + version + '/dist/react-dom.min.js';
REACT_PATH = 'https://unpkg.com/react@' + version + '/dist/react.js';
DOM_PATH = 'https://unpkg.com/react-dom@' + version + '/dist/react-dom.js';
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 switched to the unminified versions intentionally so was easier to step through stuff in devtools

}

document.write('<script src="' + REACT_PATH + '"></script>');
Expand Down
20 changes: 16 additions & 4 deletions fixtures/dom/src/components/TestCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const propTypes = {
children: PropTypes.node.isRequired,
title: PropTypes.node.isRequired,
resolvedIn: semverString,
introducedIn: semverString,
resolvedBy: PropTypes.string
};

Expand All @@ -31,6 +32,7 @@ class TestCase extends React.Component {
const {
title,
description,
introducedIn,
resolvedIn,
resolvedBy,
affectedBrowsers,
Expand All @@ -40,13 +42,13 @@ class TestCase extends React.Component {
let { complete } = this.state;

const { version } = parse(window.location.search);
const isTestRelevant = (
const isTestFixed = (
!version ||
!resolvedIn ||
semver.gte(version, resolvedIn)
);

complete = !isTestRelevant || complete;
complete = !isTestFixed || complete;
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Last time I do merge conflict resolve on github :P man.


return (
<section
Expand All @@ -68,6 +70,16 @@ class TestCase extends React.Component {
</h2>

<dl className="test-case__details">
{introducedIn && (
<dt>First broken in: </dt>)}
{introducedIn && (
<dd>
<a href={'https://github.com/facebook/react/tag/v' + introducedIn}>
<code>{introducedIn}</code>
</a>
</dd>
)}

{resolvedIn && (
<dt>First supported in: </dt>)}
{resolvedIn && (
Expand Down Expand Up @@ -100,12 +112,12 @@ class TestCase extends React.Component {
</p>

<div className="test-case__body">
{!isTestRelevant &&(
{!isTestFixed && (
<p className="test-case__invalid-version">
<strong>Note:</strong> This test case was fixed in a later version of React.
This test is not expected to pass for the selected version, and that's ok!
</p>
)}
)}

{children}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React from 'react';

import Fixture from '../../Fixture';

class RadioGroupFixture extends React.Component {
constructor(props, context) {
super(props, context);

this.state = {
changeCount: 0,
};
}

handleChange = () => {
this.setState(({ changeCount }) => {
return {
changeCount: changeCount + 1
}
})
}

handleReset = () => {
this.setState({
changeCount: 0,
})
}

render() {
const { changeCount } = this.state;
const color = changeCount === 2 ? 'green' : 'red';

return (
<Fixture>
<label>
<input
defaultChecked
name="foo"
type='radio'
onChange={this.handleChange}
/>
Radio 1
</label>
<label>
<input
name="foo"
type='radio'
onChange={this.handleChange}
/>
Radio 2
</label>

{' '}
<p style={{ color }}>
<code>onChange</code>{' calls: '}<strong>{changeCount}</strong>
</p>
<button onClick={this.handleReset}>Reset count</button>
</Fixture>
)
}
}

export default RadioGroupFixture;
20 changes: 20 additions & 0 deletions fixtures/dom/src/components/fixtures/input-change-events/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import FixtureSet from '../../FixtureSet';
import TestCase from '../../TestCase';
import RangeKeyboardFixture from './RangeKeyboardFixture';
import RadioClickFixture from './RadioClickFixture';
import RadioGroupFixture from './RadioGroupFixture';
import InputPlaceholderFixture from './InputPlaceholderFixture';

class InputChangeEvents extends React.Component {
Expand Down Expand Up @@ -50,6 +51,25 @@ class InputChangeEvents extends React.Component {

<RadioClickFixture />
</TestCase>
<TestCase
title="Uncontrolled radio groups"
description={`
Radio inputs should fire change events when the value moved to
another named input
`}
introducedIn="15.6.0"
>
<TestCase.Steps>
<li>Click on the "Radio 2"</li>
<li>Click back to "Radio 1"</li>
</TestCase.Steps>

<TestCase.ExpectedResult>
The <code>onChange</code> call count should equal 2
</TestCase.ExpectedResult>

<RadioGroupFixture />
</TestCase>

<TestCase
title="Inputs with placeholders"
Expand Down
12 changes: 12 additions & 0 deletions fixtures/dom/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2199,6 +2199,18 @@ fbjs@^0.8.1, fbjs@^0.8.4:
setimmediate "^1.0.5"
ua-parser-js "^0.7.9"

fbjs@^0.8.9:
version "0.8.12"
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.12.tgz#10b5d92f76d45575fd63a217d4ea02bea2f8ed04"
dependencies:
core-js "^1.0.0"
isomorphic-fetch "^2.1.1"
loose-envify "^1.0.0"
object-assign "^4.1.0"
promise "^7.1.1"
setimmediate "^1.0.5"
ua-parser-js "^0.7.9"

figures@^1.3.5:
version "1.7.0"
resolved "https://registry.yarnpkg.com/figures/-/figures-1.7.0.tgz#cbe1e3affcf1cd44b80cadfed28dc793a9701d2e"
Expand Down