css Overflow on the modal window in React JS - css

I am using Radix UI to create a modal window:
<Dialog.Root>
<Dialog.Trigger asChild>
<button className="Button violet" size="large">
Edit profile
</button>
</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Content className="DialogContent" style={{ width: "unset" }}>
<Dialog.Title className="DialogTitle">Edit profile</Dialog.Title>
<div
style={{ maxWidth: "300px", maxHeight: "150px", overflow: "auto" }}
>
<h1>teashabsjkdhkja</h1>
<h1>teashabsjkdhkja</h1>
<h1>teashabsjkdhkja</h1>
<h1>teashabsjkdhkja</h1>
<h1>teashabsjkdhkja</h1>
<h1>teashabsjkdhkja</h1>
<h1>teashabsjkdhkja</h1>
<h1>teashabsjkdhkja</h1>
<h1>teashabsjkdhkja</h1>
</div>
<div
style={{ display: "flex", marginTop: 25, justifyContent: "flex-end" }}
>
<Dialog.Close asChild>
<button className="Button green">Save changes</button>
</Dialog.Close>
</div>
<Dialog.Close asChild>
<button className="IconButton" aria-label="Close">
<Cross2Icon />
</button>
</Dialog.Close>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
When i resize the window from bottom to top over the modal, the Save changes button remains outside the modal, but i want to drag it at the top with the bottom window border. Question: How to solve the issue?
demoL: https://codesandbox.io/s/flamboyant-hamilton-3bx0h3

Assuming that the goal is to contain Button when resizing the window, perhaps try add display: flex and flex-direction: column to the DialogContent class in styles.css:
.DialogContent {
display: flex;
flex-direction: column;
background-color: white;
border-radius: 6px;
box-shadow: hsl(206 22% 7% / 35%) 0px 10px 38px -10px,
hsl(206 22% 7% / 20%) 0px 10px 20px -15px;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 90vw;
max-width: 450px;
max-height: 85vh;
padding: 25px;
animation: contentShow 150ms cubic-bezier(0.16, 1, 0.3, 1);
}

Related

Css clip path inside another clip path not working properly (REACT)

I'm using react on a project and I'm trying to figure out how to make a combination of two clip path. But they are interacting in some way. if I deactivate the css line (clip) of the parent component the clip-path work fine on the child component but if both work at the same time I get a visual error. The backdrop blur doesn't get the masking and the background color works fine.
// Initial State
// Disabling parent clip-path
// HTML(JSX) parent
import React from 'react'
import ImgSlider from '../config/ImgSlider'
import logoWhite from '../img/logo-white.png'
export default function start() {
return (
<div className="container-inside" >
<div className='container-start'>
<h1 style={{color: 'white'}}>¡Personalizá tu regalo!</h1>
<div className='button-start'>
<svg className='svg'>
<defs>
<clipPath id="starClip" clipPathUnits="objectBoundingBox"><path d="M0.5,0.76 L0.277,1 L0.321,0.672 L0,0.643 L0.278,0.474 L0.099,0.198 L0.401,0.315 L0.5,0 L0.599,0.315 L0.901,0.198 L0.722,0.474 L1,0.643 L0.678,0.671 L0.722,0.999 L0.5,0.76"></path></clipPath>
</defs>
</svg>
<button className="starClip">
<h2>start</h2>
</button>
</div>
<img className='logo' alt="logo"/>
</div>
<ImgSlider />
</div>
);
}
// CSS parent
.clipped {
justify-content: center;
width: 100%;
height: 87vh;
background: #F2E9DB;
background-size: cover;
-webkit-clip-path: url(#my-clip-path);
clip-path: url(#my-clip-path);
z-index: 1;
overflow: hidden;
}
// HTML(JSX) child
import React from 'react'
import ImgSlider from '../config/ImgSlider'
import logoWhite from '../img/logo-white.png'
export default function start() {
return (
<div className="container-inside" >
<div className='container-start'>
<h1 style={{color: 'white'}}>¡Personalizá tu regalo!</h1>
<div className='button-start'>
<svg className='svg'>
<defs>
<clipPath id="starClip" clipPathUnits="objectBoundingBox"><path d="M0.5,0.76 L0.277,1 L0.321,0.672 L0,0.643 L0.278,0.474 L0.099,0.198 L0.401,0.315 L0.5,0 L0.599,0.315 L0.901,0.198 L0.722,0.474 L1,0.643 L0.678,0.671 L0.722,0.999 L0.5,0.76"></path></clipPath>
</defs>
<g className="starClip" clipPath="url(#starClip)">
<button>
<h2>start</h2>
</button>
</g>
</svg>
</div>
<img className='logo' alt="logo"/>
</div>
<ImgSlider />
</div>
);
}
// CSS Child
.container-inside{
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
}
.container-start{
display: flex;
position: absolute;
flex-direction: column;
justify-content: space-around;
align-items: center;
width: 100%;
height: 100%;
z-index: 19;
}
.button-start{
z-index: 10;
position: absolute;
}
.starClip {
background-color: rgba(0, 0, 0, 0.186);
box-shadow: 0.5vh 0.5vh 1.3vh rgba(0, 0, 0, 0.1), inset 0.5vh 0.5vh 2vh rgba(0, 0, 0, 0.1) ;
height: 20vh;
width: 20vh;
-webkit-backdrop-filter: blur(5px);
backdrop-filter: blur(5px);
-webkit-clip-path: url(#starClip);
clip-path: url(#starClip);
z-index: 15;
}

Cart modal overlay sticks to the top When it has mutiple items

I created cart modal, when i add multiple items to it, the style looks weird because the firs item cant see in the modal. probably i have some style issue. i am gonna share the code of my modal and styles. The screenshot i took probably has 4 product but shows three
<div onClick={this.props.onClick} className={modalStyles.darkBg}/>
<div className={modalStyles.centered}>
<div className={modalStyles.modal}>
<p className={modalStyles.heading}>
My bags, {this.props.cart.length} items
</p>
{this.props.cart.map((item, index) => (
<div className={modalStyles.modalBody} key={item.id}>
<div className={modalStyles.row1}>
<div className={modalStyles.row2Child}>
<button type="button"onClick={()=> {this.props.addToCartWithQty(item)}}>+
</button>
<p>{item.qty}</p>
<button type="button" onClick={()=> {this.props.removeFromCart(index)}}>-
</button>
</div>
<img src={item.gallery[0]} alt="Avatar"/>
</div>
</div>
))}
</div>
</div>
Styles:
.darkBg {
position: fixed;
background-color: rgba(0, 0, 0, 0.2);
width: 100vw;
height: 100vh;
z-index: 10;
top: 0;
left: 0;
}
.centered {
position: absolute;
top: 35%;
right: 0;
transform: translate(-50%, -50%);
z-index: 10;
}
.modal {
width: 350px;
height: auto;
background: white;
color: white;
z-index: 10;
box-shadow: 0 5px 20px 0 rgba(0, 0, 0, 0.04);
}
.heading {
margin: 0;
padding: 10px;
color: #2c3e50;
font-weight: 500;
font-size: 18px;
text-align: left;
}
.modalBody {
display: flex;
flex-direction: column;
padding: 10px;
font-size: 14px;
color: #2c3e50;
gap: 10px;
}
On .modal class You need to add max-height instead of height and overflow-y should be set to scroll to be able to scroll not visible elements.
max-height: 80vh;
overflow-y: scroll;
you can wrap items in 1 div and give overflow-y: scroll; it will make that div scrollable with all items in it.

Center Align Modal ReactJS

I'm trying to style a modal in ReactJS and would like some help. I'm facing difficulty in trying to center align the content modal. In addition, when styling the modal, is it possible to assign a className and style it in the css page? I've tried doing that but it doesn't work. So I just decided to do inline styling but I can't center align my modal.
<button onClick={()=> SEOsetModalIsOpen(true)} className="viewmore">
View More
<ArrowIcon className="arrowright"/>
</button>
<Modal
isOpen={SEOmodalIsOpen}
shouldCloseOnOverlayClick={true}
onRequestClose={()=>SEOsetModalIsOpen(false)}
style={{
overlay: {
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
opacity: 1,
},
content: {
position: 'absolute',
width: '500px',
height: '300px',
top: '200px',
left: '500px',
right: '500px',
bottom: '200px',
border: '1px solid #ccc',
background: 'blue',
overflow: 'auto',
WebkitOverflowScrolling: 'touch',
borderRadius: '4px',
outline: 'none',
padding: '20px'
}
}}
>
<h2>Search Engine Optimisation</h2>
<p>Hello World</p>
<button onClick={()=>SEOsetModalIsOpen(false)}>Close</button>
</Modal>
</div>
You could use this to center it with absolute positioning:
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
instead of setting top, left, bottom, right to center your content, you can set
{
display: "flex",
justifyContent: "center",
alignItems: "center",
}

Styling fixed position in React

I'd like the top level div with message "This is a test message" pinned to top so it always on top and overlay the following div even (with black background) when i scroll
The "position: fixed" does not seem to make it work
function App() {
return (
<div>
<div
style={{
top: "0px",
position: "fixed",
width: "100%",
overflow: "hidden"
}}
>
<p>this is a test message</p>
</div>
<div
className="App"
style={{
marginTop: "50px",
height: "2000px",
width: "30px",
background: "black"
}}
></div>
</div>
);
}
I did not have to change anything to your code, I just added a few colors and some height: https://react-zda8ht.stackblitz.io
Link to the editor: https://stackblitz.com/edit/react-zda8ht
Isn't that what you're looking for?
If i understand you correctly, this is something you need
<div id="app">
The APP
</div>
<div id=message>
This is a test message
</div>
#app {
margin: 50px auto 0px auto;
padding: 10px;
width: 300px;
height: 2000px;
background-color: black;
color: white;
}
#message {
position: fixed;
top: 0px;
left: 0px;
width: 100%;
padding: 10px;
background-color: red;
color: white;
}
the jsfiddle example link
.root{
top: 0px;
position: fixed;
overflow: hidden;
width: 100%;
height: 50px;
background: darkcyan;
color:white;
}
.inner{
margin-top: 60px;
height: 1000vh;
width: 30px;
background: black;
}
<div>
<div class="root">
<p>this is a test message</p>
</div>
<div class="inner"></div>
</div>

Popup Background shadow CSS

I am creating a Pop Up in React but maybe the position of some divs is incorrect. I need my popup to be centered as it is with fixed width and height, but the shadow background doesn't work. Please help me
<div className={style.container}>
<div className={style.bg}>
<div className={style.popup}>
<div className={style.popup_inner}>
<div className={style.center}>
<h5 className={style.textStyle}>Save changes to channel?</h5>
<h5 className={style.textStyle}>‘Sapyens Night’</h5>
<hr className={style.line} />
<p>
If you confirm changes will be automatically presented<br/>
to to all users.<br/>
If you change audio source, small audio disruption
might<br/>
occur.
</p>
<div className={style.buttons}> <button className={style.back}
onClick={this.props.closePopup}>
Back
</button>
<button className={style.goLive}>Save</button></div>
</div>
</div>
</div>
</div>
</div>
.popup {
position: fixed;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.popup_inner {
position: absolute;
width: 433px;
height: 342px;
border-radius: 20px;
background: white;
border: 1px solid #502f7e;
}
.bg{
position: relative;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
Try to do like this
.bg{
position: absolute;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}

Resources