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.
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
Navn | Beskrivelse |
---|---|
(standard) | The popup's content. |
anchor | The 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
Navn | Arvet fra | Beskrivelse |
---|---|---|
sl-reposition | SlPopup | Emitted when the popup is repositioned. This event can fire a lot, so avoid putting expensive operations in your listener or consider debouncing it. |
Egenskaper
Navn | Type | Arvet fra | Beskrivelse | Reflected |
---|---|---|---|---|
popup | HTMLElement | SlPopup | A reference to the internal popup container. Useful for animating and styling the popup with JavaScript. | |
anchor | Element | string | VirtualElement | SlPopup | The 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. | |
active | boolean = false | SlPopup | Activates 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' | SlPopup | The 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' | SlPopup | Determines 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. | |
distance | number = 0 | SlPopup | The distance in pixels from which to offset the panel away from its anchor. | |
skidding | number = 0 | SlPopup | The distance in pixels from which to offset the panel along its anchor. | |
arrow | boolean = false | SlPopup | Attaches 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' | SlPopup | The 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. | |
arrowPadding | number = 10 | SlPopup | The 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. | |
flip | boolean = false | SlPopup | When 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. | |
flipFallbackPlacements | string = '' | SlPopup | If 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' | SlPopup | When 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. | |
flipBoundary | Element | Element[] | SlPopup | The 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. | |
flipPadding | number = 0 | SlPopup | The amount of padding, in pixels, to exceed before the flip behavior will occur. | |
shift | boolean = false | SlPopup | Moves the popup along the axis to keep it in view when clipped. | |
shiftBoundary | Element | Element[] | SlPopup | The 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. | |
shiftPadding | number = 0 | SlPopup | The amount of padding, in pixels, to exceed before the shift behavior will occur. | |
autoSize | 'horizontal' | 'vertical' | 'both' | SlPopup | When set, this will cause the popup to automatically resize itself to prevent it from overflowing. | |
sync | 'width' | 'height' | 'both' | SlPopup | Syncs the popup's width or height to that of the anchor element. | |
autoSizeBoundary | Element | Element[] | SlPopup | The 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. | |
autoSizePadding | number = 0 | SlPopup | The amount of padding, in pixels, to exceed before the auto-size behavior will occur. | |
hoverBridge | boolean = false | SlPopup | When 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
Navn | Parametre | Returtype | Arvet fra | Beskrivelse |
---|---|---|---|---|
reposition | SlPopup | Forces the popup to recalculate and reposition itself. |
Deler
Navn | Beskrivelse |
---|---|
arrow | The 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. |
popup | The popup's container. Useful for setting a background color, box shadow, etc. |
hover-bridge | The hover bridge element. Only available when the `hover-bridge` option is enabled. |
Spesifikke CSS-variabler for komponent
Navn | Beskrivelse |
---|---|
--arrow-size | The size of the arrow. Note that an arrow won't be shown unless the `arrow` attribute is used. |
--arrow-color | The color of the arrow. |
--auto-size-available-width | A 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-height | A 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`. |