-
Notifications
You must be signed in to change notification settings - Fork 895
Updated EuiComboBox to allow the options list to open for single selection custom options #3706
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
Merged
elizabetdev
merged 20 commits into
elastic:master
from
elizabetdev:single-selection-options-list-not-opening-bug
Jul 17, 2020
Merged
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4a0d20e
Fixing includes to return true when object exists in array
elizabetdev 76752a2
changelog
elizabetdev 118d27d
Merge remote-tracking branch 'upstream/master' into single-selection-…
elizabetdev 0cfa854
Allowing list to open for single selection custom options
elizabetdev ffddd6a
Updated changelog
elizabetdev b14665e
Merge remote-tracking branch 'upstream/master' into single-selection-…
elizabetdev a0f7ae8
Merge remote-tracking branch 'upstream/master' into single-selection-…
elizabetdev bc2f620
PR review
elizabetdev f1f26be
Improving example
elizabetdev 39d2e33
Improving example
elizabetdev a7e9b12
Addind isClearable
elizabetdev 23a0b10
Improving examples
elizabetdev 3c07460
Improving explanation text
elizabetdev 16bca05
Adding note
elizabetdev 4612cc1
Merge remote-tracking branch 'upstream/master' into single-selection-…
elizabetdev 4426ccf
Addressing PR issues
elizabetdev aa7d31a
Update src-docs/src/views/combo_box/combo_box_example.js
elizabetdev a4ff6a3
Merge branch 'single-selection-options-list-not-opening-bug' of https…
elizabetdev 70f067c
Update src-docs/src/views/combo_box/combo_box_example.js
elizabetdev 0720266
Snippet
elizabetdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
91 changes: 91 additions & 0 deletions
91
src-docs/src/views/combo_box/single_selection_custom_options.js
This file contains hidden or 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,91 @@ | ||
| import React, { useState } from 'react'; | ||
|
|
||
| import { EuiComboBox } from '../../../../src/components'; | ||
| import { DisplayToggles } from '../form_controls/display_toggles'; | ||
|
|
||
| const options = [ | ||
| { | ||
| label: 'Titan', | ||
| 'data-test-subj': 'titanOption', | ||
| }, | ||
| { | ||
| label: 'Enceladus', | ||
| }, | ||
| { | ||
| label: 'Mimas', | ||
| }, | ||
| { | ||
| label: 'Dione', | ||
| }, | ||
| { | ||
| label: 'Iapetus', | ||
| }, | ||
| { | ||
| label: 'Phoebe', | ||
| }, | ||
| { | ||
| label: 'Rhea', | ||
| }, | ||
| { | ||
| label: | ||
| "Pandora is one of Saturn's moons, named for a Titaness of Greek mythology", | ||
| }, | ||
| { | ||
| label: 'Tethys', | ||
| }, | ||
| { | ||
| label: 'Hyperion', | ||
| }, | ||
| ]; | ||
|
|
||
| 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, flattenedOptions = []) => { | ||
| const normalizedSearchValue = searchValue.trim().toLowerCase(); | ||
|
|
||
| if (!normalizedSearchValue) { | ||
| return; | ||
| } | ||
|
|
||
| const newOption = { | ||
| label: searchValue, | ||
| }; | ||
|
|
||
| // Create the option if it doesn't exist. | ||
| if ( | ||
|
elizabetdev marked this conversation as resolved.
Outdated
|
||
| flattenedOptions.findIndex( | ||
| option => option.label.trim().toLowerCase() === normalizedSearchValue | ||
| ) === -1 | ||
| ) { | ||
| options.push(newOption); | ||
| } | ||
|
|
||
| // Select the option. | ||
| setSelected([newOption]); | ||
| }; | ||
|
|
||
| return ( | ||
| <DisplayToggles | ||
| canDisabled={false} | ||
| canReadOnly={false} | ||
| canLoading={false} | ||
| canPrepend | ||
| canAppend> | ||
| <EuiComboBox | ||
| placeholder="Select a single option" | ||
| singleSelection={{ asPlainText: true }} | ||
| options={options} | ||
| selectedOptions={selectedOptions} | ||
| onChange={onChange} | ||
| onCreateOption={onCreateOption} | ||
| isClearable={false} | ||
| /> | ||
| </DisplayToggles> | ||
| ); | ||
| }; | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.