import * as React from 'react'; import * as classnames from 'classnames'; class Dropdown extends React.Component<{ initialValue?: string, wrapperClassName?: string, wrapperStyle?: any, inputClassName?: string, inputStyle?: any options: any, onOptionSelected: (newOption: string) => void, resultRenderer?: (result: string) => any, placeholder?: string }, { searchText?: string; results?: any[]; isCollapsed?: boolean }> { constructor(props: any) { super(props); this.state = { searchText: props.initialValue || '', results: props.options, isCollapsed: true }; } public onTextUpdate(evt: any) { if (!evt) { return; } const searchText = evt.target.value; if (!searchText) { return this.setState({ searchText: '', results: this.props.options }); } const results = this.props.options.filter((option: any) => { return option.toLowerCase().includes(searchText.toLowerCase()); }); this.setState({ searchText, results, isCollapsed: false }); } public selectOption(option: string) { const { onOptionSelected } = this.props; this.setState({ searchText: option, isCollapsed: true }); if (onOptionSelected) { onOptionSelected(option); } } public onFocus() { this.setState({ isCollapsed: false }); } public onBlur() { this.setState({ isCollapsed: true }); } public renderResults() { const { searchText, results, isCollapsed } = this.state; const { resultRenderer } = this.props; let resultElement; if (isCollapsed) { return null; } if (searchText && !results.length) { resultElement =