bind enter events as a submit to Popups

add s as key to submit a reshuffle in shuffled videos
This commit is contained in:
2021-01-28 19:50:26 +00:00
parent f06da8044f
commit fa21ba4f25
10 changed files with 146 additions and 26 deletions

View File

@ -2,13 +2,15 @@ import GlobalInfos from '../../utils/GlobalInfos';
import style from './PopupBase.module.css';
import {Line} from '../PageTitle/PageTitle';
import React, {RefObject} from 'react';
import {addKeyHandler, removeKeyHandler} from '../../utils/ShortkeyHandler';
interface props {
width?: string;
height?: string;
banner?: JSX.Element;
title: string;
onHide: () => void
onHide: () => void;
ParentSubmit?: () => void;
}
/**
@ -38,7 +40,7 @@ class PopupBase extends React.Component<props> {
componentDidMount(): void {
document.addEventListener('mousedown', this.handleClickOutside);
document.addEventListener('keyup', this.keypress);
addKeyHandler(this.keypress);
// add element drag drop events
if (this.wrapperRef != null) {
@ -49,7 +51,7 @@ class PopupBase extends React.Component<props> {
componentWillUnmount(): void {
// remove the appended listeners
document.removeEventListener('mousedown', this.handleClickOutside);
document.removeEventListener('keyup', this.keypress);
removeKeyHandler(this.keypress);
}
render(): JSX.Element {
@ -86,6 +88,9 @@ class PopupBase extends React.Component<props> {
// hide if escape is pressed
if (event.key === 'Escape') {
this.props.onHide();
} else if (event.key === 'Enter') {
// call a parentsubmit if defined
if (this.props.ParentSubmit) this.props.ParentSubmit();
}
}