4

Problem:

I have created A reactstrap Modal and now I want to add a custom styling to it so that I had a class and wrote CSS styling but it does not seem to work. Can someone help me to solve this problem?. This is my code.

import React, { Component } from "react";
import {
  Card,
  CardText,
  Container,
  Row,
  Col,
  Button,
  Modal,
  ModalHeader,
  ModalBody,
  ModalFooter
} from "reactstrap";

import "./Dashbord.css";

class YearCard extends Component {
  constructor(props) {
    super(props);
    this.state = {
      modal: false
    };

    this.toggle = this.toggle.bind(this);
  }

  toggle() {
    this.setState(prevState => ({
      modal: !prevState.modal
    }));
  }

  render() {
    return (
      <Card className="year">
        <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" />
      </Card>
    );
  }
}

export default YearCard;

This is my CSS.

 .modal-dialog {
    width: 100%;
    margin-top: 10%;
  }

I searched On the Internet to find a Solution to this problem. But I was unable to find any reasonable solution to this problem. If you can help me It would be a great pleasure for me.

1
  • Try with !important .modal-dialog { width: 100% !important; margin-top: 10% !important; } Commented Mar 9, 2019 at 2:32

3 Answers 3

3

These are the props available for reactstrap modal api, Reference here

<Modal 
  className: YourCustomClass,
  wrapClassName: YourCustomClass,
  modalClassName: YourCustomClass,
  backdropClassName: YourCustomClass,
  contentClassName: YourCustomClass
/> 
Sign up to request clarification or add additional context in comments.

2 Comments

But this solution is not working in reactstrap modal. It looks that only "style" will work and className not work in modal.
This is the solution. Then, you have to use the classes correctly 🤓🤙
3

Just setting the prop modalClassName as modal-dialog would do the trick.

<Modal
   modalClassName="modal-dialog"
   isOpen={this.state.modal}
   fade={false}
   toggle={this.toggle}
>
...

Comments

0

This worked for me

<Modal ClassName={`customClass`} />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.