Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit ad1dd8e

Browse files
committed
add JBDateInputEventType to event type
1 parent e07e947 commit ad1dd8e

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#changelog
2+
## [2.1.0] - 2023-3-7
3+
### new features
4+
- add `JBDateInputEventType` to event type for better event.target detection in typescript
25
## [2.0.21] - 2023-3-30
36
### fixed
47
- fix mandatory React children props

lib/JBDateInput.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,19 @@ declare global {
2828
}
2929
}
3030
}
31+
export type JBDateInputEventType<T> = T & {
32+
target: JBDateInputWebComponent
33+
}
3134
export type JBDateInputProps = {
3235
label?: string,
3336
name?:string,
3437
min?: string,
3538
max?: string,
3639
format?: string,
3740
className?:string,
38-
onKeyup?: (e:KeyboardEvent)=>void,
39-
onChange?: (e:Event)=>void,
40-
onSelect?: (e:CustomEvent)=>void,
41+
onKeyup?: (e:JBDateInputEventType<KeyboardEvent>)=>void,
42+
onChange?: (e:JBDateInputEventType<Event>)=>void,
43+
onSelect?: (e:JBDateInputEventType<CustomEvent>)=>void,
4144
valueType?: 'GREGORIAN'|'JALALI'|'TIME_STAMP',
4245
inputType?: 'GREGORIAN'|'JALALI',
4346
direction?: 'ltr'|'rtl',
@@ -61,17 +64,17 @@ export const JBDateInput = React.forwardRef((props: JBDateInputProps, ref) => {
6164
useEffect(() => {
6265
refChangeCountSetter(refChangeCount + 1);
6366
}, [element.current]);
64-
const onchange = useCallback((e) => {
67+
const onchange = useCallback((e:JBDateInputEventType<Event>) => {
6568
if (props.onChange) {
6669
props.onChange(e);
6770
}
6871
}, [props.onChange]);
69-
const onKeyup = useCallback((e) => {
72+
const onKeyup = useCallback((e:JBDateInputEventType<KeyboardEvent>) => {
7073
if (props.onKeyup) {
7174
props.onKeyup(e);
7275
}
7376
}, [props.onKeyup]);
74-
const onSelect = useCallback((e) => {
77+
const onSelect = useCallback((e:JBDateInputEventType<CustomEvent>) => {
7578
if (props.onSelect) {
7679
props.onSelect(e);
7780
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"react component",
1919
"react"
2020
],
21-
"version": "2.0.21",
21+
"version": "2.1.0",
2222
"bugs": "https://github.com/javadbat/jb-date-input-react/issues",
2323
"license": "MIT",
2424
"files": [

0 commit comments

Comments
 (0)