Skip to main content
polar_slon
January 18, 2023

Add some API that works as native "Go to main component" menu item

  • January 18, 2023
  • 3 replies
  • 634 views

Hi everyone.

I have a custom implementation and it does the thing.

function goToNode(pageId: string, nodeId: string) {
  if (!pageId || !pageName || !nodeId) {
    return;
  }

  const page = figma.getNodeById(pageId) as PageNode;
  if (!page) {
    // Some error handking.
  }

  const node = figma.getNodeById(nodeId) as SceneNode;
  if (node) {
    figma.currentPage = page;
    page.selection = [node];
    figma.viewport.scrollAndZoomIntoView([node]);
  }
}

But recently I’ve discovered that this implementation is useless in case of remote components. First of all it’s impossible to acquire the page since Figma API doesn’t expose full tree of remote componens (component is hanging in a vacuum with undefined parent property). Moreover figma.viewport.scrollAndZoomIntoView() call doesn’t work as expected. It scrolls to the middle of the nowhere on the current page in the current project.

Is there any workaround to make a navigation to a remote component (like native “Go to main component” menu item does)? I understand that Figma API has a lot of security consideration, but If i’m not mistaken navigation to some component in another library doesn’t imply any security riks.

3 replies

polar_slon
January 18, 2023

@Gleb, please take a look 👋

tank666
January 18, 2023

This is currently not possible. Without knowing the fileKey, you can’t even link to the remote component.

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
January 18, 2023

Please don’t ping me for every occasion, I do this for free