Skip to content
Open
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
137 changes: 90 additions & 47 deletions src/sections/Pricing/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useState, useEffect } from "react";
import PricingWrapper from "./pricing.style";
import Comparison from "./comparison";
import FAQ from "../General/Faq";
Expand Down Expand Up @@ -42,58 +42,101 @@ const getCustomToggleButtonStyle = (isActive, baseStyle) => ({
});

export const CurrencySelect = ({ currency, setCurrency }) => {
const [open, setOpen] = useState(false);

// Lock both <html> and <body> while the dropdown is open
useEffect(() => {
if (!open) return;
Copy link
Member

Choose a reason for hiding this comment

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

this logic seems bit low level. Why the disableScrollLock is not working? Try using modal component and see if its wokring without such logic to handle manually the scrolling

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right
I tried using the standard MUI components first, but a CSS conflict elsewhere in the app was preventing them from working correctly.
This manual useEffect is a necessary override

const prevBody = document.body.style.overflow;
const prevHtml = document.documentElement.style.overflow;
document.body.style.overflow = "hidden";
document.documentElement.style.overflow = "hidden";
return () => {
document.body.style.overflow = prevBody;
document.documentElement.style.overflow = prevHtml;
};
}, [open]);

const handleClose = () => setOpen(false);
const handleOpen = () => setOpen(true);

return (
<FormControl
variant="outlined"
size="small"
sx={{
minWidth: 150,
"& .MuiInputLabel-root": {
color: "white",
"&.Mui-focused": { color: "#00B39F" },
},
"& .MuiOutlinedInput-root": {
color: "white",
"& .MuiSelect-icon": { color: "white" },
"& .MuiOutlinedInput-notchedOutline": { borderColor: "white" },
"&.Mui-focused .MuiOutlinedInput-notchedOutline": {
borderColor: "#00B39F",
<>
{/* Transparent overlay: blocks the page & closes on outside click */}
{open && (
<Box
onMouseDown={handleClose}
onTouchStart={handleClose}
sx={{
position: "fixed",
inset: 0,
zIndex: 1299, // below MUI Menu (paper is set to 1301)
}}
/>
)}

<FormControl
variant="outlined"
size="small"
sx={{
minWidth: 150,
"& .MuiInputLabel-root": {
color: "white",
"&.Mui-focused": { color: "#00B39F" },
},
"& .MuiOutlinedInput-root": {
color: "white",
"& .MuiSelect-icon": { color: "white" },
"& .MuiOutlinedInput-notchedOutline": { borderColor: "white" },
"&.Mui-focused .MuiOutlinedInput-notchedOutline": {
borderColor: "#00B39F",
},
},
},
"&:hover": {
"& .MuiInputLabel-root": { color: "#00B39F" },
"& .MuiOutlinedInput-root .MuiOutlinedInput-notchedOutline": {
borderColor: "#00B39F",
borderWidth: "2px",
"&:hover": {
"& .MuiInputLabel-root": { color: "#00B39F" },
"& .MuiOutlinedInput-root .MuiOutlinedInput-notchedOutline": {
borderColor: "#00B39F",
borderWidth: "2px",
},
},
},
}}
>
<InputLabel id="currency-selector-label">Currency</InputLabel>
<Select
labelId="currency-selector-label"
value={currency}
onChange={(e) => {
setCurrency(e.target.value);
}}
label="Currency"
renderValue={(value) => (
<Box sx={{ display: "flex", alignItems: "center", gap: 1, color: "#fff" }}>
<Typography variant="body1">{Currencies[value]?.symbol}</Typography>
<Typography variant="body2">{Currencies[value]?.name}</Typography>
</Box>
)}
>
{Object.entries(Currencies).map(([code, { symbol, name }]) => (
<MenuItem key={code} value={code}>
<Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
<Typography variant="body1">{symbol}</Typography>
<Typography variant="body2">{name}</Typography>
<InputLabel id="currency-selector-label">Currency</InputLabel>
<Select
labelId="currency-selector-label"
value={currency}
label="Currency"
open={open}
onOpen={handleOpen}
onClose={handleClose}
onChange={(e) => {
setCurrency(e.target.value);
handleClose();
}}
MenuProps={{
disableScrollLock: false,
keepMounted: true,
PaperProps: { sx: { zIndex: 1301 } }, // ensure menu is above overlay
ModalProps: { keepMounted: true, disableScrollLock: false },
}}
renderValue={(value) => (
<Box sx={{ display: "flex", alignItems: "center", gap: 1, color: "#fff" }}>
<Typography variant="body1">{Currencies[value]?.symbol}</Typography>
<Typography variant="body2">{Currencies[value]?.name}</Typography>
</Box>
</MenuItem>
))}
</Select>
</FormControl>
)}
>
{Object.entries(Currencies).map(([code, { symbol, name }]) => (
<MenuItem key={code} value={code}>
<Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
<Typography variant="body1">{symbol}</Typography>
<Typography variant="body2">{name}</Typography>
</Box>
</MenuItem>
))}
</Select>
</FormControl>
</>
);
};

Expand Down
Loading