| 165 | |
| 166 | @polyfill |
| 167 | export class DateInput extends AbstractPureComponent2<IDateInputProps, IDateInputState> { |
| 168 | public static displayName = `${DISPLAYNAME_PREFIX}.DateInput`; |
| 169 | |
| 170 | public static defaultProps: Partial<IDateInputProps> = { |
| 171 | closeOnSelection: true, |
| 172 | dayPickerProps: {}, |
| 173 | disabled: false, |
| 174 | invalidDateMessage: "Invalid date", |
| 175 | maxDate: getDefaultMaxDate(), |
| 176 | minDate: getDefaultMinDate(), |
| 177 | outOfRangeMessage: "Out of range", |
| 178 | reverseMonthAndYearMenus: false, |
| 179 | }; |
| 180 | |
| 181 | public state: IDateInputState = { |
| 182 | isInputFocused: false, |
| 183 | isOpen: false, |
| 184 | value: this.props.value !== undefined ? this.props.value : this.props.defaultValue, |
| 185 | valueString: null, |
| 186 | }; |
| 187 | |
| 188 | private inputEl: HTMLInputElement | IRefObject<HTMLInputElement> | null = null; |
| 189 | private popoverContentEl: HTMLElement | null = null; |
| 190 | private lastElementInPopover: HTMLElement | null = null; |
| 191 | |
| 192 | private refHandlers = { |
| 193 | input: isRefObject<HTMLInputElement>(this.props.inputProps?.inputRef) |
| 194 | ? (this.inputEl = this.props.inputProps.inputRef) |
| 195 | : (ref: HTMLInputElement | null) => { |
| 196 | this.inputEl = ref; |
| 197 | (this.props.inputProps?.inputRef as IRefCallback<HTMLInputElement>)?.(ref); |
| 198 | }, |
| 199 | }; |
| 200 | |
| 201 | public componentWillUnmount() { |
| 202 | super.componentWillUnmount(); |
| 203 | this.unregisterPopoverBlurHandler(); |
| 204 | } |
| 205 | |
| 206 | public render() { |
| 207 | const { value, valueString } = this.state; |
| 208 | const dateString = this.state.isInputFocused ? valueString : getFormattedDateString(value, this.props); |
| 209 | const dateValue = isDateValid(value) ? value : null; |
| 210 | const dayPickerProps = { |
| 211 | ...this.props.dayPickerProps, |
| 212 | // dom elements for the updated month is not available when |
| 213 | // onMonthChange is called. setTimeout is necessary to wait |
| 214 | // for the updated month to be rendered |
| 215 | onMonthChange: (month: Date) => { |
| 216 | Utils.safeInvoke(this.props.dayPickerProps.onMonthChange, month); |
| 217 | this.setTimeout(this.registerPopoverBlurHandler); |
| 218 | }, |
| 219 | }; |
| 220 | |
| 221 | const wrappedPopoverContent = ( |
| 222 | <div ref={ref => (this.popoverContentEl = ref)}> |
| 223 | <DatePicker |
| 224 | {...this.props} |
nothing calls this directly
no test coverage detected