Created
May 25, 2021 11:53
-
-
Save segunadebayo/d00922675f3562f0d145367fa94b5080 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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