Fix text story creation input

This commit is contained in:
Josh Perez 2022-11-01 14:56:19 -04:00 committed by GitHub
parent 97b7f3dbc1
commit 50c48315e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,7 +3,6 @@
import type { KeyboardEvent, ReactNode } from 'react';
import type { Options, VirtualElement } from '@popperjs/core';
import FocusTrap from 'focus-trap-react';
import React, { useEffect, useRef, useState } from 'react';
import classNames from 'classnames';
import { usePopper } from 'react-popper';
@ -174,6 +173,13 @@ export function ContextMenu<T>({
ev.stopPropagation();
ev.preventDefault();
}
if (ev.key === 'Escape') {
setIsMenuShowing(false);
closeCurrentOpenContextMenu = undefined;
ev.stopPropagation();
ev.preventDefault();
}
};
const handleClick = (ev: React.MouseEvent) => {
@ -282,37 +288,31 @@ export function ContextMenu<T>({
}
return (
<FocusTrap
focusTrapOptions={{
allowOutsideClick: true,
}}
<div
className={classNames(
getClassName('__container'),
theme ? themeClassName(theme) : undefined
)}
>
<div
className={classNames(
getClassName('__container'),
theme ? themeClassName(theme) : undefined
)}
>
{buttonNode}
{isMenuShowing && (
<div className={theme ? themeClassName(theme) : undefined}>
<div
className={classNames(
getClassName('__popper'),
menuOptions.length === 1
? getClassName('__popper--single-item')
: undefined
)}
ref={setPopperElement}
style={styles.popper}
{...attributes.popper}
>
{title && <div className={getClassName('__title')}>{title}</div>}
{optionElements}
</div>
{buttonNode}
{isMenuShowing && (
<div className={theme ? themeClassName(theme) : undefined}>
<div
className={classNames(
getClassName('__popper'),
menuOptions.length === 1
? getClassName('__popper--single-item')
: undefined
)}
ref={setPopperElement}
style={styles.popper}
{...attributes.popper}
>
{title && <div className={getClassName('__title')}>{title}</div>}
{optionElements}
</div>
)}
</div>
</FocusTrap>
</div>
)}
</div>
);
}