1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop: Fixes #10815: Fix Enter key submits dialogs even if a button has focus (#10814)

This commit is contained in:
Henry Heino 2024-08-02 06:51:25 -07:00 committed by GitHub
parent 14cc053094
commit 88271bf1a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,3 +1,4 @@
import * as React from 'react';
import { useEffect, useState, useRef, useCallback } from 'react';
import { isInsideContainer } from '@joplin/lib/dom';
@ -40,8 +41,7 @@ export default (props: Props) => {
return false;
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
const onKeyDown = useCallback((event: any) => {
const onKeyDown = useCallback((event: KeyboardEvent|React.KeyboardEvent) => {
// Early exit if it's neither ENTER nor ESCAPE, because isInSubModal
// function can be costly.
if (event.keyCode !== 13 && event.keyCode !== 27) return;
@ -49,8 +49,12 @@ export default (props: Props) => {
if (!isTopDialog() || isInSubModal(event.target)) return;
if (event.keyCode === 13) {
if (event.target.nodeName !== 'TEXTAREA') {
props.onOkButtonClick();
if ('nodeName' in event.target && event.target.nodeName === 'INPUT') {
const target = event.target as HTMLInputElement;
if (target.type !== 'button' && target.type !== 'checkbox') {
props.onOkButtonClick();
}
}
} else if (event.keyCode === 27) {
props.onCancelButtonClick();