Skip to content

Instantly share code, notes, and snippets.

@segunadebayo
Created May 25, 2021 11:53
Show Gist options
  • Save segunadebayo/d00922675f3562f0d145367fa94b5080 to your computer and use it in GitHub Desktop.
Save segunadebayo/d00922675f3562f0d145367fa94b5080 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const menuMachine = Machine(
{
id: "menu-machine",
initial: "idle",
context: {
activeDescendantId: null,
menuId: "",
buttonId: "",
onSelect: () => {}
},
states: {
idle: {
on: {
BUTTON_CLICK: {
target: "open",
actions: "focusFirstItem"
},
BUTTON_FOCUS: "close"
}
},
close: {
entry: ["resetId", "focusButton"],
on: {
BUTTON_CLICK: {
target: "open",
actions: "focusFirstItem"
},
BUTTON_BLUR: "idle",
ARROW_DOWN: {
target: "open",
actions: "focusFirstItem"
},
ARROW_UP: {
target: "open",
actions: "focusLastItem"
}
}
},
open: {
entry: "focusMenu",
on: {
BUTTON_CLICK: "close",
ARROW_UP: {
actions: "focusPrevItem"
},
ARROW_DOWN: {
actions: "focusNextItem"
},
BLUR: "close",
ENTER: {
target: "close",
actions: "selectCurrentItem"
},
ESCAPE: "close",
ITEM_POINTEROVER: {
actions: "focusItem"
},
ITEM_POINTERLEAVE: {
actions: "resetId"
},
ITEM_CLICK: {
target: "close",
actions: "selectCurrentItem"
}
}
}
}
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment