-
Notifications
You must be signed in to change notification settings - Fork 886
[EuiComboBox] Added sortMatchesBy prop
#3089
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
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5bcab2d
added startingWith prop to combobox
anishagg17 d694a01
Update CHANGELOG.md
anishagg17 7dd4c4c
Update src/components/combo_box/combo_box.tsx
anishagg17 2c3b02e
updated prop
anishagg17 38c34f7
Merge branch 'master' into combo
anishagg17 62ac181
Merge branch 'master' into combo
anishagg17 6c8e6ab
added test
anishagg17 b58d3a4
Update src-docs/src/views/combo_box/combo_box_example.js
anishagg17 c52d5d9
Update src-docs/src/views/combo_box/combo_box_example.js
anishagg17 a43e564
Update src/components/combo_box/combo_box.test.tsx
anishagg17 b8c3061
Update src/components/combo_box/combo_box.test.tsx
anishagg17 88a10e9
resolved eslint errors
anishagg17 68e32db
Merge branch 'master' into combo
anishagg17 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
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,97 @@ | ||
| import React, { Component } from 'react'; | ||
|
|
||
| import { EuiComboBox } from '../../../../src/components'; | ||
|
|
||
| export default class extends Component { | ||
| constructor(props) { | ||
| super(props); | ||
|
|
||
| this.options = [ | ||
| { | ||
| label: 'Titan', | ||
| 'data-test-subj': 'titanOption', | ||
| }, | ||
| { | ||
| label: 'Enceladus is disabled', | ||
| disabled: true, | ||
| }, | ||
| { | ||
| 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', | ||
| }, | ||
| ]; | ||
|
|
||
| this.state = { | ||
| selectedOptions: [this.options[2], this.options[4]], | ||
| }; | ||
| } | ||
|
|
||
| onChange = selectedOptions => { | ||
| this.setState({ | ||
| selectedOptions, | ||
| }); | ||
| }; | ||
|
|
||
| onCreateOption = (searchValue, flattenedOptions) => { | ||
| const normalizedSearchValue = searchValue.trim().toLowerCase(); | ||
|
|
||
| if (!normalizedSearchValue) { | ||
| return; | ||
| } | ||
|
|
||
| const newOption = { | ||
| label: searchValue, | ||
| }; | ||
|
|
||
| // Create the option if it doesn't exist. | ||
| if ( | ||
| flattenedOptions.findIndex( | ||
| option => option.label.trim().toLowerCase() === normalizedSearchValue | ||
| ) === -1 | ||
| ) { | ||
| this.options.push(newOption); | ||
| } | ||
|
|
||
| // Select the option. | ||
| this.setState(prevState => ({ | ||
| selectedOptions: prevState.selectedOptions.concat(newOption), | ||
| })); | ||
| }; | ||
|
|
||
| render() { | ||
| const { selectedOptions } = this.state; | ||
| return ( | ||
| <EuiComboBox | ||
| sortMatchesBy="startsWith" | ||
| placeholder="Select or create options" | ||
| options={this.options} | ||
| selectedOptions={selectedOptions} | ||
| onChange={this.onChange} | ||
| onCreateOption={this.onCreateOption} | ||
| isClearable={true} | ||
| data-test-subj="demoComboBox" | ||
| /> | ||
| ); | ||
| } | ||
| } |
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
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.