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

feat: Add onBeforeToggle event handler type #4694

Merged
merged 1 commit into from
Feb 19, 2025

Conversation

lukewarlow
Copy link
Contributor

@lukewarlow lukewarlow commented Feb 18, 2025

This is slightly complicated, basically Details has had an ontoggle for a long time but historically it was just an Event. More recently Popovers were added and they had a beforetoggle and a toggle event but used a new ToggleEvent type. Details was subsequently updated to use this type for it's toggle event too (but it doesn't have a beforetoggle event itself).

Dialogs also more recently have had a toggle and beforetoggle event added to them.

@@ -625,7 +625,8 @@ export namespace JSXInternal {
onCompositionUpdate?: CompositionEventHandler<Target> | undefined;
onCompositionUpdateCapture?: CompositionEventHandler<Target> | undefined;

// Details Events
// Popover Events
onBeforeToggle?: ToggleEventHandler<Target> | undefined;
onToggle?: ToggleEventHandler<Target> | undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

DetailsHTMLAttributes has an onToggle defined too, but as a GenericEventHandler idk if that should be removed or if it is in addition to this type (can't really remember how TS works).

Copy link
Member

Choose a reason for hiding this comment

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

That'd be a mistake -- IIRC, the DetailsHTMLAttributes interface was created prior, then moved into this module. Later we added this entry with a backport of the correct event handler type. I think the DetailsHTML interface will take precedence too so that should probably be removed in favor of this "global" type, but that can be done separately later.

I think in the future we'll try to break up this mega list of events too, try to restrict them (where appropriate) to specific elements.

@coveralls
Copy link

coveralls commented Feb 18, 2025

Coverage Status

coverage: 99.609%. remained the same
when pulling c33c424 on lukewarlow:onbeforetoggle-types
into 66fa1b5 on preactjs:main.

@preactjs preactjs deleted a comment from github-actions bot Feb 19, 2025
Copy link
Member

@rschristian rschristian left a comment

Choose a reason for hiding this comment

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

Cheers

@rschristian rschristian merged commit 8941185 into preactjs:main Feb 19, 2025
5 checks passed
@lukewarlow lukewarlow deleted the onbeforetoggle-types branch February 19, 2025 09:02
@JoviDeCroock JoviDeCroock mentioned this pull request Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants