|
1 | 1 | const React = window.React;
|
2 | 2 |
|
| 3 | +import Fixture from '../../Fixture'; |
| 4 | +import FixtureSet from '../../FixtureSet'; |
| 5 | +import TestCase from '../../TestCase'; |
| 6 | +import InputTestCase from './InputTestCase'; |
| 7 | + |
3 | 8 | class TextInputFixtures extends React.Component {
|
4 |
| - state = { |
5 |
| - color: '#ffaaee', |
6 |
| - }; |
| 9 | + render() { |
| 10 | + return ( |
| 11 | + <FixtureSet |
| 12 | + title="Inputs" |
| 13 | + description="Common behavior across controled and uncontrolled inputs" |
| 14 | + > |
| 15 | + <TestCase title="Numbers in a controlled text field with no handler"> |
| 16 | + <TestCase.Steps> |
| 17 | + <li>Move the cursor to after "2" in the text field</li> |
| 18 | + <li>Type ".2" into the text input</li> |
| 19 | + </TestCase.Steps> |
7 | 20 |
|
8 |
| - renderControlled = (type) => { |
9 |
| - let id = `controlled_${type}`; |
| 21 | + <TestCase.ExpectedResult> |
| 22 | + The text field's value should not update. |
| 23 | + </TestCase.ExpectedResult> |
10 | 24 |
|
11 |
| - let onChange = e => { |
12 |
| - let value = e.target.value; |
13 |
| - if (type === 'number') { |
14 |
| - value = value === '' ? '' : parseFloat(value, 10) || 0; |
15 |
| - } |
16 |
| - this.setState({ |
17 |
| - [type] : value, |
18 |
| - }); |
19 |
| - }; |
| 25 | + <Fixture> |
| 26 | + <div className="control-box"> |
| 27 | + <fieldset> |
| 28 | + <legend>Value as number</legend> |
| 29 | + <input value={2} onChange={() => {}} /> |
| 30 | + </fieldset> |
20 | 31 |
|
21 |
| - let state = this.state[type] || ''; |
| 32 | + <fieldset> |
| 33 | + <legend>Value as string</legend> |
| 34 | + <input value={"2"} onChange={() => {}} /> |
| 35 | + </fieldset> |
| 36 | + </div> |
| 37 | + </Fixture> |
22 | 38 |
|
23 |
| - return ( |
24 |
| - <div key={type} className="field"> |
25 |
| - <label className="control-label" htmlFor={id}>{type}</label> |
26 |
| - <input id={id} type={type} value={state} onChange={onChange} /> |
27 |
| - → {JSON.stringify(state)} |
28 |
| - </div> |
29 |
| - ); |
30 |
| - } |
| 39 | + <p className="footnote"> |
| 40 | + This issue was first introduced when we added extra logic |
| 41 | + to number inputs to prevent unexpected behavior in Chrome |
| 42 | + and Safari (see the number input test case). |
| 43 | + </p> |
| 44 | + </TestCase> |
31 | 45 |
|
32 |
| - renderUncontrolled = (type) => { |
33 |
| - let id = `uncontrolled_${type}`; |
34 |
| - return ( |
35 |
| - <div key={type} className="field"> |
36 |
| - <label className="control-label" htmlFor={id}>{type}</label> |
37 |
| - <input id={id} type={type} /> |
38 |
| - </div> |
39 |
| - ); |
40 |
| - } |
| 46 | + <TestCase title="Cursor when editing email inputs"> |
| 47 | + <TestCase.Steps> |
| 48 | + |
| 49 | + <li>Select "@"</li> |
| 50 | + <li>Type ".", to replace "@" with a period</li> |
| 51 | + </TestCase.Steps> |
41 | 52 |
|
42 |
| - render() { |
43 |
| - // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input |
44 |
| - let types = [ |
45 |
| - 'text', 'email', 'number', 'url', 'tel', |
46 |
| - 'color', 'date', 'datetime-local', |
47 |
| - 'time', 'month', 'week', 'range', 'password', |
48 |
| - ]; |
49 |
| - return ( |
50 |
| - <form onSubmit={event => event.preventDefault()}> |
51 |
| - <fieldset> |
52 |
| - <legend>Controlled</legend> |
53 |
| - {types.map(this.renderControlled)} |
54 |
| - </fieldset> |
55 |
| - <fieldset> |
56 |
| - <legend>Uncontrolled</legend> |
57 |
| - {types.map(this.renderUncontrolled)} |
58 |
| - </fieldset> |
59 |
| - </form> |
| 53 | + <TestCase.ExpectedResult> |
| 54 | + The text field's cursor should not jump to the end. |
| 55 | + </TestCase.ExpectedResult> |
| 56 | + |
| 57 | + <InputTestCase type="email" defaultValue="" /> |
| 58 | + </TestCase> |
| 59 | + |
| 60 | + <TestCase title="Cursor when editing url inputs"> |
| 61 | + <TestCase.Steps> |
| 62 | + <li>Type "http://www.example.com"</li> |
| 63 | + <li>Select "www."</li> |
| 64 | + <li>Press backspace/delete</li> |
| 65 | + </TestCase.Steps> |
| 66 | + |
| 67 | + <TestCase.ExpectedResult> |
| 68 | + The text field's cursor should not jump to the end. |
| 69 | + </TestCase.ExpectedResult> |
| 70 | + |
| 71 | + <InputTestCase type="url" defaultValue="" /> |
| 72 | + </TestCase> |
| 73 | + |
| 74 | + <TestCase title="All inputs" description="General test of all inputs"> |
| 75 | + <InputTestCase type="text" defaultValue="Text" /> |
| 76 | + <InputTestCase type="email" defaultValue="[email protected]"/> |
| 77 | + <InputTestCase type="number" defaultValue={0} /> |
| 78 | + <InputTestCase type="url" defaultValue="http://example.com"/> |
| 79 | + <InputTestCase type="tel" defaultValue="555-555-5555"/> |
| 80 | + <InputTestCase type="color" defaultValue="#ff0000" /> |
| 81 | + <InputTestCase type="date" defaultValue="2017-01-01" /> |
| 82 | + <InputTestCase type="datetime-local" defaultValue="2017-01-01T01:00" /> |
| 83 | + <InputTestCase type="time" defaultValue="01:00" /> |
| 84 | + <InputTestCase type="month" defaultValue="2017-01" /> |
| 85 | + <InputTestCase type="week" defaultValue="2017-W01" /> |
| 86 | + <InputTestCase type="range" defaultValue={0.5} /> |
| 87 | + <InputTestCase type="password" defaultValue="" /> |
| 88 | + </TestCase> |
| 89 | + </FixtureSet> |
60 | 90 | );
|
61 | 91 | }
|
62 | 92 | }
|
|
0 commit comments