Created
March 2, 2016 15:33
-
-
Save Ahineya/e689a012e32a48e6d734 to your computer and use it in GitHub Desktop.
Issue example
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
export class SearchField extends React.Component<EditorProps, any> { | |
public onChange: Function; | |
constructor(props) { | |
super(props); | |
this.state = {editorState: EditorState.createEmpty()}; | |
this.onChange = (editorState) => { | |
console.info("here"); | |
let searchQuery = editorState.getCurrentContent().getPlainText(); | |
this.props.onChange(searchQuery); | |
this.setState({editorState}); | |
} | |
} | |
//Here it doesn't work properly | |
clearSearchField = (): any => { | |
this.setState({editorState: EditorState.createEmpty()}); | |
this.props.onEscape(); | |
return true; | |
}; | |
//And here too | |
selectInstrument = (): any => { | |
this.setState({editorState: EditorState.createEmpty()}); | |
this.props.onEnter(); | |
return true; | |
}; | |
render() { | |
const {editorState} = this.state; | |
return <Editor editorState={editorState} | |
onChange={this.onChange} | |
onEscape={this.clearSearchField} | |
onDownArrow={this.props.onDownArrow} | |
onUpArrow={this.props.onUpArrow} | |
handleReturn={this.selectInstrument} | |
/>; | |
} | |
} | |
//And this.props.onEscape and this.props.onEnter are in parent component: | |
onEnter = (): any => { | |
if (this.state.selectedItemIndex !== null) { | |
const instrument = this.filterInstruments(this.state.instruments)[this.state.selectedItemIndex]; | |
this.selectInstrument(instrument); | |
} | |
} | |
onEscape = (): void => { | |
this.setState({ | |
filter: null, | |
showSearchResults: false, | |
selectedItemIndex: null | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment