问题:
我已经创建了一个React应用程序,在那里我创建了一个既带有模式又带有React的弹出框的组件。但是只有模型显示出它没有显示弹出窗口,否则有人可以通过修改我的代码来帮助我解决此问题。
这是我的组件。
import React, { Component } from "react";
import {
Card,
CardText,
Container,
Row,
Col,
Button,
Modal,
ModalHeader,
ModalBody,
ModalFooter,
Popover,
PopoverHeader,
PopoverBody
} from "reactstrap";
import "./Dashbord.css";
class YearCard extends Component {
constructor(props) {
super(props);
this.state = {
modal: false,
popoverOpen: false
};
this.toggle = this.toggle.bind(this);
this.toggleModal = this.toggleModal.bind(this);
}
toggle() {
this.setState(prevState => ({
modal: !prevState.modal
}));
}
toggleModal() {
this.setState({
popoverOpen: !this.state.popoverOpen
});
}
render() {
return (
<Card className="year" id="Popover1">
<Container>
<CardText className="year-text">Year</CardText>
</Container>
<div className="year-full-screen" onClick={this.toggle}>
<i className="fas fa-expand-arrows-alt" />
</div>
<Modal
className="modal-dialog"
isOpen={this.state.modal}
fade={false}
toggle={this.toggle}
>
<ModalHeader toggle={this.toggle}>Modal title</ModalHeader>
<ModalBody>My Modal</ModalBody>
<ModalFooter>
<Button color="primary" onClick={this.toggle}>
Do Something
</Button>{" "}
<Button color="secondary" onClick={this.toggle}>
Cancel
</Button>
</ModalFooter>
</Modal>
<hr className="horizentel-line" />
<Popover
placement="bottom"
isOpen={this.state.popoverOpen}
target="Popover1"
toggle={this.toggle}
>
<PopoverHeader>Popover Title</PopoverHeader>
<PopoverBody>
Sed posuere consectetur est at lobortis. Aenean eu leo quam.
Pellentesque ornare sem lacinia quam venenatis vestibulum.
</PopoverBody>
</Popover>
</Card>
);
}
}
export default YearCard;
这是我的CSS文件。
body {
overflow-x: hidden;
}
.year {
width: 5%;
height: 48px;
margin-top: 1%;
margin-left: 1%;
}
.year:hover {
border-width: 1px;
border-color: black;
}
.year:hover .year-full-screen {
display: block;
}
.month:hover .month-full-screen {
display: block;
}
.year-text {
font-weight: 700;
font-size: 12px;
padding-top: 8px;
text-align: left;
}
.month {
width: 5%;
height: 48px;
margin-top: 1%;
margin-left: 1%;
}
.month:hover {
border-width: 1px;
border-color: black;
}
.month-text {
font-weight: 700;
font-size: 12px;
padding-top: 8px;
text-align: left;
}
.background-gray {
background-color: #f2f2f2;
}
.year-full-screen {
display: none;
margin-left: 70%;
cursor: pointer;
z-index: 2;
margin-top: -30px;
font-size: 30px;
background-color: rgb(250, 250, 250);
}
.month-full-screen {
display: none;
margin-left: 70%;
cursor: pointer;
z-index: 2;
margin-top: -30px;
font-size: 30px;
background-color: rgb(250, 250, 250);
}
.horizentel-line {
z-index: 1;
}
.horizentel-line-month {
z-index: 1;
}
.year:hover .horizentel-line {
margin-top: 1px;
}
.month:hover .horizentel-line-month {
margin-top: 1px;
}
.subscribers {
margin-left: 1%;
}
/*desktops and laptops*/
@media only screen and (min-width: 1024px) {
.year {
width: 6%;
height: 48px;
margin-top: 1%;
margin-left: 2%;
}
.modal-dialog {
min-width: 100% !important;
margin-top: 4% !important;
}
.subscribers {
margin-left: 2%;
margin-top: 20px;
width: 13%;
height: 70px;
}
.subscribers-text {
font-family: sans-serif;
font-size: 12px;
line-height: 16.8px;
text-align: center;
color: #bdbdbd;
margin-top: 5px;
}
.subscribers-amount {
color: hsl(182, 75%, 30%);
display: inline;
font-size: 30.2962px;
text-align: center;
margin-top: -20px;
}
.channels-amount {
color: #53c9fc;
display: inline;
font-size: 30.2962px;
text-align: center;
margin-top: -20px;
}
.channels-text {
font-family: sans-serif;
font-size: 12px;
line-height: 16.8px;
text-align: center;
color: #bdbdbd;
margin-top: 5px;
}
.channels {
margin-left: 2%;
margin-top: 20px;
width: 13%;
height: 70px;
}
.month {
width: 6%;
height: 48px;
margin-top: 1%;
margin-left: 1%;
}
.year-full-screen {
display: none;
margin-left: 65%;
cursor: pointer;
z-index: 0;
margin-top: -30px;
font-size: 30px;
background-color: rgb(250, 250, 250);
}
.month-full-screen {
display: none;
margin-left: 65%;
cursor: pointer;
z-index: 2;
margin-top: -30px;
font-size: 30px;
background-color: rgb(250, 250, 250);
}
}
/*tabs*/
@media only screen and (min-width: 308px) and (max-width: 1024px) {
.year {
width: 40%;
height: 65px;
margin-top: 1%;
margin-left: 6%;
}
.year:hover {
border-width: 1px;
border-color: black;
}
.year:hover .year-full-screen {
display: block;
}
.month:hover .month-full-screen {
display: block;
}
.year-text {
font-weight: 800;
font-size: 20px;
padding-top: 8px;
text-align: left;
}
.month {
width: 45%;
height: 65px;
margin-top: 1%;
margin-left: 3%;
}
.month:hover {
border-width: 1px;
border-color: black;
}
.month-text {
font-weight: 800;
font-size: 20px;
padding-top: 8px;
text-align: left;
}
.background-gray {
background-color: #f2f2f2;
}
.year-full-screen {
display: none;
margin-left: 90%;
cursor: pointer;
z-index: 2;
margin-top: -30px;
font-size: 30px;
background-color: rgb(250, 250, 250);
}
.month-full-screen {
display: none;
margin-left: 90%;
cursor: pointer;
z-index: 2;
margin-top: -30px;
font-size: 30px;
background-color: rgb(250, 250, 250);
}
.horizentel-line {
z-index: 1;
}
.horizentel-line-month {
z-index: 1;
}
.year:hover .horizentel-line {
margin-top: 1px;
}
.month:hover .horizentel-line-month {
margin-top: 1px;
}
.subscribers {
margin-left: 6%;
margin-top: 20px;
width: 88%;
height: 70px;
}
.subscribers-text {
font-family: sans-serif;
font-size: 12px;
line-height: 16.8px;
text-align: center;
color: #bdbdbd;
margin-top: 5px;
}
.subscribers-amount {
color: hsl(182, 75%, 30%);
display: inline;
font-size: 30.2962px;
text-align: center;
margin-top: -20px;
}
.channels-amount {
color: hsl(182, 75%, 30%);
display: inline;
font-size: 30.2962px;
text-align: center;
margin-top: -20px;
}
.channels-text {
font-family: sans-serif;
font-size: 12px;
line-height: 16.8px;
text-align: center;
color: #bdbdbd;
margin-top: 5px;
}
.channels {
margin-left: 6%;
margin-top: 20px;
width: 88%;
height: 70px;
}
}
这里,我要做的是单击全屏图标时显示模型。并在点击卡片时显示弹出窗口。但是我的代码现在要做的是单击卡时显示模型,但是单击全屏图标时不显示任何内容。如果有人可以帮助我,将不胜感激。