Choose first result on enter in the emoji picker

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2020-09-28 15:56:22 +01:00
parent 6873402666
commit abd7bf37f4
2 changed files with 28 additions and 3 deletions

View file

@ -18,10 +18,12 @@ limitations under the License.
import React from 'react';
import { _t } from '../../../languageHandler';
import {Key} from "../../../Keyboard";
interface IProps {
query: string;
onChange(value: string): void;
onEnter(): void;
}
class Search extends React.PureComponent<IProps> {
@ -32,6 +34,14 @@ class Search extends React.PureComponent<IProps> {
setTimeout(() => this.inputRef.current.focus(), 0);
}
private onKeyDown = (ev: React.KeyboardEvent) => {
if (ev.key === Key.ENTER) {
this.props.onEnter();
ev.stopPropagation();
ev.preventDefault();
}
};
render() {
let rightButton;
if (this.props.query) {
@ -54,6 +64,7 @@ class Search extends React.PureComponent<IProps> {
placeholder="Search"
value={this.props.query}
onChange={ev => this.props.onChange(ev.target.value)}
onKeyDown={this.onKeyDown}
ref={this.inputRef}
/>
{rightButton}