Skip to content

nve-popup

Popup er et verktøy som lar deg deklarativt forankre "popup"-beholdere til et annet element. Popup gir ingen stiler - bare posisjonering! Popup-vinduets foretrukne plassering, avstand og skrens (offset) kan konfigureres ved hjelp av attributter.

Arvet fra SlPopup.

Denne komponenten bygger på en Shoelace-komponent. Sjekk også dokumentasjonen i Shoelace for å få full oversikt over hvordan komponenten funker.

Feil / oppgaver / PR

Ingen som vi vet om. Hvis du finner noe muffens, registrer en feil under Issues i Github og merk den med nve-popup.

 

html
<div style="margin:32px">
  <nve-popup placement="top" active>
    <span slot="anchor" style="border: 1px dotted black; border-radius:4px; padding:4px; width:100px;">Ankare</span>
    <div style="border: 1px solid black; border-radius:4px; padding:4px; ">Innehåll i popup</div>
  </nve-popup>
</div>

Eksempler

Plassering

Bruk placement for å styre plassering.

html
<nve-popup placement="right" active>
  <span slot="anchor" style="border: 1px dotted black; border-radius:4px; padding:4px; width:100px;">Ankare</span>
  <div style="border: 1px solid black; border-radius:4px; padding:4px; ">Innehåll i popup</div>
</nve-popup>

Spor

NavnBeskrivelse
(standard)The popup's content.
anchorThe element the popup will be anchored to. If the anchor lives outside of the popup, you can use the `anchor` attribute or property instead.

Hendelser

NavnArvet fraBeskrivelse
sl-repositionSlPopupEmitted when the popup is repositioned. This event can fire a lot, so avoid putting expensive operations in your listener or consider debouncing it.

Egenskaper

NavnTypeArvet fraBeskrivelseReflected
popupHTMLElement SlPopupA reference to the internal popup container. Useful for animating and styling the popup with JavaScript.
anchorElement | string | VirtualElement SlPopupThe element the popup will be anchored to. If the anchor lives outside of the popup, you can provide the anchor element `id`, a DOM element reference, or a `VirtualElement`. If the anchor lives inside the popup, use the `anchor` slot instead.
activeboolean = falseSlPopupActivates the positioning logic and shows the popup. When this attribute is removed, the positioning logic is torn down and the popup will be hidden.
placement| 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'right' | 'right-start' | 'right-end' | 'left' | 'left-start' | 'left-end' = 'top'SlPopupThe preferred placement of the popup. Note that the actual placement will vary as configured to keep the panel inside of the viewport.
strategy'absolute' | 'fixed' = 'absolute'SlPopupDetermines how the popup is positioned. The `absolute` strategy works well in most cases, but if overflow is clipped, using a `fixed` position strategy can often workaround it.
distancenumber = 0SlPopupThe distance in pixels from which to offset the panel away from its anchor.
skiddingnumber = 0SlPopupThe distance in pixels from which to offset the panel along its anchor.
arrowboolean = falseSlPopupAttaches an arrow to the popup. The arrow's size and color can be customized using the `--arrow-size` and `--arrow-color` custom properties. For additional customizations, you can also target the arrow using `::part(arrow)` in your stylesheet.
arrowPlacement'start' | 'end' | 'center' | 'anchor' = 'anchor'SlPopupThe placement of the arrow. The default is `anchor`, which will align the arrow as close to the center of the anchor as possible, considering available space and `arrow-padding`. A value of `start`, `end`, or `center` will align the arrow to the start, end, or center of the popover instead.
arrowPaddingnumber = 10SlPopupThe amount of padding between the arrow and the edges of the popup. If the popup has a border-radius, for example, this will prevent it from overflowing the corners.
flipboolean = falseSlPopupWhen set, placement of the popup will flip to the opposite site to keep it in view. You can use `flipFallbackPlacements` to further configure how the fallback placement is determined.
flipFallbackPlacementsstring = ''SlPopupIf the preferred placement doesn't fit, popup will be tested in these fallback placements until one fits. Must be a string of any number of placements separated by a space, e.g. "top bottom left". If no placement fits, the flip fallback strategy will be used instead.
flipFallbackStrategy'best-fit' | 'initial' = 'best-fit'SlPopupWhen neither the preferred placement nor the fallback placements fit, this value will be used to determine whether the popup should be positioned using the best available fit based on available space or as it was initially preferred.
flipBoundaryElement | Element[] SlPopupThe flip boundary describes clipping element(s) that overflow will be checked relative to when flipping. By default, the boundary includes overflow ancestors that will cause the element to be clipped. If needed, you can change the boundary by passing a reference to one or more elements to this property.
flipPaddingnumber = 0SlPopupThe amount of padding, in pixels, to exceed before the flip behavior will occur.
shiftboolean = falseSlPopupMoves the popup along the axis to keep it in view when clipped.
shiftBoundaryElement | Element[] SlPopupThe shift boundary describes clipping element(s) that overflow will be checked relative to when shifting. By default, the boundary includes overflow ancestors that will cause the element to be clipped. If needed, you can change the boundary by passing a reference to one or more elements to this property.
shiftPaddingnumber = 0SlPopupThe amount of padding, in pixels, to exceed before the shift behavior will occur.
autoSize'horizontal' | 'vertical' | 'both' SlPopupWhen set, this will cause the popup to automatically resize itself to prevent it from overflowing.
sync'width' | 'height' | 'both' SlPopupSyncs the popup's width or height to that of the anchor element.
autoSizeBoundaryElement | Element[] SlPopupThe auto-size boundary describes clipping element(s) that overflow will be checked relative to when resizing. By default, the boundary includes overflow ancestors that will cause the element to be clipped. If needed, you can change the boundary by passing a reference to one or more elements to this property.
autoSizePaddingnumber = 0SlPopupThe amount of padding, in pixels, to exceed before the auto-size behavior will occur.
hoverBridgeboolean = falseSlPopupWhen a gap exists between the anchor and the popup element, this option will add a "hover bridge" that fills the gap using an invisible element. This makes listening for events such as `mouseenter` and `mouseleave` more sane because the pointer never technically leaves the element. The hover bridge will only be drawn when the popover is active.

Metoder

NavnParametreReturtypeArvet fraBeskrivelse
repositionSlPopupForces the popup to recalculate and reposition itself.

Deler

NavnBeskrivelse
arrowThe arrow's container. Avoid setting `top|bottom|left|right` properties, as these values are assigned dynamically as the popup moves. This is most useful for applying a background color to match the popup, and maybe a border or box shadow.
popupThe popup's container. Useful for setting a background color, box shadow, etc.
hover-bridgeThe hover bridge element. Only available when the `hover-bridge` option is enabled.

Spesifikke CSS-variabler for komponent

NavnBeskrivelse
--arrow-sizeThe size of the arrow. Note that an arrow won't be shown unless the `arrow` attribute is used.
--arrow-colorThe color of the arrow.
--auto-size-available-widthA read-only custom property that determines the amount of width the popup can be before overflowing. Useful for positioning child elements that need to overflow. This property is only available when using `auto-size`.
--auto-size-available-heightA read-only custom property that determines the amount of height the popup can be before overflowing. Useful for positioning child elements that need to overflow. This property is only available when using `auto-size`.