Skip to content
This repository was archived by the owner on Jan 28, 2026. It is now read-only.
Open
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
4 changes: 2 additions & 2 deletions Sources/TokamakCore/Views/Controls/Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public struct _Button<Label>: View where Label: View {
public let action: () -> ()

@State
public var isPressed = false
public var isPressed: (down: Bool, inside: Bool) = (false, false)
Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure about the public api here. It's a breaking change in theory, but AFAIK _Button should only be used internally.


let anyStyle: AnyButtonStyle
public var style: Any.Type { anyStyle.type }
Expand All @@ -112,7 +112,7 @@ public struct _Button<Label>: View where Label: View {
configuration: .init(
role: role,
label: .init(body: AnyView(label)),
isPressed: isPressed
isPressed: isPressed.down && isPressed.inside
)
)
}
Expand Down
8 changes: 6 additions & 2 deletions Sources/TokamakDOM/Views/Buttons/Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ extension _Button: DOMPrimitive {
@_spi(TokamakCore)
public var renderedBody: AnyView {
let listeners: [String: Listener] = [
"pointerdown": { _ in isPressed = true },
// Only fires on down *inside*. Set both to true.
"pointerdown": { _ in isPressed = (true, true) },
"pointerenter": { _ in isPressed.inside = true },
// "pointerup" does not fire when the pointer left. Set both to false.
"pointerleave": { _ in isPressed = (false, false) },
"pointerup": { _ in
isPressed = false
isPressed.down = false
action()
},
]
Expand Down