Browse Source

fix(date-picker): fix focus

pull/14264/head
Yangzhedi 6 years ago
committed by 偏右
parent
commit
f52b087194
  1. 11
      components/date-picker/RangePicker.tsx
  2. 11
      components/date-picker/WeekPicker.tsx
  3. 10
      components/date-picker/createPicker.tsx

11
components/date-picker/RangePicker.tsx

@ -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 });

11
components/date-picker/WeekPicker.tsx

@ -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>) => {

10
components/date-picker/createPicker.tsx

@ -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() {

Loading…
Cancel
Save