Skip to content

Instantly share code, notes, and snippets.

@sgregson
Last active November 8, 2019 23:00
Show Gist options
  • Save sgregson/0a92f7896b399652d942c0766db5ee5b to your computer and use it in GitHub Desktop.
Save sgregson/0a92f7896b399652d942c0766db5ee5b to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'Radio Group',
initial: 'unfocused',
context: {
//
insideToolbar: false,
checkedIndex: -1
},
states: {
unfocused: {
on: {
TAB: 'focused'
}
},
focused: {
on: {
KEYDOWN: [
{
target: "unfocused",
cond: "tab"
},
{
target: "unfocused",
cond: "shiftTab"
},
{
target: "focused",
cond: "rightOrDown"
},
{
target: "focused",
cond: "leftOrUp"
}
],
}
},
success: {
type: 'final'
},
failure: {
on: {
RETRY: {
target: 'unfocused',
actions: assign({
retries: (context, event) => context.retries + 1
})
}
}
}
}
},{
guards: {
tab: (c,e) => {
// tab key, no shift
if(e.which == 9 && !e.shiftKey) {
// no other modifiers
return !(e.altKey || e.ctrlKey || e.metaKey)
}
return false
},
shiftTab: (c,e) => {
// tab key w/ shift
if(e.which == 9 && e.shiftKey) {
// no other modifiers
return !(e.altKey || e.ctrlKey || e.metaKey)
}
return false
},
rightOrDown: () => {
return true
},
leftOrUp: () => {
return true
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment