user10727653
user10727653

Reputation:

making antd modal full screen without any padding or margins

I'm new to programming. Here I have an antd modal and I've been trying to find a way to make it full screen. I want the modal to be full scree when it's opened and it shouldn't have any margin or paddings. For example, in the code I added width={1000} but there is still some margin on the left and right of the modal.

So how do I make the modal to take the whole screen without any margin and padding?

code: https://codesandbox.io/s/otjy6?file=/index.js:539-560

Upvotes: 8

Views: 22593

Answers (3)

Mohamed Swadique K
Mohamed Swadique K

Reputation: 331

I think instead of Modal you can use the Antd Drawer. Here is the implementation.

import React,{useState} from 'react';
import {Drawer} from 'antd;

const FullScreenDrawer = ()=>{
  const [visible,setVisible] = useState(false)
  
  return(
    <>
      <button onClick={()=>setVisible(true)/>
      <Drawer
        visible={isVisible}
        onClose={() => setVisible(false)}
        width="100VW"
       >
       The content goes here
      </Drawer>
    </>
    );
    }


 

Upvotes: 2

Rami Assi
Rami Assi

Reputation: 1129

  1. Remove the fixed value for modal width and the centered attribute from your code file:

index.js

import React, { useState } from 'react';
import ReactDOM from 'react-dom';
import 'antd/dist/antd.css';
import './index.css';
import { Modal, Button } from 'antd';

const App = () => {
  const [visible, setVisible] = useState(false);
  return (
    <>
      <Button type="primary" onClick={() => setVisible(true)}>
        Open Modal of 1000px width
      </Button>
      <Modal
        title="Modal 1000px width"
        // This was removed
        // centered
        visible={visible}
        onOk={() => setVisible(false)}
        onCancel={() => setVisible(false)}
        // This was removed
        // width={'1000'}
      >
        <p>some contents...</p>
        <p>some contents...</p>
        <p>some contents...</p>
      </Modal>
    </>
  );
};

ReactDOM.render(<App />, document.getElementById('container'));
  1. You need to add these CSS rules to the CSS file.

index.css

.ant-modal, .ant-modal-content {
 height: 100vh;
 width: 100vw;
 margin: 0;
 top: 0;
}
.ant-modal-body {
 height: calc(100vh - 110px);
}

Upvotes: 7

Priyank Kachhela
Priyank Kachhela

Reputation: 2635

  1. you need to unset max-width and margin of modal
.ant-modal {
  max-width: unset;
  margin: unset;
}
  1. you need to unset content in before pseudo-element of ant-modal-centered class
.ant-modal-centered::before {
  content: unset;
}

Working Demo

Upvotes: 1

Related Questions