Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: Incorrect onToggle event type #4615

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion src/jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@
Target,
TouchEvent
>;
export type TargetedToggleEvent<Target extends EventTarget> = TargetedEvent<
Target,
ToggleEvent

Check failure on line 513 in src/jsx.d.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build & Test

Cannot find name 'ToggleEvent'.
>;
export type TargetedTransitionEvent<Target extends EventTarget> =
TargetedEvent<Target, TransitionEvent>;
export type TargetedUIEvent<Target extends EventTarget> = TargetedEvent<
Expand Down Expand Up @@ -536,6 +540,9 @@
export type DragEventHandler<Target extends EventTarget> = EventHandler<
TargetedDragEvent<Target>
>;
export type ToggleEventHandler<Target extends EventTarget> = EventHandler<
TargetedToggleEvent<Target>

Check failure on line 544 in src/jsx.d.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build & Test

Type 'TargetedToggleEvent<Target>' does not satisfy the constraint 'TargetedEvent<EventTarget, Event>'.
>;
export type FocusEventHandler<Target extends EventTarget> = EventHandler<
TargetedFocusEvent<Target>
>;
Expand Down Expand Up @@ -597,7 +604,7 @@
onCompositionUpdateCapture?: CompositionEventHandler<Target> | undefined;

// Details Events
onToggle?: GenericEventHandler<Target> | undefined;
onToggle?: ToggleEventHandler<Target> | undefined;

// Dialog Events
onClose?: GenericEventHandler<Target> | undefined;
Expand Down
12 changes: 10 additions & 2 deletions test/ts/preact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ const acceptsStringAsLength = <div style={{ marginTop: '20px' }} />;

const ReturnNull: FunctionalComponent = () => null;

// Should accept arbitrary properties outside of JSX.HTMLAttributes
h('option', { x: 'foo' });
createElement('option', { value: 'foo' });

// Refs should work on elements
const ref = createRef<HTMLDivElement>();
createElement('div', { ref: ref }, 'hi');
Expand All @@ -375,13 +379,17 @@ const onBeforeInput = (e: h.JSX.TargetedInputEvent<HTMLInputElement>) => {};
createElement('input', { onBeforeInput: onBeforeInput });
h('input', { onBeforeInput: onBeforeInput });

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

h('option', { value: 'foo' });
createElement('option', { value: 'foo' });
Comment on lines -383 to -384
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the diff, placed this rather wonkily a few weeks ago. Moved it out so it wasn't sat in the middle of the event tests.

// Should accept onToggle
const onToggle = (e: h.JSX.TargetedToggleEvent<HTMLDetailsElement>) => {};
<dialog onToggle={(e) => ({ newState: e.newState, oldState: e.oldState }) } />;
createElement('dialog', { onToggle: onToggle });
h('dialog', { onToggle: onToggle });

// Should default to correct event target element for the attribute interface
h<JSX.InputHTMLAttributes>('input', { onClick: e => e.currentTarget.capture });
Expand Down
Loading