mirror of https://github.com/vector-im/riot-web
Choose first result on enter in the emoji picker
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>pull/21833/head
parent
6873402666
commit
abd7bf37f4
|
@ -52,7 +52,7 @@ class EmojiPicker extends React.Component<IProps, IState> {
|
||||||
private readonly memoizedDataByCategory: Record<CategoryKey, IEmoji[]>;
|
private readonly memoizedDataByCategory: Record<CategoryKey, IEmoji[]>;
|
||||||
private readonly categories: ICategory[];
|
private readonly categories: ICategory[];
|
||||||
|
|
||||||
private bodyRef = React.createRef<HTMLElement>();
|
private bodyRef = React.createRef<HTMLDivElement>();
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
@ -190,6 +190,13 @@ class EmojiPicker extends React.Component<IProps, IState> {
|
||||||
setTimeout(this.updateVisibility, 0);
|
setTimeout(this.updateVisibility, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private onEnterFilter = () => {
|
||||||
|
const btn = this.bodyRef.current.querySelector<HTMLButtonElement>(".mx_EmojiPicker_item");
|
||||||
|
if (btn) {
|
||||||
|
btn.click();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private onHoverEmoji = (emoji: IEmoji) => {
|
private onHoverEmoji = (emoji: IEmoji) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
previewEmoji: emoji,
|
previewEmoji: emoji,
|
||||||
|
@ -220,8 +227,15 @@ class EmojiPicker extends React.Component<IProps, IState> {
|
||||||
return (
|
return (
|
||||||
<div className="mx_EmojiPicker">
|
<div className="mx_EmojiPicker">
|
||||||
<Header categories={this.categories} onAnchorClick={this.scrollToCategory} />
|
<Header categories={this.categories} onAnchorClick={this.scrollToCategory} />
|
||||||
<Search query={this.state.filter} onChange={this.onChangeFilter} />
|
<Search query={this.state.filter} onChange={this.onChangeFilter} onEnter={this.onEnterFilter} />
|
||||||
<AutoHideScrollbar className="mx_EmojiPicker_body" wrappedRef={this.bodyRef} onScroll={this.onScroll}>
|
<AutoHideScrollbar
|
||||||
|
className="mx_EmojiPicker_body"
|
||||||
|
wrappedRef={ref => {
|
||||||
|
// @ts-ignore - AutoHideScrollbar should accept a RefObject or fall back to its own instead
|
||||||
|
this.bodyRef.current = ref
|
||||||
|
}}
|
||||||
|
onScroll={this.onScroll}
|
||||||
|
>
|
||||||
{this.categories.map(category => {
|
{this.categories.map(category => {
|
||||||
const emojis = this.memoizedDataByCategory[category.id];
|
const emojis = this.memoizedDataByCategory[category.id];
|
||||||
const categoryElement = ((
|
const categoryElement = ((
|
||||||
|
|
|
@ -18,10 +18,12 @@ limitations under the License.
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { _t } from '../../../languageHandler';
|
import { _t } from '../../../languageHandler';
|
||||||
|
import {Key} from "../../../Keyboard";
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
query: string;
|
query: string;
|
||||||
onChange(value: string): void;
|
onChange(value: string): void;
|
||||||
|
onEnter(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Search extends React.PureComponent<IProps> {
|
class Search extends React.PureComponent<IProps> {
|
||||||
|
@ -32,6 +34,14 @@ class Search extends React.PureComponent<IProps> {
|
||||||
setTimeout(() => this.inputRef.current.focus(), 0);
|
setTimeout(() => this.inputRef.current.focus(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private onKeyDown = (ev: React.KeyboardEvent) => {
|
||||||
|
if (ev.key === Key.ENTER) {
|
||||||
|
this.props.onEnter();
|
||||||
|
ev.stopPropagation();
|
||||||
|
ev.preventDefault();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let rightButton;
|
let rightButton;
|
||||||
if (this.props.query) {
|
if (this.props.query) {
|
||||||
|
@ -54,6 +64,7 @@ class Search extends React.PureComponent<IProps> {
|
||||||
placeholder="Search"
|
placeholder="Search"
|
||||||
value={this.props.query}
|
value={this.props.query}
|
||||||
onChange={ev => this.props.onChange(ev.target.value)}
|
onChange={ev => this.props.onChange(ev.target.value)}
|
||||||
|
onKeyDown={this.onKeyDown}
|
||||||
ref={this.inputRef}
|
ref={this.inputRef}
|
||||||
/>
|
/>
|
||||||
{rightButton}
|
{rightButton}
|
||||||
|
|
Loading…
Reference in New Issue