Skip to content

Instantly share code, notes, and snippets.

@Ahineya
Created March 2, 2016 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ahineya/e689a012e32a48e6d734 to your computer and use it in GitHub Desktop.
Save Ahineya/e689a012e32a48e6d734 to your computer and use it in GitHub Desktop.
Issue example
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