Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incorrect oninput event type #4226

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,10 @@ export namespace JSXInternal {
Target,
FocusEvent
>;
export type TargetedInputEvent<Target extends EventTarget> = TargetedEvent<
Target,
InputEvent
>;
export type TargetedKeyboardEvent<Target extends EventTarget> = TargetedEvent<
Target,
KeyboardEvent
Expand Down Expand Up @@ -1495,6 +1499,9 @@ export namespace JSXInternal {
export type GenericEventHandler<Target extends EventTarget> = EventHandler<
TargetedEvent<Target>
>;
export type InputEventHandler<Target extends EventTarget> = EventHandler<
TargetedInputEvent<Target>
>;
export type KeyboardEventHandler<Target extends EventTarget> = EventHandler<
TargetedKeyboardEvent<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;
onBeforeInput?: GenericEventHandler<Target> | undefined;
onBeforeInputCapture?: GenericEventHandler<Target> | undefined;
onInput?: InputEventHandler<Target> | undefined;
onInputCapture?: InputEventHandler<Target> | undefined;
onBeforeInput?: InputEventHandler<Target> | undefined;
onBeforeInputCapture?: InputEventHandler<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
14 changes: 13 additions & 1 deletion test/ts/preact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,19 @@ 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 onBeforeInput
const onBeforeInput = (e: h.JSX.TargetedInputEvent<HTMLInputElement>) => {};
<input onBeforeInput={e => e.currentTarget.value} />;
createElement('input', { onBeforeInput: onBeforeInput });
h('input', { onBeforeInput: onBeforeInput });

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