Skip to content

Commit

Permalink
fix: incorrect oninput + onsubmit type
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Dec 7, 2023
1 parent 2629e40 commit 0df2dbf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,10 @@ export namespace JSXInternal {
Target,
SubmitEvent
>;
export type TargetedInputEvent<Target extends EventTarget> = TargetedEvent<
Target,
InputEvent
>;
export type TargetedTouchEvent<Target extends EventTarget> = TargetedEvent<
Target,
TouchEvent
Expand Down Expand Up @@ -1492,6 +1496,9 @@ export namespace JSXInternal {
export type FocusEventHandler<Target extends EventTarget> = EventHandler<
TargetedFocusEvent<Target>
>;
export type InputEventHandler<Target extends EventTarget> = EventHandler<
TargetedInputEvent<Target>
>;
export type GenericEventHandler<Target extends EventTarget> = EventHandler<
TargetedEvent<Target>
>;
Expand All @@ -1504,6 +1511,9 @@ export namespace JSXInternal {
export type PointerEventHandler<Target extends EventTarget> = EventHandler<
TargetedPointerEvent<Target>
>;
export type SubmitEventHandler<Target extends EventTarget> = EventHandler<
TargetedSubmitEvent<Target>
>;
export type TouchEventHandler<Target extends EventTarget> = EventHandler<
TargetedTouchEvent<Target>
>;
Expand Down Expand Up @@ -1563,14 +1573,14 @@ export namespace JSXInternal {
// Form Events
onChange?: GenericEventHandler<Target> | undefined;
onChangeCapture?: GenericEventHandler<Target> | undefined;
onInput?: GenericEventHandler<Target> | undefined;
onInputCapture?: GenericEventHandler<Target> | undefined;
onInput?: InputEventHandler<Target> | undefined;
onInputCapture?: InputEventHandler<Target> | undefined;
onBeforeInput?: GenericEventHandler<Target> | undefined;
onBeforeInputCapture?: GenericEventHandler<Target> | undefined;
onSearch?: GenericEventHandler<Target> | undefined;
onSearchCapture?: GenericEventHandler<Target> | undefined;
onSubmit?: TargetedSubmitEvent<Target> | undefined;
onSubmitCapture?: TargetedSubmitEvent<Target> | undefined;
onSubmit?: SubmitEventHandler<Target> | undefined;
onSubmitCapture?: SubmitEventHandler<Target> | undefined;
onInvalid?: GenericEventHandler<Target> | undefined;
onInvalidCapture?: GenericEventHandler<Target> | undefined;
onReset?: GenericEventHandler<Target> | undefined;
Expand Down
9 changes: 8 additions & 1 deletion test/ts/preact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,14 @@ createElement(RefComponentTest, { ref: functionRef }, 'hi');
h(RefComponentTest, { ref: functionRef }, 'hi');

// Should accept onInput
const onInput = (e: h.JSX.TargetedEvent<HTMLInputElement>) => {};
const onInput = (e: h.JSX.TargetedInputEvent<HTMLInputElement>) => {};
<input onInput={onInput} />;
<input onInput={e => e.currentTarget.value} />;
createElement('input', { onInput: onInput });
h('input', { onInput: onInput });

// Should accept onSubmit
const onSubmit = (e: h.JSX.TargetedSubmitEvent<HTMLFormElement>) => {};
<form onSubmit={e => e.currentTarget.elements} />;
createElement('form', { onSubmit: onSubmit });
h('form', { onSubmit: onSubmit });

0 comments on commit 0df2dbf

Please sign in to comment.