Files
oneuptime/Common/UI/Components/FullPageModal/FullPageModal.tsx
Nawaz Dhandala e9d5a560ff Refactor migration files and improve code formatting
- Updated migration files to enhance readability by adjusting indentation and line breaks.
- Added missing commas in the index file for migration imports.
- Improved accessibility attributes in various UI components by ensuring proper aria-labels and roles.
- Refactored key event handlers in UI components for better clarity and consistency.
- Enhanced error message handling in form components to ensure proper display and accessibility.
- Updated legacy function comments for clarity and maintainability.
2026-01-26 19:23:58 +00:00

64 lines
1.6 KiB
TypeScript

import Icon, { SizeProp, ThickProp } from "../Icon/Icon";
import IconProp from "../../../Types/Icon/IconProp";
import React, { FunctionComponent, ReactElement } from "react";
export interface ComponentProps {
onClose: () => void;
children: ReactElement | Array<ReactElement>;
}
const FullPageModal: FunctionComponent<ComponentProps> = (
props: ComponentProps,
): ReactElement => {
const handleClose: () => void = (): void => {
props.onClose?.();
};
const handleKeyDown: (event: React.KeyboardEvent) => void = (
event: React.KeyboardEvent,
): void => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
handleClose();
}
};
// Handle Escape key at the modal level
React.useEffect(() => {
const handleEscapeKey: (event: KeyboardEvent) => void = (
event: KeyboardEvent,
): void => {
if (event.key === "Escape") {
handleClose();
}
};
document.addEventListener("keydown", handleEscapeKey);
return () => {
document.removeEventListener("keydown", handleEscapeKey);
};
}, []);
return (
<div className="full-page-modal" role="dialog" aria-modal="true">
<div
className="margin-50 align-right"
onClick={handleClose}
onKeyDown={handleKeyDown}
role="button"
tabIndex={0}
aria-label="Close modal"
>
<Icon
icon={IconProp.Close}
size={SizeProp.ExtraLarge}
thick={ThickProp.Thick}
/>
</div>
<div className="margin-50">{props.children}</div>
</div>
);
};
export default FullPageModal;