Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Fix shortcut keys prevented in date fields (#5009)

shamoon55dadf0b004f
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()
}
}