Skip to main content
rrhyne
December 14, 2021
Solved

Focus plugin window on open?

  • December 14, 2021
  • 11 replies
  • 1495 views

I’d like my plugin to be interacted with primarily via the keyboard.

The primary flow would be CMD+/, select plugin, down arrow to action in the plugin, return to run the action on the selected frame.

To do this, I need to set the user’s focus to the plugin window.

Is that possible?

This topic has been closed for replies.
Best answer by Gleb

Just call window.focus() in the UI code.

11 replies

Gleb
GlebAnswer
Power Member
December 15, 2021

Just call window.focus() in the UI code.

rrhyne
rrhyneAuthor
December 15, 2021

Worked beautifully. Dead simple, can’t believe I didn’t try it. Thanks!

RyanS
November 30, 2022

Apologies for asking in this solved thread. My question is kind of related to this.

I can’t manage to get the opposite work. Does window.blur() also work?

figma shortcuts doesn’t seem to work after an action made in the plugin. I added window.blur() inside an executed function (in UI code), but looks like the focus didn’t shift back to figma viewport. Any idea? Thanks

Gleb
Power Member
November 30, 2022

No, unfortunately the only way as far as I know it’s to click the canvas manually.

RyanS
November 30, 2022

That’s a shame. I guess I have to live with that for now. I hope figma will allow this someday.

I’ve seen your post here. I think that’s a great suggestion! but it’s been more than a year and no still change in Figma 😕

Stephane_Popout
March 8, 2024

Not sure it works everywhere but you can try this

@Gleb what do you think.

const focusFirstParentWithMoreThanOneFrame = () => {
  let parent = window.parent;
  while (parent.parent !== parent && parent.frames.length === 1) {
    parent = parent.parent;
  }
  parent.focus();
};
Gleb
Power Member
March 8, 2024

You don’t have access to outside frames with the Figma API sandbox limitations. Otherwise you would also be able to do a bunch of cool stuff like triggering shortcuts from a plugin.

Stephane_Popout
March 8, 2024

I tried it in dev mode and it worked. Should try in production mode now

You cannot access elements in the iframe but looks like you might be able to run the focus function ?

Thanks for your feedback 🙂

tank666
March 8, 2024
UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank
Gleb
Power Member
March 8, 2024

That’s very cool, see the reply above ↑

I didn’t know it was possible, sorry for the misleading comment!