Skip to content

This component is developed with StencilJS and provides a first-class option for rendering children in a DOM node that exists outside the DOM hierarchy of the parent or reference component.

Notifications You must be signed in to change notification settings

tomas-teston/stencil-portal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stencil Portal

This component is developed with StencilJS and provides a first-class option for rendering children in a DOM node that exists outside the DOM hierarchy of the parent or reference component.

A typical use case for portals is when a main component has an overflow style: hidden or z-index, but needs the element to "come out" visually from its container. For example, dialog boxes, hovercards and tooltips.

How does it work?

The component portal component requires us to pass a component reference from which it will calculate the position (see in the example the component tooltip component has a reference on the Host tab)

<Host ref={(el) => (this.tooltipRef = el)}>

In this same component we can see that there is a label <Slot />. This is used for the example, and is the place where the parent's child component will be drawn (in this case a where it will be possible to hover and show the content that is in the portal)

Example tooltip hover

When the cursor is placed over the element, the portal is positioned absolutely on top of the referenced element by default

How to run the example

  1. Install nodejs 14.5.0 from this link or using Node Version Manager.
  2. Install yarn 1.22.5 globally executing the following command:
npm install -g [email protected]
  1. Install all project dependencies from SPA root folder:
yarn
  1. Start the project in local development mode with:
yarn start

About

This component is developed with StencilJS and provides a first-class option for rendering children in a DOM node that exists outside the DOM hierarchy of the parent or reference component.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published