Dialogs: Better keyboard support (#1714)
This commit is contained in:
parent
45db295c2f
commit
831d1589b4
@ -1,7 +1,8 @@
|
|||||||
import React, { FC, memo } from '../../lib/teact/teact';
|
import React, { FC, memo, useCallback, useRef } from '../../lib/teact/teact';
|
||||||
|
|
||||||
import useLang from '../../hooks/useLang';
|
import useLang from '../../hooks/useLang';
|
||||||
import { TextPart } from '../common/helpers/renderMessageText';
|
import { TextPart } from '../common/helpers/renderMessageText';
|
||||||
|
import useKeyboardListNavigation from '../../hooks/useKeyboardListNavigation';
|
||||||
|
|
||||||
import Modal from './Modal';
|
import Modal from './Modal';
|
||||||
import Button from './Button';
|
import Button from './Button';
|
||||||
@ -37,6 +38,15 @@ const ConfirmDialog: FC<OwnProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const lang = useLang();
|
const lang = useLang();
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-null/no-null
|
||||||
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
const handleSelectWithEnter = useCallback((index: number) => {
|
||||||
|
if (index === -1) confirmHandler();
|
||||||
|
}, [confirmHandler]);
|
||||||
|
|
||||||
|
const handleKeyDown = useKeyboardListNavigation(containerRef, isOpen, handleSelectWithEnter, '.Button');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
className="confirm"
|
className="confirm"
|
||||||
@ -45,13 +55,12 @@ const ConfirmDialog: FC<OwnProps> = ({
|
|||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
onCloseAnimationEnd={onCloseAnimationEnd}
|
onCloseAnimationEnd={onCloseAnimationEnd}
|
||||||
onEnter={confirmHandler}
|
|
||||||
>
|
>
|
||||||
{text && text.split('\\n').map((textPart) => (
|
{text && text.split('\\n').map((textPart) => (
|
||||||
<p>{textPart}</p>
|
<p>{textPart}</p>
|
||||||
))}
|
))}
|
||||||
{textParts || children}
|
{textParts || children}
|
||||||
<div className={isButtonsInOneRow ? 'dialog-buttons mt-2' : ''}>
|
<div className={isButtonsInOneRow ? 'dialog-buttons mt-2' : ''} ref={containerRef} onKeyDown={handleKeyDown}>
|
||||||
<Button
|
<Button
|
||||||
className="confirm-dialog-button"
|
className="confirm-dialog-button"
|
||||||
isText
|
isText
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user