简体   繁体   中英

Prevent date picker from scrolling with page

I am making a react app which has datepicker made up of antd

Simple index.js code:

import React from "react";
import ReactDOM from "react-dom";
import { DatePicker } from "antd";
import "antd/dist/antd.css";
import "./index.css";

ReactDOM.render(
  <div className="App">
    <h1>Select date-picker scroll bug.</h1>
    <div
      style={{ marginTop: "16px", width: 500, overflow: "scroll", height: 400 }}
    >
      <DatePicker />
      <div style={{ minHeight: 500 }}></div>
    </div>
  </div>,
  document.getElementById("root")
);

Working Example:

编辑 antd 复制模板(分叉)

To Reproduce : If user clicks on the input, datepicker displayed but when we try to scroll down, the datepicker also get scrolled along with the page.

Expected Result : Datepicker should not get scrolled and it needs to be under the input box.

Any help would be highly appreciable. Thanks in advance.

This is described in their FAQ: https://ant.design/docs/react/faq#How-do-I-prevent-Select-Dropdown-DatePicker-TimePicker-Popover-Popconfirm-scrolling-with-the-page ?

  1. Add position: "relative" to the parent element.
  2. Add getPopupContainer={trigger => trigger.parentElement} to your DatePicker .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM