|
1 | 1 | import React, { useState } from 'react'; |
2 | 2 |
|
3 | | -import { EuiComboBox } from '../../../../src/components'; |
4 | | -import { DisplayToggles } from '../form_controls/display_toggles'; |
| 3 | +import { EuiComboBox, EuiFieldText } from '../../../../src/components'; |
5 | 4 |
|
6 | | -const optionsStatic = [ |
7 | | - { |
8 | | - label: 'Titan', |
9 | | - 'data-test-subj': 'titanOption', |
10 | | - }, |
11 | | - { |
12 | | - label: 'Enceladus is disabled', |
13 | | - disabled: true, |
14 | | - }, |
15 | | - { |
16 | | - label: 'Mimas', |
17 | | - }, |
18 | | - { |
19 | | - label: 'Dione', |
20 | | - }, |
21 | | - { |
22 | | - label: 'Iapetus', |
23 | | - }, |
24 | | - { |
25 | | - label: 'Phoebe', |
26 | | - }, |
27 | | - { |
28 | | - label: 'Rhea', |
29 | | - }, |
30 | | - { |
31 | | - label: |
32 | | - "Pandora is one of Saturn's moons, named for a Titaness of Greek mythology", |
33 | | - }, |
34 | | - { |
35 | | - label: 'Tethys', |
36 | | - }, |
37 | | - { |
38 | | - label: 'Hyperion', |
39 | | - }, |
40 | | -]; |
41 | 5 | export default () => { |
42 | | - const [options, setOptions] = useState(optionsStatic); |
43 | | - const [selectedOptions, setSelected] = useState([options[2], options[4]]); |
| 6 | + const [name, setName] = useState(''); |
44 | 7 |
|
45 | | - const onChange = (selectedOptions) => { |
46 | | - setSelected(selectedOptions); |
| 8 | + const onSubmit = (ev) => { |
| 9 | + ev.preventDefault(); |
| 10 | + ev.stopPropagation(); |
| 11 | + window.alert('form submitted'); |
47 | 12 | }; |
48 | 13 |
|
49 | | - const onCreateOption = (searchValue, flattenedOptions = []) => { |
50 | | - const normalizedSearchValue = searchValue.trim().toLowerCase(); |
| 14 | + const options = [ |
| 15 | + { label: 'Chandler', color: 'hotpink' }, |
| 16 | + { label: 'Rachel', color: 'green' }, |
| 17 | + ]; |
51 | 18 |
|
52 | | - if (!normalizedSearchValue) { |
53 | | - return; |
54 | | - } |
55 | | - |
56 | | - const newOption = { |
57 | | - label: searchValue, |
58 | | - }; |
59 | | - |
60 | | - // Create the option if it doesn't exist. |
61 | | - if ( |
62 | | - flattenedOptions.findIndex( |
63 | | - (option) => option.label.trim().toLowerCase() === normalizedSearchValue |
64 | | - ) === -1 |
65 | | - ) { |
66 | | - setOptions([...options, newOption]); |
67 | | - } |
68 | | - |
69 | | - // Select the option. |
70 | | - setSelected([...selectedOptions, newOption]); |
71 | | - }; |
| 19 | + const [selectedOptions, setSelectedOptions] = useState([]); |
72 | 20 |
|
73 | 21 | return ( |
74 | | - /* DisplayToggles wrapper for Docs only */ |
75 | | - <DisplayToggles canDisabled={false} canReadOnly={false}> |
| 22 | + <form onSubmit={onSubmit}> |
| 23 | + <EuiFieldText value={name} onChange={(ev) => setName(ev.target.value)} /> |
76 | 24 | <EuiComboBox |
77 | | - placeholder="Select or create options" |
78 | 25 | options={options} |
| 26 | + onChange={(options) => setSelectedOptions(options)} |
79 | 27 | selectedOptions={selectedOptions} |
80 | | - onChange={onChange} |
81 | | - onCreateOption={onCreateOption} |
82 | | - isClearable={true} |
83 | | - data-test-subj="demoComboBox" |
84 | 28 | /> |
85 | | - </DisplayToggles> |
| 29 | + {/* <input type="submit" /> */} |
| 30 | + </form> |
86 | 31 | ); |
87 | 32 | }; |
0 commit comments