Skip to content

Instantly share code, notes, and snippets.

@george-aidonidis
Last active September 2, 2017 03:53
Show Gist options
  • Save george-aidonidis/0ce376a0f30f60e54616e6cef468ece5 to your computer and use it in GitHub Desktop.
Save george-aidonidis/0ce376a0f30f60e54616e6cef468ece5 to your computer and use it in GitHub Desktop.
Grommet select onEnter
_onEnter (event) {
const { onChange, options } = this.props;
const { activeOptionIndex } = this.state;
const { intl } = this.context;
event.preventDefault(); // prevent submitting forms
const option = options[activeOptionIndex >= 0 ? activeOptionIndex : 0];
const value = this._valueForSelectedOption(option);
this.setState({ dropActive: false, value }, () => {
const optionMessage = this._renderLabel(option);
const selectedMessage = Intl.getMessage(intl, 'Selected');
announce(`${optionMessage} ${selectedMessage}`);
});
if (onChange) {
onChange({ target: this.inputRef, option, value });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment