Skip to content

Build your personal knowledge base with Trilium Notes

fix(modal): accept a modal without a class name

Elian Doran23c18eb14537
diff --git a/apps/client/src/widgets/react/Modal.spec.tsx b/apps/client/src/widgets/react/Modal.spec.tsx
index d0e1c475d1..1af0e9cfd5 100644
--- a/apps/client/src/widgets/react/Modal.spec.tsx
+++ b/apps/client/src/widgets/react/Modal.spec.tsx
@@ -223,6 +223,14 @@ describe("Modal", () => {
expect(dialog?.classList.contains("show")).toBe(true);
});
+ it("renders without a class of the host's own", async () => {
+ await act(async () => {
+ render(<Modal size="md" show onHidden={() => {}}>body</Modal>, container);
+ });
+
+ expect(container.querySelector(".modal")?.getAttribute("class")).toBe("modal fade mx-auto");
+ });
+
/**
* `openDialog` moves focus onto the new backdrop synchronously, and a focus-trap still active on
* the dialog underneath pulls it straight back in. Over the Options dialog that lands in the
diff --git a/apps/client/src/widgets/react/Modal.tsx b/apps/client/src/widgets/react/Modal.tsx
index ce84ae6b58..3e0d0f5e5d 100644
--- a/apps/client/src/widgets/react/Modal.tsx
+++ b/apps/client/src/widgets/react/Modal.tsx
@@ -21,7 +21,7 @@ interface CustomTitleBarButton {
}
export interface ModalProps {
- className: string;
+ className?: string;
title?: string | ComponentChildren;
customTitleBarButtons?: (CustomTitleBarButton | null)[];
size: "xl" | "lg" | "md" | "sm";
@@ -108,7 +108,7 @@ export interface ModalProps {
ariaLabel?: string;
}
-export default function Modal({ children, className, size, title, customTitleBarButtons: titleBarButtons, header, footer, footerStyle, footerAlignment, onShown, onSubmit, helpPageId, minWidth, maxWidth, zIndex, scrollable, onHidden, modalRef: externalModalRef, formRef, bodyStyle, show, stackable, keepInDom, noFocus, sidebar, hideSidebarHeader, isFullPageOnMobile, ariaLabel }: ModalProps) {
+export default function Modal({ children, className = "", size, title, customTitleBarButtons: titleBarButtons, header, footer, footerStyle, footerAlignment, onShown, onSubmit, helpPageId, minWidth, maxWidth, zIndex, scrollable, onHidden, modalRef: externalModalRef, formRef, bodyStyle, show, stackable, keepInDom, noFocus, sidebar, hideSidebarHeader, isFullPageOnMobile, ariaLabel }: ModalProps) {
const modalRef = useSyncedRef<HTMLDivElement>(externalModalRef);
const modalInstanceRef = useRef<BootstrapModal | undefined>(undefined);
const elementToFocus = useRef<Element | null | undefined>(undefined);
diff --git a/packages/commons/src/lib/script_api_preact.ts b/packages/commons/src/lib/script_api_preact.ts
index 9ec01f614e..ad6c33f012 100644
--- a/packages/commons/src/lib/script_api_preact.ts
+++ b/packages/commons/src/lib/script_api_preact.ts
@@ -321,7 +321,7 @@ export declare const LinkButton: FunctionComponent<LinkButtonProps>;
export declare const LoadingSpinner: FunctionComponent<{}>;
interface ModalProps {
- className: string;
+ className?: string;
title?: ComponentChildren;
customTitleBarButtons?: ({ title: string; iconClassName: string; onClick: (e: MouseEvent) => void } | null)[];
size: "xl" | "lg" | "md" | "sm";