From ad1dd8ee6d7c5a51f302dbded7fc98a74d7a4f9f Mon Sep 17 00:00:00 2001 From: javadbat Date: Fri, 8 Sep 2023 16:41:39 +0330 Subject: [PATCH] add `JBDateInputEventType` to event type --- CHANGELOG.md | 3 +++ lib/JBDateInput.tsx | 15 +++++++++------ package.json | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16b5f96..b3a7017 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ #changelog +## [2.1.0] - 2023-3-7 +### new features +- add `JBDateInputEventType` to event type for better event.target detection in typescript ## [2.0.21] - 2023-3-30 ### fixed - fix mandatory React children props diff --git a/lib/JBDateInput.tsx b/lib/JBDateInput.tsx index 67de4f1..83b7b4a 100644 --- a/lib/JBDateInput.tsx +++ b/lib/JBDateInput.tsx @@ -28,6 +28,9 @@ declare global { } } } +export type JBDateInputEventType = T & { + target: JBDateInputWebComponent +} export type JBDateInputProps = { label?: string, name?:string, @@ -35,9 +38,9 @@ export type JBDateInputProps = { max?: string, format?: string, className?:string, - onKeyup?: (e:KeyboardEvent)=>void, - onChange?: (e:Event)=>void, - onSelect?: (e:CustomEvent)=>void, + onKeyup?: (e:JBDateInputEventType)=>void, + onChange?: (e:JBDateInputEventType)=>void, + onSelect?: (e:JBDateInputEventType)=>void, valueType?: 'GREGORIAN'|'JALALI'|'TIME_STAMP', inputType?: 'GREGORIAN'|'JALALI', direction?: 'ltr'|'rtl', @@ -61,17 +64,17 @@ export const JBDateInput = React.forwardRef((props: JBDateInputProps, ref) => { useEffect(() => { refChangeCountSetter(refChangeCount + 1); }, [element.current]); - const onchange = useCallback((e) => { + const onchange = useCallback((e:JBDateInputEventType) => { if (props.onChange) { props.onChange(e); } }, [props.onChange]); - const onKeyup = useCallback((e) => { + const onKeyup = useCallback((e:JBDateInputEventType) => { if (props.onKeyup) { props.onKeyup(e); } }, [props.onKeyup]); - const onSelect = useCallback((e) => { + const onSelect = useCallback((e:JBDateInputEventType) => { if (props.onSelect) { props.onSelect(e); } diff --git a/package.json b/package.json index 9a51eaf..95f74fa 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "react component", "react" ], - "version": "2.0.21", + "version": "2.1.0", "bugs": "https://github.com/javadbat/jb-date-input-react/issues", "license": "MIT", "files": [