简体   繁体   English

如何从反应日期范围选择器中删除输入范围?

[英]How to remove input range from react date range picker?

Image is showing date range picker图像显示日期范围选择器在此处输入图像描述

I want to remove days up to today and days starting today both label from date range picker how can i do that my code snippet is,我想从日期范围选择器中删除截至今天的天数和从今天开始的天数 label 我该怎么做我的代码片段是,

class BetterDatePicker extends Component {
constructor(props) {
    super(props);
    this.state = {
        selectionRange: {
            startDate: new Date(),
            endDate: new Date(),
            key: 'selection',
        }
    }
}
handleSelect = (ranges) => {
    console.log("range", ranges);
    this.setState({
        selectionRange: ranges.selection
    })
}
render() {
    return (
        <DateRangePicker
            ranges={[this.state.selectionRange]}
            onChange={this.handleSelect}
            minDate={new Date('2020')}
            maxDate={new Date('2022')}
        />
    )
}

} }

You can simply do this with the following code:您可以使用以下代码简单地执行此操作:

<DateRangePicker
    staticRanges={[]}
    inputRanges={[]}
/>

The inputRanges with an empty array hides the 'days up to today' and 'days starting today'.具有空数组的inputRanges隐藏了“到今天的天数”和“从今天开始的天数”。 The staticRanges with an empty array hides the buttons saying 'Yesterday' etc.带有空数组的staticRanges隐藏了“昨天”等按钮。

You can see these documented here: https://www.npmjs.com/package/react-date-range您可以在此处查看这些文档: https://www.npmjs.com/package/react-date-range

I also added a line of CSS to hide the container for these inputs:我还添加了一行 CSS 来隐藏这些输入的容器:

.rdrDefinedRangesWrapper {
    display: none;
}

In order to hide that simply add the following line in the global CSS file of your project, it will override the react-date-range component's style.为了隐藏它,只需在项目的全局 CSS 文件中添加以下行,它将覆盖 react-date-range 组件的样式。

.rdrDefinedRangesWrapper {
      display: none;
 }

In my case where I am working on a Next.js project I just added the above code in styles/globals.css , I have also attached the snippet of my globals.css file below.在我从事 Next.js 项目的情况下,我刚刚在styles/globals.css中添加了上述代码,我还在下面附上了我的 globals.css 文件的片段。

html,
body {
  padding: 0;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
    Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

* {
  box-sizing: border-box;
}
/*to hide left panel from date range picker */
.rdrDefinedRangesWrapper {
  display: none;
}

添加上述代码后我的 react-date-range 组件

My react-date-range component after adding above code.添加上述代码后我的 react-date-range 组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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