Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(module:date-picker,time-picker): prevent losing input focus #6171

Merged
merged 1 commit into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion components/date-picker/date-range-popup.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ import { getTimeConfig, isAllowedDate, PREFIX_CLASS } from './util';
<span class="ant-tag ant-tag-blue">{{ name }}</span>
</li>
</ng-template>
`
`,
host: {
'(mousedown)': 'onMousedown($event)'
}
})
export class DateRangePopupComponent implements OnInit, OnChanges, OnDestroy {
@Input() isRange!: boolean;
Expand Down Expand Up @@ -202,6 +205,14 @@ export class DateRangePopupComponent implements OnInit, OnChanges, OnDestroy {
this.updateActiveDate();
}

/**
* Prevent input losing focus when click panel
* @param event
*/
onMousedown(event: MouseEvent): void {
event.preventDefault();
}

onClickOk(): void {
const inputIndex = { left: 0, right: 1 }[this.datePickerService.activeInput];
const value: CandyDate = this.isRange
Expand Down
11 changes: 10 additions & 1 deletion components/time-picker/time-picker-panel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ export type NzTimePickerUnit = 'hour' | 'minute' | 'second' | '12-hour';
'[class.ant-picker-time-panel-column-2]': `enabledColumns === 2 && !nzInDatePicker`,
'[class.ant-picker-time-panel-column-3]': `enabledColumns === 3 && !nzInDatePicker`,
'[class.ant-picker-time-panel-narrow]': `enabledColumns < 3`,
'[class.ant-picker-time-panel-placement-bottomLeft]': `!nzInDatePicker`
'[class.ant-picker-time-panel-placement-bottomLeft]': `!nzInDatePicker`,
'(mousedown)': 'onMousedown($event)'
},
providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: NzTimePickerPanelComponent, multi: true }]
})
Expand Down Expand Up @@ -566,4 +567,12 @@ export class NzTimePickerPanelComponent implements ControlValueAccessor, OnInit,
registerOnTouched(fn: () => void): void {
this.onTouch = fn;
}

/**
* Prevent input losing focus when click panel
* @param event
*/
onMousedown(event: MouseEvent): void {
event.preventDefault();
}
}