diff --git a/src/jsx.d.ts b/src/jsx.d.ts index a8af87ae6a6..8f2b98cc925 100644 --- a/src/jsx.d.ts +++ b/src/jsx.d.ts @@ -1441,6 +1441,10 @@ export namespace JSXInternal { Target, FocusEvent >; + export type TargetedInputEvent = TargetedEvent< + Target, + InputEvent + >; export type TargetedKeyboardEvent = TargetedEvent< Target, KeyboardEvent @@ -1495,6 +1499,9 @@ export namespace JSXInternal { export type GenericEventHandler = EventHandler< TargetedEvent >; + export type InputEventHandler = EventHandler< + TargetedInputEvent + >; export type KeyboardEventHandler = EventHandler< TargetedKeyboardEvent >; @@ -1504,6 +1511,9 @@ export namespace JSXInternal { export type PointerEventHandler = EventHandler< TargetedPointerEvent >; + export type SubmitEventHandler = EventHandler< + TargetedSubmitEvent + >; export type TouchEventHandler = EventHandler< TargetedTouchEvent >; @@ -1563,14 +1573,14 @@ export namespace JSXInternal { // Form Events onChange?: GenericEventHandler | undefined; onChangeCapture?: GenericEventHandler | undefined; - onInput?: GenericEventHandler | undefined; - onInputCapture?: GenericEventHandler | undefined; - onBeforeInput?: GenericEventHandler | undefined; - onBeforeInputCapture?: GenericEventHandler | undefined; + onInput?: InputEventHandler | undefined; + onInputCapture?: InputEventHandler | undefined; + onBeforeInput?: InputEventHandler | undefined; + onBeforeInputCapture?: InputEventHandler | undefined; onSearch?: GenericEventHandler | undefined; onSearchCapture?: GenericEventHandler | undefined; - onSubmit?: TargetedSubmitEvent | undefined; - onSubmitCapture?: TargetedSubmitEvent | undefined; + onSubmit?: SubmitEventHandler | undefined; + onSubmitCapture?: SubmitEventHandler | undefined; onInvalid?: GenericEventHandler | undefined; onInvalidCapture?: GenericEventHandler | undefined; onReset?: GenericEventHandler | undefined; diff --git a/test/ts/preact.tsx b/test/ts/preact.tsx index 757cf3f6550..bbc905d5416 100644 --- a/test/ts/preact.tsx +++ b/test/ts/preact.tsx @@ -362,7 +362,19 @@ createElement(RefComponentTest, { ref: functionRef }, 'hi'); h(RefComponentTest, { ref: functionRef }, 'hi'); // Should accept onInput -const onInput = (e: h.JSX.TargetedEvent) => {}; +const onInput = (e: h.JSX.TargetedInputEvent) => {}; ; + e.currentTarget.value} />; createElement('input', { onInput: onInput }); h('input', { onInput: onInput }); + +// Should accept onBeforeInput +const onBeforeInput = (e: h.JSX.TargetedInputEvent) => {}; + e.currentTarget.value} />; +createElement('input', { onBeforeInput: onBeforeInput }); +h('input', { onBeforeInput: onBeforeInput }); + +const onSubmit = (e: h.JSX.TargetedSubmitEvent) => {}; +
e.currentTarget.elements} />; +createElement('form', { onSubmit: onSubmit }); +h('form', { onSubmit: onSubmit });