Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove input range from react date range picker?

Image is showing date range pickerenter image description here

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,

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')}
        />
    )
}

}

like image 634
Hasmukh Lohar Avatar asked Feb 08 '26 00:02

Hasmukh Lohar


2 Answers

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'. The staticRanges with an empty array hides the buttons saying 'Yesterday' etc.

You can see these documented here: https://www.npmjs.com/package/react-date-range

I also added a line of CSS to hide the container for these inputs:

.rdrDefinedRangesWrapper {
    display: none;
}
like image 114
Worm Avatar answered Feb 09 '26 14:02

Worm


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.

.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.

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;
}

my react-date-range component after adding above code

My react-date-range component after adding above code.

like image 30
Abdullah Ansari Avatar answered Feb 09 '26 13:02

Abdullah Ansari