Skip to content

fix(base): preserve the originating press in checkbox changes - #537

Merged
houko merged 6 commits into
mainfrom
fix/checkbox-press-event
Nov 18, 2026
Merged

houko merged 6 commits into
mainfrom
fix/checkbox-press-event

Conversation

@houko

@houko houko commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #398.

Add OnChangeEvent(checked bool, press core.PressEvent) to base.Checkbox and ui.Checkbox, so a list can implement Shift-press range selection without type-asserting the rendered view. When provided it replaces OnChange; existing value-only callbacks keep their behavior and the app retains control of the value. TSX receives { checked, press }, and generated declarations use the existing PressEvent type so modifiers are available to the type checker too.

Keep modifiers when a focused desktop or web pressable is activated with Space or Return, after shortcut handling. Windows delivers Space and Return held with Alt as system keys (WM_SYSKEYDOWN) that go to the window menu, so they never press a view there; headless input follows the same rules, including the platform-specific Mod mapping and the Windows Alt exception. A press on a visible label (LabelFor, from main) forwards its modifiers to the checkbox. Checkbox pointer/keyboard regressions run in the Linux, Windows, macOS and Chromium input jobs. Physical-keyboard activation on mobile remains an explicit roadmap gap; pointer-event metadata is shared by every target.

Targets

  • Shared code (base, ui, core, tsx, nsgotest)
  • macOS
  • Windows
  • Linux
  • Web

Screenshots

None: default appearance is unchanged.

Verification

Rebased onto main fd6adf5c. Main's workflow now runs the whole internal/testhost/testdata/press package on the macOS, Windows, Linux (xvfb), Chromium and Android emulator jobs, so this PR no longer edits .github/workflows/test.yml: TestCheckboxPressModifiersReachTheApp runs on every desktop and the web there and skips on Android, where physical-keyboard activation is the roadmap gap. ui.Checkbox forwards Ref, LabelledBy, Invalid and OnChangeEvent. The public checkbox docs (English and Chinese) and nsgotest.App.Key now state the Windows Alt exception.

  • go build ./... and go tool nsgo check -target all (Linux host): every desktop, Android and web target vets; go tool nsgo check -target ios and GOOS=darwin/ios vets of internal/platform/macos and internal/platform/ios pass on macOS.
  • go tool nsgo test ./base: 447 passed, 0 failed, 2 skipped; checkbox tests: 5 passed, covering press metadata, mixed, disabled and controlled values, callback precedence, shortcut priority, macOS/Windows/Linux Mod mapping, Alt on each desktop and the web, and a Shift-press through a visible label.
  • Mutation check: letting Alt-held Space/Return press the view in the headless Windows environment fails TestCheckboxAltActivationOnWindowsIsTheSystemsKey/windows; replacing the originating press with an empty event fails TestCheckboxChangeEventKeepsThePress.
  • go tool nsgo test ./tsx/ui (7 passed), ./tsx (179 passed), ./nsgotest (77 passed, 1 skipped), ./core (694 passed), ./ui (184 passed), headless ./internal/testhost/testdata/press (7 passed, 1 macOS-only skip), -run 'Layer|Skills|Doc' . (35 passed).
  • Native macOS, Windows, Linux (xvfb) and Chromium press fixtures run in this PR's CI jobs.

Checklist

  • Conventional Commit title.
  • Architecture, English/Chinese public docs and app-author skill guidance updated.
  • No new dependencies or third-party code.

@github-actions github-actions Bot added size/M bug Something isn't working documentation Improvements or additions to documentation macOS iOS Windows Linux Web core base ui tsx ci conflict Conflicts with the base branch; resolve it first labels Nov 17, 2026
@houko
houko force-pushed the fix/checkbox-press-event branch from f8ba8dd to f07d5f7 Compare November 17, 2026 10:45
@github-actions github-actions Bot added conflict Conflicts with the base branch; resolve it first and removed conflict Conflicts with the base branch; resolve it first labels Nov 17, 2026
@houko
houko force-pushed the fix/checkbox-press-event branch from f07d5f7 to 8c30597 Compare November 17, 2026 16:47
@github-actions github-actions Bot removed the conflict Conflicts with the base branch; resolve it first label Nov 17, 2026
@houko
houko force-pushed the fix/checkbox-press-event branch from 8c30597 to e8c6977 Compare November 17, 2026 17:28
@houko

houko commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Reviewed. Checked the full diff against main and issue #398's acceptance: OnChangeEvent on base.Checkbox and ui.Checkbox hands the app the originating core.PressEvent without type-asserting the rendered view, OnChange is unchanged when OnChangeEvent is unset, and TSX declares { checked, press: PressEvent }. The native keyboard paths (macOS keyDown:, Windows WM_KEYDOWN controlKey, Linux controlKey, web keydown) all run after the keymap/shortcut handling, and Windows never routes WM_SYSKEYDOWN to controlKey, which matches the headless Alt rule. CHANGELOG.md is untouched, no hard-wrapped lines or attribution were added.

Verification, after rebasing onto main 065ea1b (an unrelated ui/chat change, no conflicts):

  • go build ./... plus GOOS=windows (amd64, arm64), linux and android builds pass; go tool nsgo check -target all vets macos, windows, linux, android_arm64 and web.
  • Headless: ./base 446 passed (2 skipped), ./nsgotest 75 passed, ./tsx 172 passed, ./tsx/ui 6 passed, press fixture passed.
  • Mutation checks: passing an empty PressEvent from base.Checkbox fails 4 of the 5 checkbox tests; dropping modifiers in nsgotest's keyboard activation fails 3 of them.
  • Real Linux (Ubuntu 24.04, GNOME 46, X11 session): TestCheckboxPressModifiersReachTheApp, TestPressModifiersReachTheApp and TestVisibleLabelsFocusAndActivateTheirControls pass through real pointer and keyboard input. With the Linux backend's key modifiers removed, the checkbox fixture fails on Shift+Space as expected.
  • CI on the pre-rebase head (same diff): the checkbox press fixture passed on native Windows, native macOS, Linux under xvfb and Chromium.
  • iOS is a comment-only change; mobile physical-keyboard activation stays a roadmap gap, so no iPhone check was needed.

Minor, not blocking: the headless tvOS environment now passes Shift and other modifiers on Space/Return, while the device's select press carries none; the roadmap entry already covers mobile keyboard modifiers.

@houko
houko marked this pull request as ready for review November 17, 2026 17:28
@github-actions github-actions Bot added the conflict Conflicts with the base branch; resolve it first label Nov 17, 2026
@houko
houko force-pushed the fix/checkbox-press-event branch from e8c6977 to 3aa33c1 Compare November 17, 2026 23:08
@github-actions github-actions Bot removed the conflict Conflicts with the base branch; resolve it first label Nov 17, 2026
Windows delivers Space and Return held with Alt as WM_SYSKEYDOWN, which the backend leaves to DefWindowProc and the window menu, so a real Windows app never presses the focused view with them. The headless Windows environment now does the same instead of reporting an Alt-modified keyboard press.
A Shift-press on a visible label reaches OnChangeEvent with its modifiers at the checkbox origin, and Alt with Space or Return presses the focused checkbox on macOS, Linux and the web but not on Windows.
@houko
houko force-pushed the fix/checkbox-press-event branch from 3aa33c1 to a22177d Compare November 17, 2026 23:46
@houko

houko commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

Reviewed. Head a22177d on main fd6adf5; its six commits are patch-identical to the previous head 3aa33c1 (range-diff), only rebased.

Code and docs: read the full diff against main and issue #398's acceptance. OnChangeEvent on base.Checkbox and ui.Checkbox gets the originating core.PressEvent, replaces OnChange when set, and leaves the value with the app; TSX gets { checked, press } typed as PressEvent. Keyboard activation keeps modifiers on macOS (focus.go, after the keymap), Linux and Windows (controlKey runs after the shortcut lookup; Windows only reaches it from WM_KEYDOWN, so Alt-held Space/Return stay with the window menu), the web (keyDown) and headless nsgotest.App.Key. The docs (en/zh), roadmap gap and skill reference match the behaviour. CHANGELOG.md untouched, no hard-wrapped lines, no unrelated changes.

Mutation checks: passing an empty PressEvent from base.Checkbox and dropping the modifiers from nsgotest.App.Key fails four of the five base checkbox tests and the press fixture; removing the modifiers from the macOS focus press makes TestCheckboxPressModifiersReachTheApp fail on a real macOS target (Modifiers all false, want Shift).

Verification on this head:

  • Linux host: go build ./...; vets for windows/amd64, linux, js/wasm and an android/arm64 build of the touched packages pass.
  • go tool nsgo test: ./base 447 passed (2 skipped), ./ui 184, ./nsgotest 78 (1 skipped), ./tsx 179, ./tsx/ui 7, headless ./internal/testhost/testdata/press 9 passed (1 skipped).
  • Real macOS (-target macos): TestCheckboxPressModifiersReachTheApp passes.
  • Chromium (-target web): the whole press package passes, 9 passed, 1 skipped. I ran this one myself because CI skipped the browser steps after the unrelated failure below.
  • CI on this head: the native press fixture passes on Windows, Linux (xvfb) and macOS, and skips on the Android emulator as intended; Apple build and vet, apple-simulator and build and vet pass.

The only red CI job, test, fails in TestWebCanvasScrollZoom/pixels (TestNestedZoomedCanvasIsSharp, gray pixels at zoom 1 and 3). It fails the same way on main fd6adf5 and is not touched by this PR.

Not device-checked: physical-keyboard activation on iOS and Android, which this PR leaves as the documented roadmap gap (iOS changes only a comment).

@houko

houko commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

Reviewed. The only CI failures are unrelated to this change: TestNestedZoomedCanvasIsSharp, fixed on main by #631, and the hosted runner's slow simulator boot, addressed by #634.

@houko
houko merged commit 6d7f4e8 into main Nov 18, 2026
21 of 22 checks passed
@houko
houko deleted the fix/checkbox-press-event branch November 18, 2026 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

base.Checkbox drops the press, so OnChange cannot see Shift or other modifiers

1 participant