-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated EuiComboBox to allow the options list to open for single sele…
…ction custom options (#3706) * Fixing includes to return true when object exists in array * changelog * Allowing list to open for single selection custom options * Updated changelog * PR review * Improving example * Improving example * Addind isClearable * Improving examples * Improving explanation text * Adding note * Addressing PR issues * Update src-docs/src/views/combo_box/combo_box_example.js Co-authored-by: Caroline Horn <[email protected]> * Update src-docs/src/views/combo_box/combo_box_example.js Co-authored-by: Caroline Horn <[email protected]> * Snippet Co-authored-by: Caroline Horn <[email protected]>
- Loading branch information
1 parent
0c69cad
commit 518419c
Showing
5 changed files
with
117 additions
and
25 deletions.
There are no files selected for viewing
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
67 changes: 67 additions & 0 deletions
67
src-docs/src/views/combo_box/single_selection_custom_options.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,67 @@ | ||
import React, { useState } from 'react'; | ||
|
||
import { EuiComboBox, EuiFormRow } from '../../../../src/components'; | ||
|
||
const options = [ | ||
{ | ||
label: 'Software Developer', | ||
'data-test-subj': 'softDevOption', | ||
}, | ||
{ | ||
label: 'Mobile Developer', | ||
}, | ||
{ | ||
label: 'Javascript Engineer', | ||
}, | ||
{ | ||
label: 'UX Designer', | ||
}, | ||
{ | ||
label: 'UI Designer', | ||
}, | ||
{ | ||
label: 'Product Designer', | ||
}, | ||
{ | ||
label: 'QA Engineer', | ||
}, | ||
]; | ||
|
||
export default () => { | ||
const [selectedOptions, setSelected] = useState([options[2]]); | ||
|
||
const onChange = selectedOptions => { | ||
// We should only get back either 0 or 1 options. | ||
setSelected(selectedOptions); | ||
}; | ||
|
||
const onCreateOption = (searchValue = []) => { | ||
const normalizedSearchValue = searchValue.trim().toLowerCase(); | ||
|
||
if (!normalizedSearchValue) { | ||
return; | ||
} | ||
|
||
const newOption = { | ||
label: searchValue, | ||
}; | ||
|
||
// Select the option. | ||
setSelected([newOption]); | ||
}; | ||
|
||
return ( | ||
<EuiFormRow | ||
label="Your occupation" | ||
helpText="Select an occupation from the list. If your occupation isn’t available, create a custom one."> | ||
<EuiComboBox | ||
placeholder="Select a single occupation" | ||
singleSelection={{ asPlainText: true }} | ||
options={options} | ||
selectedOptions={selectedOptions} | ||
onChange={onChange} | ||
onCreateOption={onCreateOption} | ||
/> | ||
</EuiFormRow> | ||
); | ||
}; |
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