Skip to content

Commit

Permalink
add JBDateInputEventType to event type
Browse files Browse the repository at this point in the history
  • Loading branch information
javadbat committed Sep 8, 2023
1 parent e07e947 commit ad1dd8e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 9 additions & 6 deletions lib/JBDateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ declare global {
}
}
}
export type JBDateInputEventType<T> = T & {
target: JBDateInputWebComponent
}
export type JBDateInputProps = {
label?: string,
name?:string,
min?: string,
max?: string,
format?: string,
className?:string,
onKeyup?: (e:KeyboardEvent)=>void,
onChange?: (e:Event)=>void,
onSelect?: (e:CustomEvent)=>void,
onKeyup?: (e:JBDateInputEventType<KeyboardEvent>)=>void,
onChange?: (e:JBDateInputEventType<Event>)=>void,
onSelect?: (e:JBDateInputEventType<CustomEvent>)=>void,
valueType?: 'GREGORIAN'|'JALALI'|'TIME_STAMP',
inputType?: 'GREGORIAN'|'JALALI',
direction?: 'ltr'|'rtl',
Expand All @@ -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<Event>) => {
if (props.onChange) {
props.onChange(e);
}
}, [props.onChange]);
const onKeyup = useCallback((e) => {
const onKeyup = useCallback((e:JBDateInputEventType<KeyboardEvent>) => {
if (props.onKeyup) {
props.onKeyup(e);
}
}, [props.onKeyup]);
const onSelect = useCallback((e) => {
const onSelect = useCallback((e:JBDateInputEventType<CustomEvent>) => {
if (props.onSelect) {
props.onSelect(e);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down

0 comments on commit ad1dd8e

Please sign in to comment.