Skip to content

Commit

Permalink
chore: fix RangePicker value and onChange definition (#20015)
Browse files Browse the repository at this point in the history
  • Loading branch information
chj-damon authored and afc163 committed Dec 2, 2019
1 parent be06f53 commit cba968f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const eslintrc = {
'jsx-a11y/anchor-has-content': 0,
'jsx-a11y/click-events-have-key-events': 0,
'jsx-a11y/anchor-is-valid': 0,
'jsx-a11y/no-noninteractive-element-interactions': 0,
'comma-dangle': ['error', 'always-multiline'],
'react/jsx-filename-extension': 0,
'react/state-in-constructor': 0,
Expand Down
4 changes: 2 additions & 2 deletions components/date-picker/RangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function getShowDateFromValue(value: RangePickerValue, mode?: string | string[])
if (mode && mode[0] === 'month') {
return [start, end] as RangePickerValue;
}
const newEnd = end && end.isSame(start, 'month') ? end.clone().add(1, 'month') : end;
const newEnd = end && end.isSame(start!, 'month') ? end.clone().add(1, 'month') : end;
return [start, newEnd] as RangePickerValue;
}

Expand Down Expand Up @@ -162,7 +162,7 @@ class RangePicker extends React.Component<RangePickerProps, RangePickerState> {
showDate: getShowDateFromValue(value) || showDate,
}));
}
if (value[0] && value[0].diff(value[1]) > 0) {
if (value[0] && value[1] && value[0].diff(value[1]) > 0) {
value[1] = undefined;
}
const [start, end] = value;
Expand Down
21 changes: 12 additions & 9 deletions components/date-picker/interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ export interface PickerProps {
getCalendarContainer?: (triggerNode: Element) => HTMLElement;
open?: boolean;
onOpenChange?: (status: boolean) => void;
disabledDate?: (current: moment.Moment | undefined) => boolean;
disabledDate?: (current: moment.Moment | null) => boolean;
dateRender?: (current: moment.Moment, today: moment.Moment) => React.ReactNode;
autoFocus?: boolean;
onFocus?: React.FocusEventHandler;
onBlur?: (e: React.SyntheticEvent) => void;
}

export interface SinglePickerProps {
value?: moment.Moment;
defaultValue?: moment.Moment;
defaultPickerValue?: moment.Moment;
value?: moment.Moment | null;
defaultValue?: moment.Moment | null;
defaultPickerValue?: moment.Moment | null;
placeholder?: string;
renderExtraFooter?: (mode: DatePickerMode) => React.ReactNode;
onChange?: (date: moment.Moment | null, dateString: string) => void;
Expand All @@ -46,16 +46,16 @@ export interface DatePickerProps extends PickerProps, SinglePickerProps {
showTime?: TimePickerProps | boolean;
showToday?: boolean;
open?: boolean;
disabledTime?: (
current: moment.Moment | undefined,
disabledTime: (

This comment has been minimized.

Copy link
@dgomez-orangeloops

dgomez-orangeloops Dec 9, 2019

Contributor

@chj-damon disabledTime should be optional ?

disabledTime: -> disabledTime?:

This comment has been minimized.

Copy link
@afc163

afc163 Dec 9, 2019

Member

You are right, could you send us a PR? I will release a patch ASAP.

This comment has been minimized.

Copy link
@dgomez-orangeloops

dgomez-orangeloops Dec 9, 2019

Contributor
current?: moment.Moment | null,
) => {
disabledHours?: () => number[];
disabledMinutes?: () => number[];
disabledSeconds?: () => number[];
};
onOpenChange?: (status: boolean) => void;
onPanelChange?: (value: moment.Moment | undefined, mode: DatePickerMode) => void;
onOk?: (selectedTime: moment.Moment) => void;
onPanelChange?: (value: moment.Moment | null, mode: DatePickerMode) => void;
onOk?: (selectedTime: moment.Moment | null) => void;
mode?: DatePickerMode;
}

Expand All @@ -65,9 +65,12 @@ export interface MonthPickerProps extends PickerProps, SinglePickerProps {

export type RangePickerValue =
| undefined[]
| null[]
| [moment.Moment]
| [undefined, moment.Moment]
| [moment.Moment, undefined]
| [null, moment.Moment]
| [moment.Moment, null]
| [moment.Moment, moment.Moment];
export type RangePickerPresetRange = RangePickerValue | (() => RangePickerValue);

Expand All @@ -90,7 +93,7 @@ export interface RangePickerProps extends PickerProps {
mode?: string | string[];
separator?: React.ReactNode;
disabledTime?: (
current: moment.Moment | undefined,
current: RangePickerValue,
type: string,
) => {
disabledHours?: () => number[];
Expand Down

0 comments on commit cba968f

Please sign in to comment.