Skip to main content

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

  • January 18, 2023
  • 3 replies
  • 538 views

polar_slon

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
  • Author
  • 3 replies
  • January 18, 2023

@Gleb, please take a look đź‘‹


tank666
  • 4858 replies
  • January 18, 2023

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


Gleb
  • Power Member
  • 4706 replies
  • January 18, 2023

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings