fix(date-picker): fix focus

This commit is contained in:
Yangzhedi 2019-01-04 16:55:07 +08:00 committed by 偏右
parent 1e62802d58
commit f52b087194
3 changed files with 20 additions and 12 deletions

View File

@ -12,6 +12,7 @@ import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import warning from '../_util/warning';
import interopDefault from '../_util/interopDefault';
import { RangePickerValue, RangePickerPresetRange } from './interface';
import { PickerProps } from './createPicker';
export interface RangePickerState {
value?: RangePickerValue;
@ -124,6 +125,12 @@ class RangePicker extends React.Component<any, RangePickerState> {
};
}
componentDidUpdate(prevProps: PickerProps) {
if ('open' in prevProps && prevProps.open) {
this.focus();
}
}
clearSelection = (e: React.MouseEvent<HTMLElement>) => {
e.preventDefault();
e.stopPropagation();
@ -158,10 +165,6 @@ class RangePicker extends React.Component<any, RangePickerState> {
if (onOpenChange) {
onOpenChange(open);
}
if (!open) {
this.focus();
}
};
handleShowDateChange = (showDate: RangePickerValue) => this.setState({ showDate });

View File

@ -7,6 +7,7 @@ import classNames from 'classnames';
import Icon from '../icon';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import interopDefault from '../_util/interopDefault';
import { PickerProps } from './createPicker';
function formatValue(value: moment.Moment | null, format: string): string {
return (value && value.format(format)) || '';
@ -55,6 +56,12 @@ class WeekPicker extends React.Component<any, WeekPickerState> {
};
}
componentDidUpdate(prevProps: PickerProps) {
if ('open' in prevProps && prevProps.open) {
this.focus();
}
}
weekDateRender = (current: any) => {
const selectedValue = this.state.value;
const { prefixCls } = this;
@ -90,10 +97,6 @@ class WeekPicker extends React.Component<any, WeekPickerState> {
if (onOpenChange) {
onOpenChange(open);
}
if (!open) {
this.focus();
}
};
clearSelection = (e: React.MouseEvent<HTMLElement>) => {

View File

@ -70,6 +70,12 @@ export default function createPicker(TheCalendar: React.ComponentClass): any {
};
}
componentDidUpdate(prevProps: PickerProps) {
if ('open' in prevProps && prevProps.open) {
this.focus();
}
}
renderFooter = (...args: any[]) => {
const { renderExtraFooter } = this.props;
const { prefixCls } = this;
@ -108,10 +114,6 @@ export default function createPicker(TheCalendar: React.ComponentClass): any {
if (onOpenChange) {
onOpenChange(open);
}
if (!open) {
this.focus();
}
};
focus() {