Skip to content

Instantly share code, notes, and snippets.

@garrettlancaster
Created June 23, 2021 17:02
Show Gist options
  • Select an option

  • Save garrettlancaster/c82fecdea83c4f744123e65b9686df8e to your computer and use it in GitHub Desktop.

Select an option

Save garrettlancaster/c82fecdea83c4f744123e65b9686df8e to your computer and use it in GitHub Desktop.

Revisions

  1. garrettlancaster revised this gist Jun 23, 2021. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion machine.js
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,6 @@ const machine = Machine({
    },
    guards: {
    isChar: (_, {keydown}) => {
    if (!keydown) { return }
    return keydown.key.length === 1;
    }
    }
  2. garrettlancaster created this gist Jun 23, 2021.
    32 changes: 32 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    const machine = Machine({
    initial: 'Closed',
    states: {
    Closed: {
    on: {
    keydown: {
    cond: 'isChar',
    target: 'Open',
    actions: 'focus'
    }
    }
    },
    Open: {
    on: {
    closed: 'Closed'
    }
    }
    }
    }, {
    actions: {
    focus: (_, {select}) => {
    console.log('focus', select)
    Select2.focusSearch(select)
    }
    },
    guards: {
    isChar: (_, {keydown}) => {
    if (!keydown) { return }
    return keydown.key.length === 1;
    }
    }
    })