sterling-svelte  2.0.18
A modern, accessible, lightweight UI component library for Svelte.

Popover 2

An element that floats above other content.

Code
<script lang="ts">
  import { Popover2 } from '@geoffcox/sterling-svelte';

  let anchor = $state<HTMLDivElement>();
</script>

<div bind:this={anchor}>(anchor div)</div>

<Button popovertarget="ExamplePopover">Toggle</Button>

<Popover2 id="ExamplePopover" {anchor} anchorOrigin="top-left" lightDismiss="false" offsetX="0" offsetY="0" placement="auto">
 sterling-svelte
</Popover2>

Members

Property NameTypeBindableDefaultComment
allowFlipPopover2FlipAxis | undefinednoundefinedWhich axis/axes allow the popover to flip to the other side when there is not enough space.
anchorHTMLElement | null | undefinednoundefinedThe element the popover uses to position itself.
anchorOriginPopover2Nonant | undefinedno'auto'The point in a 3x3 grid on the anchor that should be used as the origin.
invokerHTMLElement | null | undefinednoundefinedThe element that controls opening/closing the popover. If the anchor is not specified, the invoker is used as the anchor.
lightDismissboolean | null | undefinednotrueWhen true, this popover closes when another element is clicked or focused. Also closes when another popover opens.
offsetXnumberno0The how many pixels to move the popover left (negative) or right (positive).
offsetYnumberno0The how many pixels to move the popover up (negative) or down (positive).
openboolean | null | undefinedyesfalseWhen true, the popover is open and visible.
placement'auto'| Popover2Nonant | undefinedno'center'How the popover should be positioned relative to the anchor point. When 'auto', placement follows anchorOrigin.

Types

Type NameDefinitionComment
Popover2Nonant'top-left' | 'top' | 'top-right' | 'left' | 'center' | 'right' | 'bottom-left' | 'bottom' | 'bottom-right'A nonant is like quadrant but 3x3 rather than 2x2.
Popover2FlipAxis'none' | 'x' | 'y' | 'both'

Considerations

  • Uses the w3c standard Popover API to place the popover on the top layer.
  • This component manages CSS anchor-name and position-anchor properties to connect the specified anchor to the popover.
  • The position-try CSS for popovers does not currently work so this component implement position flipping.
  • Includes HTMLDivElement props, events, and methods.

Anatomy

<div 
  class="sterling-popover-2 light-dismiss has-anchor-ident"
  style="--anchor-ident:anchor-123 --offset-x:calc(0% + 15px); --offset-y:calc(0% + 0px);"
  data-placement="top-left"
  data-anchor-origin="top-left"
  popover="auto">
    <div class="content">
      {@render children?.()}
    </div>
</div>