Skip to content

refactor(ui): move block callbacks inside v-bind objects in examples into named methods - #427

Merged
JuroOravec merged 2 commits into
mainfrom
ui/named-vbind-handlers
Oct 27, 2026
Merged

JuroOravec merged 2 commits into
mainfrom
ui/named-vbind-handlers

Conversation

@JuroOravec

@JuroOravec JuroOravec commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #424 (#141). Some CContextMenu, CMenu and CSplitButton snippets pass callbacks inside v-bind="{ onOpenChange: (...) => { ... } }" objects rather than as :on* attributes. This PR moves the ten that had a block body into named methods in each snippet's js block. Single-expression callbacks stay inline.

Snippet Method
ccontext_menu/snippets/controlled_open.py claimOpenRequest
ccontext_menu/snippets/focus_and_keyboard.py changeReturnTarget
ccontext_menu/snippets/positioning_and_rtl.py recordAcceptedPoint, claimExternalOpen
ccontext_menu/snippets/touch_and_pen.py recordTouchRequest, refuseScrollCardRequest
cmenu/snippets/controlled_open.py applyOpenRequest
csplitbutton/snippets/controlled_menu.py applyOpenRequest
csplitbutton/snippets/layers_and_dialog.py applyLayerAction

Behaviour is unchanged. Each method keeps the callback's arguments, its this reads and writes, the order of its side effects, and its return value. The return value matters here: when CContextMenu's onOpenChange returns a literal true, the owner has claimed the opening. So every return true, return false, and bare return stays where it was.

Proof:

  • No e2e test loaded these snippets except a docs test that builds the whole site, so this PR adds eight new ones. They are in test_ccontext_menu_examples_e2e.py, test_cmenu_examples_e2e.py, and test_csplitbutton_examples_e2e.py.
  • They pass before and after the change.
  • Each of these edits makes them fail:
    • dropping a claim's return true;
    • dropping the external-open claim;
    • dropping a data write;
    • flipping the scroll card's return false.
  • The family non-e2e tests pass (95), as do the preview tests (37), and ruff is clean.
  • An independent reviewer found no behaviour change and no missed callback.

Found along the way, and explained: after a refused claim, the next right click on the same target didn't call onOpenChange until a left click. The cause is that the browser's own menu, which opens after a refused claim, selects the word under the pointer. CContextMenu then leaves a target with a selection to the browser's menu, as api.md documents. Headed Chromium does the same. This is the documented behaviour, not a bug, so the test now clears the selection explicitly and says why.

Single-line block-bodied handlers remain in the ccalendar, cdate_picker, and ctour snippets. They are outside #141's multiline scope.

🤖 Generated with Claude Code

JuroOravec and others added 2 commits October 25, 2026 17:45
…into named methods

Follow-up to #424 (#141). Some CContextMenu, CMenu and CSplitButton
snippets pass callbacks inside `v-bind="{ onOpenChange: (...) => { ... } }"`
objects rather than as `:on*` attributes. The ten that had a block body
now live in each snippet's `js` `methods` block under a name that says
what they do; single-expression callbacks stay inline.

The methods keep each callback's arguments, `this` reads and writes,
side-effect order, and return value. The return value matters here:
CContextMenu reads a literal `true` from onOpenChange as the owner
claiming the opening, so every `return true`, `return false` and bare
`return` stays where it was.

No e2e test loaded these snippets, so eight new ones do. They pass on
the old and new files, and dropping a claim's `return true` or a data
write makes them fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…m test

The browser's own menu, shown after a refused claim, selects the word
under the pointer, and CContextMenu leaves a target with a selection to
the browser's menu as api.md documents. The test now clears the
selection and says so, in place of a left click that only happened to
clear it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec merged commit 3a2e2ed into main Oct 27, 2026
17 of 28 checks passed
@JuroOravec
JuroOravec deleted the ui/named-vbind-handlers branch October 27, 2026 11:52
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.

1 participant