From 55dadf0b004fa39d7928423a51105c74d4a98291 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 17 Dec 2023 17:07:09 -0800 Subject: [PATCH] Fix shortcut keys prevented in date fields (#5009) --- .../common/input/date/date.component.spec.ts | 30 +++++++++++++++++++ .../common/input/date/date.component.ts | 6 +++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src-ui/src/app/components/common/input/date/date.component.spec.ts b/src-ui/src/app/components/common/input/date/date.component.spec.ts index 2b5467412..766d7fa02 100644 --- a/src-ui/src/app/components/common/input/date/date.component.spec.ts +++ b/src-ui/src/app/components/common/input/date/date.component.spec.ts @@ -81,6 +81,16 @@ describe('DateComponent', () => { expect(eventSpy).toHaveBeenCalled() }) + it('should show allow system keyboard events', () => { + let event: KeyboardEvent = new KeyboardEvent('keypress', { + key: '9', + altKey: true, + }) + let preventDefaultSpy = jest.spyOn(event, 'preventDefault') + input.dispatchEvent(event) + expect(preventDefaultSpy).not.toHaveBeenCalled() + }) + it('should support paste', () => { expect(component.value).toBeUndefined() const date = '5/4/20' @@ -99,5 +109,25 @@ describe('DateComponent', () => { event['clipboardData'] = clipboardData input.dispatchEvent(event) expect(component.value).toEqual({ day: 4, month: 5, year: 2020 }) + // coverage + window['clipboardData'] = { + getData: (type) => '', + } + component.onPaste(new Event('foo') as any) + }) + + it('should set filter button title', () => { + component.title = 'foo' + expect(component.filterButtonTitle).toEqual( + 'Filter documents with this foo' + ) + }) + + it('should emit date on filter', () => { + let dateReceived + component.value = '12/16/2023' + component.filterDocuments.subscribe((date) => (dateReceived = date)) + component.onFilterDocuments() + expect(dateReceived).toEqual([{ day: 16, month: 12, year: 2023 }]) }) }) diff --git a/src-ui/src/app/components/common/input/date/date.component.ts b/src-ui/src/app/components/common/input/date/date.component.ts index 36bbea57c..9d96379e3 100644 --- a/src-ui/src/app/components/common/input/date/date.component.ts +++ b/src-ui/src/app/components/common/input/date/date.component.ts @@ -90,7 +90,11 @@ export class DateComponent } onKeyPress(event: KeyboardEvent) { - if ('Enter' !== event.key && !/[0-9,\.\/-]+/.test(event.key)) { + if ( + 'Enter' !== event.key && + !(event.altKey || event.metaKey || event.ctrlKey) && + !/[0-9,\.\/-]+/.test(event.key) + ) { event.preventDefault() } }