Skip to content

Instantly share code, notes, and snippets.

@aldis-ameriks
Created August 22, 2018 11:45
Show Gist options
  • Save aldis-ameriks/8bf7069fe025cca156fba9626d9833a4 to your computer and use it in GitHub Desktop.
Save aldis-ameriks/8bf7069fe025cca156fba9626d9833a4 to your computer and use it in GitHub Desktop.
Disabling start date in DateRangePicker
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;
@aldis-ameriks
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment