How to make input field autofocus?

My plugin has an input field.

What I’m trying to do: when the plugin UI is displayed (via slash command), the input field will be automatically focused.

What I’ve tried…

  • add “autofocus” attribute to the input tag (i.e. <input type="search" autofocus>)
  • set autoFocus: true, i.e. logseq.showMainUI({autoFocus: true)})
  • get the input field and add .focus()

…but none of this worked. Any idea how to achieve that autofocus behavior?

Figured it out myself. In case anyone has the same question: what worked for me was to put .focus() in a timeout, within main().

1 Like