-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added delimenator prop * Entering delimeator hits enter functionality added * added docs example, CL * prettified * removed console.log() * added copy functionality * added test,snap * removed copy button * removed copy button * Update src-docs/src/views/combo_box/combo_box_example.js Co-Authored-By: Caroline Horn <[email protected]> * Update src/components/combo_box/combo_box.tsx Co-Authored-By: Caroline Horn <[email protected]> * fixed only first gets entered * updated text * indent fix * Update combo_box_options_list.tsx * Update src/components/combo_box/combo_box_options_list/combo_box_options_list.tsx Co-Authored-By: Caroline Horn <[email protected]> * removed empty string * removed redundant code Co-authored-by: Caroline Horn <[email protected]>
- Loading branch information
1 parent
c91fb39
commit 2bc9917
Showing
7 changed files
with
232 additions
and
16 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
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 | ||
placeholder="Select or create options" | ||
options={this.options} | ||
delimiter="," | ||
selectedOptions={selectedOptions} | ||
onChange={this.onChange} | ||
onCreateOption={this.onCreateOption} | ||
isClearable={true} | ||
data-test-subj="demoComboBox" | ||
/> | ||
); | ||
} | ||
} |
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
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