Dialog box of azure synapse closes on pressing escape button (#1543)

This commit is contained in:
MokireddySampath 2023-09-27 20:46:26 +05:30 committed by GitHub
parent d15feb3478
commit a3bd126a21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,9 @@
import { import {
ChoiceGroup, ChoiceGroup,
DefaultButton, DefaultButton,
Dialog as FluentDialog,
DialogFooter, DialogFooter,
DialogType, DialogType,
Dialog as FluentDialog,
FontIcon, FontIcon,
IButtonProps, IButtonProps,
IChoiceGroupProps, IChoiceGroupProps,
@ -15,7 +15,7 @@ import {
ProgressIndicator, ProgressIndicator,
TextField, TextField,
} from "@fluentui/react"; } from "@fluentui/react";
import React, { FC } from "react"; import React, { FC, useEffect } from "react";
import create, { UseStore } from "zustand"; import create, { UseStore } from "zustand";
export interface DialogState { export interface DialogState {
@ -157,6 +157,20 @@ export const Dialog: FC = () => {
contentHtml, contentHtml,
} = props || {}; } = props || {};
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === "Escape") {
useDialog.getState().closeDialog();
}
};
useEffect(() => {
if (visible) {
document.addEventListener("keydown", handleKeyDown);
} else {
document.removeEventListener("keydown", handleKeyDown);
}
}, [visible]);
const dialogProps: IDialogProps = { const dialogProps: IDialogProps = {
hidden: !visible, hidden: !visible,
dialogContentProps: { dialogContentProps: {