Skip to content

Instantly share code, notes, and snippets.

@rayou
Created October 20, 2020 04:42
Show Gist options
  • Select an option

  • Save rayou/a90d77dcf3425391d59998b0faa68043 to your computer and use it in GitHub Desktop.

Select an option

Save rayou/a90d77dcf3425391d59998b0faa68043 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const dropdownMachine = Machine({
id: "dropdown",
initial: "idle",
context: {
items: [],
query: "",
},
on: {
UPDATE_ITEMS: {
actions: "updateItems",
},
},
states: {
idle: {
on: {
FOCUS: {
target: "focus",
actions: [
"selectText",
"updateContainerHeight",
"scrollToSelectedItem",
],
},
},
},
focus: {
initial: "focused",
on: {
EDITING: {
target: ".editing",
actions: "assignQuery",
},
BLUR: "idle",
},
states: {
focused: {},
editing: {},
},
},
},
},
{
actions: {
updateItems: assign((ctx, evt) => ({
items: evt.type === "UPDATE_ITEMS" ? evt.items : ctx.items,
})),
assignQuery: assign((ctx, evt) => ({
query: evt.type === "EDITING" ? evt.query : ctx.query,
})),
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment