Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Confirmation modal can be very narrow #976 #1018

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/components/ConfirmationModal/ConfirmationModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { MouseEvent, ReactElement } from "react";
import React, { MouseEvent, ReactElement, useState, useEffect } from "react";
import type { ReactNode } from "react";
import { PropsWithSpread, ValueOf } from "types";
import Button, { ButtonAppearance } from "components/Button";
Expand Down Expand Up @@ -43,6 +43,25 @@ export const ConfirmationModal = ({
onConfirm,
...props
}: Props): ReactElement => {
const [minWidth, setMinWidth] = useState("480px");
useEffect(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion @nadeem-R17, but this seems a bit too complex and arbitrary solution for a styling issue.

It seems that it would need to be addressed in Vanilla CSS framework (that is the source of the styles), rather then programatically in React code.
So a Vanilla CSS modal component would need to define min width, respecting different screen size breakpoints supported by Vanilla, or possibly utilising modern min() function in CSS.

const updateMinWidth = () => {
if (window.matchMedia("(max-width: 400px)").matches) {
setMinWidth("200px");
} else if (window.matchMedia("(max-width: 700px)").matches) {
setMinWidth("300px");
} else {
setMinWidth("480px");
}
};

window.addEventListener("resize", updateMinWidth);
updateMinWidth();
return () => {
window.removeEventListener("resize", updateMinWidth);
};
}, []);

return (
<Modal
buttonRow={
Expand All @@ -62,7 +81,9 @@ export const ConfirmationModal = ({
}
{...props}
>
{children}
<div style={{ minWidth: minWidth }}>
{children}
</div>
</Modal>
);
};
Expand Down