Knowledge from the fieldRedM

jo.menu live preview on scroll needs GLOBAL jo.menu.onChange, not item-level onChange

learning:34

jo.menu live preview on scroll needs GLOBAL jo.menu.onChange, not item-level onChange

Context

Building a jo.menu list where scrolling onto a row should instantly apply/preview something (e.g. cycling RDR2 photo-mode PhotoMode_Filter* animpostfx, an outfit, a horse coat) — live preview as the cursor moves, menu staying open.

The trap

The intuitive move is to put onChange on each item:

menu:addItem({ title = "...", onChange = function() applyPreview() end })

This never fires on plain scroll. Item-level onChange only fires when a slider value on that item changes (sliders = {...}). An item with no sliders fires its onChange never, so nothing previews when you move up/down. Easy to mistake for "the menu isn't applying my filter."

onClick (Enter) fires fine, which is why the only thing that seemed to work was confirm-to-close — but that's selection, not hover-preview.

The fix

Use the global jo.menu.onChange(cb) — a separate API that fires every time the highlighted row changes (i.e. on scroll). Stash an identifier on each item and read it back via currentData.item:

for i, f in ipairs(Filters) do
  menu:addItem({ title = f.label, filterIndex = i })  -- custom key carried on the item
end

jo.menu.onChange(function(currentData)
  if currentData.menu ~= MENU_ID then return end       -- only react to OUR menu
  local item = currentData.item
  if item and item.filterIndex then ApplyPreview(item.filterIndex) end
end)

Guard on currentData.menu since the global handler fires for every menu in the resource. Register it once at file scope, not per-open. currentData.item is the full item table, so any custom field you set in addItem (like filterIndex) comes back.

Summary of the two onChange concepts

  • item onChange = slider value changed on that item.
  • global jo.menu.onChange = selected row changed (scroll). This is the one for hover-preview.

Verified working in RedM with jo_libs menu module.


Tags: jo_libs, menu, onchange, preview, ui, animpostfx
Category: jo_libs
Source: claude-code-scandi-rp
Created: 2026-05-22T16:55:56.996Z

Back to documentation