Skip to content

Commit ffff04a

Browse files
committed
fix multiple keyboard event bind
1 parent 62340e8 commit ffff04a

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# changelog
22

3-
## [5.4.0] - upcoming
3+
## [5.4.5] - 2025-02-13
44

55
### new features:
66
- add new Events like `onLoad`,`onInit`, `onInvalid`, `onInput`, `onBeforeInput`, `onKeyPress`, `onKeyDown` to react component & `beforeinput`, `input`, `keydown` to web component.
77
- add `jb-core` as a dependency to make all events following the new events standard.
8+
- capture and silent input keyboard events to unify all keyboard events
89

910
## [5.3.0] - 2024-11-30
1011
### Breaking changes:

lib/jb-date-input.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import { checkMaxValidation, checkMinValidation, getEmptyValueObject, handleDayB
1313
import { enToFaDigits, faToEnDigits } from '../../../common/scripts/persian-helper';
1414
import { ValidationHelper, type ValidationResult, type ValidationItem, type WithValidation, type ShowValidationErrorInput} from 'jb-validation';
1515
import { requiredValidation } from './validations';
16-
import { isMobile } from '../../../common/scripts/device-detection';
1716
// eslint-disable-next-line no-duplicate-imports
1817
import { JBInputWebComponent } from 'jb-input';
19-
import { createInputEvent, createKeyboardEvent, createFocusEvent } from 'jb-core';
18+
import { createInputEvent, createKeyboardEvent, createFocusEvent, listenAndSilentEvent, isMobile } from 'jb-core';
2019
export * from "./types.js";
2120

2221
if (HTMLElement == undefined) {
@@ -375,12 +374,13 @@ export class JBDateInputWebComponent extends HTMLElement implements WithValidati
375374
}
376375
}
377376
#registerEventListener() {
378-
this.elements.input.addEventListener('blur', this.#onInputBlur.bind(this), { passive: false, capture:false });
379-
this.elements.input.addEventListener('focus', this.#onInputFocus.bind(this), { passive: false, capture:false });
380377
this.elements.input.addEventListener('beforeinput', this.#onInputBeforeInput.bind(this));
381-
this.elements.input.addEventListener('keypress', this.#onInputKeyPress.bind(this), { capture:false });
382-
this.elements.input.addEventListener('keyup', this.#onInputKeyup.bind(this), { capture:false });
383-
this.elements.input.addEventListener('keydown', this.#onInputKeydown.bind(this),{capture:false});
378+
listenAndSilentEvent(this.elements.input, 'focus', this.#onInputFocus.bind(this),{passive:true});
379+
listenAndSilentEvent(this.elements.input, 'blur', this.#onInputBlur.bind(this),{passive:true});
380+
listenAndSilentEvent(this.elements.input, 'keypress', this.#onInputKeyPress.bind(this));
381+
listenAndSilentEvent(this.elements.input, 'keyup', this.#onInputKeyup.bind(this));
382+
listenAndSilentEvent(this.elements.input, 'keydown', this.#onInputKeydown.bind(this));
383+
384384
//
385385
this.elements.calendarTriggerButton.addEventListener('focus', this.#onCalendarButtonFocused.bind(this));
386386
this.elements.calendarTriggerButton.addEventListener('blur', this.#onCalendarButtonBlur.bind(this));
@@ -683,7 +683,6 @@ export class JBDateInputWebComponent extends HTMLElement implements WithValidati
683683
this.dispatchEvent(keyPressEvent);
684684
}
685685
#onInputKeyup(e: KeyboardEvent) {
686-
debugger;
687686
this.#updateValueFromInputString(this.#sInputValue);
688687
this.#dispatchOnInputKeyup(e);
689688
}

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
"jb",
1111
"jb-date-input",
1212
"calendar",
13+
"date input",
1314
"jalali calendar",
1415
"jalali date",
1516
"shamsi",
1617
"jalali",
1718
"web component",
19+
"react component",
1820
"persian date",
1921
"persian calendar",
2022
"persian date input",
@@ -28,7 +30,7 @@
2830
"jalali web-component",
2931
"jalali web component"
3032
],
31-
"version": "5.4.3",
33+
"version": "5.4.5",
3234
"bugs": "https://github.com/javadbat/jb-date-input/issues",
3335
"license": "MIT",
3436
"files": [
@@ -50,11 +52,11 @@
5052
"dependencies": {
5153
"date-fns": "^2.28.0",
5254
"date-fns-jalali": "^2.28.0-1",
53-
"jb-calendar": ">=4.1.5",
55+
"jb-calendar": ">=4.2.2",
5456
"jb-popover":">=1.1.0",
5557
"jb-validation":">=0.2.0",
56-
"jb-input":">=3.6.1",
57-
"jb-core":"0.0.4"
58+
"jb-input":">=3.6.2",
59+
"jb-core":"0.1.0"
5860
},
5961
"devDependencies": {
6062
"jb-form":">=0.6.10"

react/lib/events-hook.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export type EventProps = {
2121
onChange?: (e: JBDateInputEventType<Event>) => void,
2222
onInput?: (e: JBDateInputEventType<InputEvent>) => void,
2323
onBeforeInput?: (e: JBDateInputEventType<InputEvent>) => void,
24-
onKeyUp1?: (e: JBDateInputEventType<KeyboardEvent>) => void,
24+
onKeyUp?: (e: JBDateInputEventType<KeyboardEvent>) => void,
2525
onKeyPress?: (e: JBDateInputEventType<KeyboardEvent>) => void,
2626
onKeyDown?: (e: JBDateInputEventType<KeyboardEvent>) => void,
2727
/*
@@ -42,7 +42,7 @@ export function useEvents(element:RefObject<JBDateInputWebComponent>,props:Event
4242
useEvent(element, 'change', props.onChange, true);
4343
useEvent(element, 'beforeinput', props.onBeforeInput, false);
4444
useEvent(element, 'input', props.onInput, true);
45-
useEvent(element, 'keyup', props.onKeyUp1, true);
45+
useEvent(element, 'keyup', props.onKeyUp, true);
4646
useEvent(element, 'keydown', props.onKeyDown, false);
4747
useEvent(element, 'keypress', props.onKeyPress, true);
4848
useEvent(element, 'select', props.onSelect, true);

react/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"../../../common/hooks/**/*.js",
99
"lib/**/*.ts",
1010
"lib/**/*.tsx"
11-
],
11+
, "../../jb-core/lib/device-detection.ts" ],
1212
"exclude": [
1313
"node_modules",
1414
"**/*.spec.ts",

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"include": [
66
"../global.d.ts",
77
"lib/**/*.ts",
8-
"../../common/scripts/**/*.ts",
8+
"../../common/scripts/**/*.ts", "../jb-core/lib/device-detection.ts",
99
],
1010
"exclude": [
1111
"node_modules",

0 commit comments

Comments
 (0)