Created
August 22, 2018 11:45
-
-
Save aldis-ameriks/8bf7069fe025cca156fba9626d9833a4 to your computer and use it in GitHub Desktop.
Disabling start date in DateRangePicker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { DateRangePicker, FocusedInputShape } from 'react-dates'; | |
import 'react-dates/initialize'; | |
import 'react-dates/lib/css/_datepicker.css'; | |
import { FieldRenderProps } from 'react-final-form'; | |
type Props = { | |
disabledStartDate: boolean; | |
} & FieldRenderProps; | |
type State = { | |
focusedInput: 'startDate' | 'endDate' | null; | |
}; | |
class DateRangeInput extends React.Component<Props, State> { | |
constructor(props: Props) { | |
super(props); | |
this.onFocusChange = this.onFocusChange.bind(this); | |
this.state = { | |
focusedInput: null, | |
}; | |
} | |
public render() { | |
const { input, meta, disabledStartDate } = this.props; | |
const showError = meta.error && meta.touched; | |
return ( | |
<DateRangePicker | |
startDate={input.value.startDate} | |
startDateId="start-date" | |
startDatePlaceholderText="start date placeholder" | |
endDate={input.value.endDate} | |
endDateId="end-date" | |
endDatePlaceholderText="end date placeholder" | |
focusedInput={this.state.focusedInput} | |
onFocusChange={this.onFocusChange} | |
onDatesChange={input.onChange} | |
showDefaultInputIcon={true} | |
disabled={disabledStartDate ? 'startDate' : false} | |
/> | |
); | |
} | |
private onFocusChange(focusedInput: FocusedInputShape) { | |
this.setState({ focusedInput }); | |
} | |
} | |
export default DateRangeInput; |
Author
aldis-ameriks
commented
Aug 22, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment