React Boostrap Modal Container not working - reactjs

I'm trying to get a React Booststrap Modal working inside a container I've tried in many different ways but I'm not getting it to work inside the container (div), I honestly don't know why.
The code is a little long, so I will let you a snippet of the code.
MisListas.js
function MisListas() {
const listContainer=useRef(null)
return (
<div ref={listContainer}> //Here is the ref
// Some Code
<Row xs={2} sm={3} md={4} lg={4} xl={5}>
{search && search.map(product =>{
return (
<ListProduct
product={
{
...product,
BasePrice: product.Price,
FinalPrice: product.Price
}
}
container={listContainer}/>
)})}
</Row>
</div>
)
}
Product.js
This is the Modal:
function Product({product,container}) {
return(
<div>
<Modal
show={isOpen}
onHide={handleClose}
container={container.current}
backdrop={false}
enforceFocus={false}
className="modal-clase-productList"
>
//Some Code
</Modal>
</div>
)
}
This is a simplified version of the code. As you can see I am passing the ref (listContainer) as the container of the modal as container.ref. But the modal keeps taking the whole screen when it opens.
Any idea how can I make it work?

Related

Building a button only with image in React

I've spent two days trying to figure out how to create a button with image in React but so far not able to achieve something shown below.
Screenshot of what I'm trying to achieve -- Files and Folders there are clickable buttons:
I'm willing to use MUI or even better if this can be done using plain react.
Appreciate if anyone can show me how this can be done.
Use This Code
import Button from '#mui/material/Button';
export default function App() {
return (
<>
<Button variant="text" size="small" style={{display: "flex", flexDirection: "column"}}>
<img src="https://www.tenforums.com/geek/gars/images/2/types/thumb_14486407500Folder.png" width="100" alt="folder"/>
<label>Pictures</label>
</Button>
</>
);
}
You can do something similar as well
export default function App() {
return (
<div className="App">
<img
src="https://www.tenforums.com/geek/gars/images/2/types/thumb_14486407500Folder.png"
alt=""
onClick={handleClick}
id="secret_folder"
/>
</div>
);
function handleClick(e) {
if (e.target.id === "secret_folder") {
console.log("you clicked");
}
}
}

Why does my table component filter crash the browser tab?

I have a page with a table which is working quite fine and is very performant as it should be. I'm now trying to implement a filter for it so the users can easily check only what they need. But one weird thing is happening. If I have the filter component commented out, everything works fine. If I include it in the component it should be, the browser becomes extremely slow and even crashes my chrome tab. I was trying to comment out all the code in that component to check where the problem is but I can't figure it out.
My weird component code without the comments:
import { Grid, LuxButton } from 'luxclusif-material';
import React, { useState } from 'react';
import { FilterComponentStyles } from './FilterComponent.styles';
export default function FilterComponent() {
const classes = FilterComponentStyles();
const [status, setStatus] = useState('Supplier');
return (
<>
<div className={classes.spacing}>
{/* commented out stuff */}
</div>
<div className={`${classes.statusMenu} ${classes.spacing}`}>
<Grid
container
direction="row"
justify="flex-start"
alignItems="center"
className={classes.heightStatus}>
<div className={classes.rightMargin}>
<LuxButton
variant="contained"
luxColor={(status === 'Supplier' ? 'secondary' : 'default')}
onClick={() => setStatus('Supplier')}
className={classes.transformTextNone}
disableElevation>
<span className={classes.addButtonText}>Supplier</span>
</LuxButton>
</div>
<div className={classes.rightMargin}>
<LuxButton
variant="contained"
luxColor={(status === 'Active' ? 'secondary' : 'default')}
onClick={() => setStatus('Active')}
className={classes.transformTextNone}
disableElevation>
<span className={classes.addButtonText}>Active</span>
</LuxButton>
</div>
<div className={classes.rightMargin}>
<LuxButton
variant="contained"
luxColor={(status === 'Inactive' ? 'secondary' : 'default')}
onClick={() => setStatus('Inactive')}
className={classes.transformTextNone}
disableElevation>
<span className={classes.addButtonText}>Inactive</span>
</LuxButton>
</div>
</Grid>
</div>
</>
);
}
This FilterComponent is being called like this:
<TableContainer component={Paper} >
<FilterComponent ></FilterComponent>
<Table>
{/* table code */}
</Table>
</TableContainer>
Notes: LuxButton is an extension of material-ui Button and its luxColor property is the extension to the color property.

Flag setting issue in React

So basically I'm trying to tie in the Login and Sign Up component to the Main component by making use of onClick action of a button.
Given below is the code segment
function Dev({value}){
const [isButton, ButtonClicked ] = useState(false);
const handleClick=()=> ButtonClicked(!isButton);
return(
<div>
<Card>
<CardImg top width="100%" src={value.src} alt="Card image cap" />
<CardBody>
<CardTitle className='text-card'>{value.title}</CardTitle>
<CardText className='text-text'>{value.text}</CardText>
<Button className='text-button' onClick={handleClick}>{value.button}<i class={value.icon} aria-hidden="true"></i></Button>
</CardBody>
</Card>
{isButton && (value.id ? <Login open={true} /> : <Sign open={true}/>)}
</div>
);
}
The code works fine, but there is an issue.
When I first click on the button, isButton will be set to true and the Login component will pop up. After closing it, I have to click twice on the button to render the Login component again.
I know the reason behind this; when I click on the button the second time isButton will be toggled to false and I should click again to toggle it to true. This is kind of inappropriate, is there any way to work around this issue?
The code for Login Component
const Login = (props) => {
const [modal, setModal] = useState(props.open);
const toggle = () => setModal(!modal);
return (
<div>
<Modal isOpen={modal} toggle={toggle}>
<ModalHeader toggle={toggle}>Login</ModalHeader>
<ModalBody>
.
.
.
</ModalBody>
</Modal>
</div>
);
}
export default Login;

ReactJS conditional display of elements with map function is returning that my object or key is 'undefined'

Here I have passed my state from one component to another the same way I've done before. And when I console.log the passed state (before I add the map statement in JSX) I get the object im looking for. But when I go inside the return statement I get "cannot map 'undefined'". And at that point the console.log starts returning as undefined. But before I tried to map over the passed prop the console.log was returning the data.Can anyone help me see what im doing wrong?
function Items ({orgList}) {
console.log(orgList.items)
return (
<>
{orgList ?
<div>
{orgList.items.map((item, i) => (
<Card key={i} className= "w-100 m-2">
<CardHeader className="d-flex">
<p>Hello</p>
</CardHeader>
<CardBody>
<p>The Body</p>
<Row>
<Col md="5">
<dl>
<dt>GroupID</dt>
<dd>{item.GroupID}</dd>
<dt>Name</dt>
<dd>{item.name}</dd>
</dl>
</Col>
</Row>
</CardBody>
</Card>
))}
</div>
:
<div>
<PageLoadSpinner inProgress={inProgress} />
</div>
}
</>
)
}
export default Items;**strong text**
Here is the parent Component
function Orgs () {
const [orgList, setOrgList] = useState([]);
useEffect(() => {
loadOrgs();
}, []);
const loadOrgs = () => {
api.MonitoringOrg.list()
.then(response => {
console.log(response)
setOrgList(...orgList, response)
})
.catch(err => console.log(err))
}
return(
<>
<Items orgList={orgList}/>
</>
)
}
export default Orgs;
Errors that include undefined like the one you are observing likely mean one of two things:
(1) The variable is not defined or accessible to the function. This is not the case in your situation as you have shown that the variable is accessible outside of the scope of your conditional. Or,
(2) The render function has not yet evaluated your variable by the time it gets to rendering. This is likely the case in your situation.
I think the second situation is due to a race condition, and I leave the details of that to someone with better knowledge of the React source code to explain.
An easy way to avoid this situation is to update your conditional with the specific keys you will need. This will help prevent the render function from short circuiting your component. This way, your data will not be called upon if a render proceeds without it being there.
Given in your situation that you are drawing on orgList.items in your map function, let's update the code as per the following:
function Items ({orgList}) {
console.log(orgList.items)
return (
<>
{orgList?.items? {/* <------ update this line as seen here */}
<div>
{orgList.items.map((item, i) => (
<Card key={i} className= "w-100 m-2">
<CardHeader className="d-flex">
<p>Hello</p>
</CardHeader>
<CardBody>
<p>The Body</p>
<Row>
<Col md="5">
<dl>
<dt>GroupID</dt>
<dd>{item.GroupID}</dd>
<dt>Name</dt>
<dd>{item.name}</dd>
</dl>
</Col>
</Row>
</CardBody>
</Card>
))}
</div>
:
<div>
<PageLoadSpinner inProgress={inProgress} />
</div>
}
</>
)
}
export default Items;

Flickering issue with antd

I am using the Ant Design components for some interfaces in a React App but I'm noticing an issue with Modals and Tooltips. Usually when the modal is empty or is simple - e.g has only a text it is going to show properly but in case there are more elements on it (on production scenario) it flickers.
You can visually watch the flickering issue here: https://drive.google.com/file/d/1ODsj-aGz6saHJLXLI7sJaesgHKKPrvD2/view
Hope to get some answers :-) Thank you!
The visibleRequest state variable is triggered true by a button in the interface.
EDIT: As requested here's my code:
renderRequests=()=>{
const data = [
{name:"Request #1",description:"Request description",status:"0"},
{name:"Request #1",description:"Request description",status:"1"},
{name:"Request #1",description:"Request description",status:"2"}
];
const handleOk = ()=>{
console.log("Submitted");
this.setState({visibleRequest:false})
}
const handleCancel = ()=>{
this.setState({visibleRequest:false})
}
return(
<div style={{overflowY:"scroll"}}>
<Modal
title="Submit new request"
visible={this.state.visibleRequest}
onOk={handleOk}
onCancel={handleCancel}
>
<Input placeholder="Title"/>
<Input.TextArea placeholder="Description"/>
<DatePicker/>
</Modal>
<List
dataSource={data}
renderItem={item=>{
return(
<List.Item>
<List.Item.Meta
title={item.name}
description={item.description}
/>
{item.status==1?<Tooltip title="Request approved">
<Icon type="check-circle" theme="twoTone" twoToneColor="#52c41a" />
</Tooltip>:
item.status==2?<Icon type="close-circle" theme="twoTone" twoToneColor="#7F1C43" />:<Icon type="ellipsis" theme="outlined" />}
</List.Item>
)
}}/>
<Pagination total={20}/>
</div>
)
}

Resources