본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Popover 문서

원문 보기 위키 갱신

Popover는 트리거 요소에 고정된 떠 있는 패널(floating panel)에 풍부한 콘텐츠를 보여 주는 컴포넌트예요. 툴팁보다 크고 자유로운 내용을 담을 수 있어서, 세부 정보나 간단한 폼을 트리거 근처에 표시할 때 유용해요.

출처: 문서

본문

아래 예시는 Popover.Root가 전체 상태를 관리하고, Popover.Trigger가 열고 닫으며, Popover.Content가 실제 콘텐츠를 보여 주는 기본 구조예요. Popover.Arrow로 트리거를 가리키는 화살표도 함께 배치할 수 있어요.

<script lang="ts">
  import { Popover, Separator, Toggle } from "bits-ui";
  import ImageSquare from "phosphor-svelte/lib/ImageSquare";
  import LinkSimpleHorizontalBreak from "phosphor-svelte/lib/LinkSimpleHorizontalBreak";
  let width = $state(1024);
  let height = $state(768);
</script>
<Popover.Root>
  <Popover.Trigger
    class="rounded-input bg-dark
	text-background shadow-mini hover:bg-dark/95 inline-flex h-10 select-none items-center justify-center whitespace-nowrap px-[21px] text-[15px] font-medium transition-all hover:cursor-pointer active:scale-[0.98]"
  >
    Resize
  </Popover.Trigger>
  <Popover.Portal>
    <Popover.Content
      class="border-dark-10 bg-background shadow-popover data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-(--bits-popover-content-transform-origin) z-30 w-full max-w-[328px] rounded-[12px] border p-4"
      sideOffset={8}
    >
      <div class="flex items-center">
        <div
          class="bg-muted mr-3 flex size-12 items-center justify-center rounded-full"
        >
          <ImageSquare class="size-6" />
        </div>
        <div class="flex flex-col">
          <h4 class="text-[17px] font-semibold leading-5 tracking-[-0.01em]">
            Resize image
          </h4>
          <p class="text-muted-foreground text-sm font-medium">
            Resize your photos easily
          </p>
        </div>
      </div>
      <Separator.Root class="bg-dark-10 -mx-4 mb-6 mt-[17px] block h-px" />
      <div class="flex items-center pb-2">
        <div class="mr-2 flex items-center">
          <div class="relative mr-2">
            <span class="sr-only">Width</span>
            <span
              aria-hidden="true"
              class="text-xxs text-muted-foreground absolute left-5 top-4"
              >W</span
            >
            <input
              type="number"
              class="h-input rounded-10px border-border-input bg-background text-foreground w-[119px] border pl-10 pr-2 text-base sm:text-sm"
              bind:value={width}
            />
          </div>
          <div class="relative">
            <span class="sr-only">Height</span>
            <span
              aria-hidden="true"
              class="text-xxs text-muted-foreground absolute left-5 top-4"
              >H</span
            >
            <input
              type="number"
              class="h-input rounded-10px border-border-input bg-background text-foreground w-[119px] border pl-10 pr-2 text-base sm:text-sm"
              bind:value={height}
            />
          </div>
        </div>
        <Toggle.Root
          aria-label="toggle constrain portions"
          class="bg-background hover:bg-muted data-[state=on]:bg-muted inline-flex size-10 items-center justify-center rounded-[9px] transition-all active:scale-[0.98]"
        >
          <LinkSimpleHorizontalBreak class="size-6" />
        </Toggle.Root>
      </div>
    </Popover.Content>
  </Popover.Portal>
</Popover.Root>

구조 (Structure)

<script lang="ts">
  import { Popover } from "bits-ui";
</script>
<Popover.Root>
  <Popover.Trigger />
  <Popover.Portal>
    <Popover.Overlay />
    <Popover.Content>
      <Popover.Close />
      <Popover.Arrow />
    </Popover.Content>
  </Popover.Portal>
</Popover.Root>

열림 상태 다루기 (Managing Open State)

이번 절에서는 컴포넌트의 open 상태를 어떻게 다루는지 설명할게요.

양방향 바인딩 (Two-Way Binding)

간단하고 자동으로 상태를 동기화하고 싶다면 bind:open을 사용해요.

<script lang="ts">
  import { Popover } from "bits-ui";
  let isOpen = $state(false);
</script>
<button onclick={() => (isOpen = true)}>Open Popover</button>
<Popover.Root bind:open={isOpen}>
  <!-- ... -->
</Popover.Root>

완전 제어 (Fully Controlled)

상태의 읽기와 쓰기를 모두 직접 제어하고 싶다면 Function Binding을 사용해요.

<script lang="ts">
  import { Popover } from "bits-ui";
  let myOpen = $state(false);
  function getOpen() {
    return myOpen;
  }
  function setOpen(newOpen: boolean) {
    myOpen = newOpen;
  }
</script>
<Popover.Root bind:open={getOpen, setOpen}>
  <!-- ... -->
</Popover.Root>

호버 시 열기 (Open on Hover)

Popover.Trigger 컴포넌트의 openOnHover prop을 true로 설정하면 트리거 위에 마우스를 올렸을 때 Popover가 열리게 할 수 있어요. 열리기 전 지연은 openDelay(기본값: 700ms), 닫히기 전 지연은 closeDelay(기본값: 300ms)로 조절할 수 있어요.

호버로 열렸다면, 사용자가 콘텐츠와 상호작용(내부 요소를 클릭하거나 포커스)하지 않는 한 마우스가 트리거와 콘텐츠를 모두 벗어나면 Popover는 자동으로 닫혀요. "그레이스 영역(grace area)" 폴리곤 덕분에 트리거와 콘텐츠 사이를 닫히지 않고 부드럽게 커서를 이동할 수 있어요.

코드 펼치기 (Expand Code)

<script lang="ts">
  import { Button, Popover, Separator } from "bits-ui";
  import MapPin from "phosphor-svelte/lib/MapPin";
  import Calendar from "phosphor-svelte/lib/Calendar";
</script>
<Popover.Root>
  <Popover.Trigger
    openOnHover
    openDelay={200}
    closeDelay={100}
    class="bg-muted hover:bg-muted/80 inline-flex items-center gap-2 rounded-full py-1.5 pl-1.5 pr-3 text-sm font-medium transition-colors"
  >
    <img
      src="https://github.com/huntabyte.png"
      alt=""
      class="size-6 rounded-full object-cover"
    />
    huntabyte
  </Popover.Trigger>
  <Popover.Portal>
    <Popover.Content
      class="border-dark-10 bg-background shadow-popover data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-(--bits-popover-content-transform-origin) z-30 w-full max-w-[300px] rounded-[12px] border p-4 focus-visible:outline-none"
      sideOffset={8}
    >
      <div class="flex items-start justify-between gap-3">
        <div class="flex items-start gap-3">
          <div
            class="bg-muted flex size-12 shrink-0 items-center justify-center rounded-full"
          >
            <img
              src="https://github.com/huntabyte.png"
              alt="Hunter Johnston"
              class="size-full rounded-full object-cover"
            />
          </div>
          <div class="flex flex-col gap-0.5">
            <span class="text-[15px] font-semibold leading-5"
              >Hunter Johnston</span
            >
            <span class="text-muted-foreground text-sm">@huntabyte</span>
          </div>
        </div>
        <Button.Root
          href="https://x.com/huntabyte"
          target="_blank"
          class="bg-dark text-background shrink-0 rounded-full px-3.5 py-1.5 text-sm font-medium transition-opacity hover:opacity-90"
        >
          Follow
        </Button.Root>
      </div>
      <p class="text-foreground/90 mt-3 text-sm leading-relaxed">
        Building Bits UI and other open source tools for the Svelte ecosystem.
      </p>
      <Separator.Root class="bg-dark-10 -mx-4 my-3 block h-px" />
      <div class="text-muted-foreground flex flex-wrap gap-x-4 gap-y-1 text-xs">
        <span class="inline-flex items-center gap-1">
          <MapPin class="size-3.5" />
          FL, USA
        </span>
        <span class="inline-flex items-center gap-1">
          <Calendar class="size-3.5" />
          Joined 2020
        </span>
      </div>
    </Popover.Content>
  </Popover.Portal>
</Popover.Root>
<Popover.Root>
  <Popover.Trigger openOnHover>@huntabyte</Popover.Trigger>
  <Popover.Content>
    <!-- profile card content -->
  </Popover.Content>
</Popover.Root>

동작 참고 사항 (Behavior Notes)

  • 호버 중 클릭: 호버로 Popover가 열린 상태에서 사용자가 트리거를 클릭하면 "클릭으로 열린" 모드로 전환되고, 이제부터는 escape 키나 바깥을 클릭해서만 닫혀요.
  • 콘텐츠 내부 상호작용: 콘텐츠 안의 상호작용 가능한 요소를 클릭하거나 포커스하면, 명시적으로 닫기 전까지 Popover를 열어 둔 상태로 유지해요.
  • 키보드: openOnHover는 키보드 포커스로는 열리지 않아요. 키보드 사용자는 여전히 Enter나 Space를 눌러 열 수 있어요.
  • 터치 기기: 탭으로 여는 동작과 충돌하지 않도록, 호버 기능에서는 터치 이벤트가 무시돼요.

포커스 관리 (Managing Focus)

포커스 트랩 (Focus Trap)

기본적으로 Popover가 열리면 포커스가 그 Popover 안에 갇히게 돼요. 이 동작을 끄려면 Popover.Content 컴포넌트에 trapFocus prop을 false로 설정하면 돼요.

<Popover.Content trapFocus={false}>
  <!-- ... -->
</Popover.Content>

열 때 포커스 (Open Focus)

기본적으로 Popover가 열리면 Popover.Content 안의 첫 번째 포커스 가능한 요소에 포커스가 이동해요. 키보드로 탐색하는 사용자가 Popover 안에서 상호작용할 수 있는 곳으로 이동하게 보장해 주죠.

이 동작은 Popover.Content 컴포넌트의 onOpenAutoFocus prop으로 바꿀 수 있어요. 이 prop으로 Popover 콘텐츠 안의 무언가를 포커스하도록 쓰는 걸 강력히 권장해요.

먼저 onOpenAutoFocus 콜백에 전달된 이벤트를 취소해 첫 번째 포커스 가능한 요소를 포커스하는 기본 동작을 막아야 해요. 그런 다음 원하는 무엇이든 포커스할 수 있어요.

<script lang="ts">
  import { Popover } from "bits-ui";
  let nameInput = $state<HTMLInputElement>();
</script>
<Popover.Root>
  <Popover.Trigger>Open Popover</Popover.Trigger>
  <Popover.Content
    onOpenAutoFocus={(e) => {
      e.preventDefault();
      nameInput?.focus();
    }}
  >
    <input type="text" bind:this={nameInput} />
  </Popover.Content>
</Popover.Root>

닫을 때 포커스 (Close Focus)

기본적으로 Popover가 닫히면 Popover의 트리거 요소에 포커스가 이동해요. 이 동작은 Popover.Content 컴포넌트의 onCloseAutoFocus prop으로 바꿀 수 있어요.

onCloseAutoFocus 콜백에 전달된 이벤트를 취소해 트리거 요소를 포커스하는 기본 동작을 막은 뒤, 원하는 무엇이든 포커스하면 돼요.

<script lang="ts">
  import { Popover } from "bits-ui";
  let nameInput = $state<HTMLInputElement>();
</script>
<input type="text" bind:this={nameInput} />
<Popover.Root>
  <Popover.Trigger>Open Popover</Popover.Trigger>
  <Popover.Content
    onCloseAutoFocus={(e) => {
      e.preventDefault();
      nameInput?.focus();
    }}
  >
    <!-- ... -->
  </Popover.Content>
</Popover.Root>

스크롤 잠금 (Scroll Lock)

기본적으로 Popover가 열려 있어도 사용자는 바디를 스크롤하고 Popover 바깥의 콘텐츠와 상호작용할 수 있어요. 바디 스크롤을 잠그고 Popover 바깥 콘텐츠와의 상호작용을 막고 싶다면 Popover.Content 컴포넌트에 preventScroll prop을 true로 설정하면 돼요.

<Popover.Content preventScroll={true}>
  <!-- ... -->
</Popover.Content>

Escape 키 누름 (Escape Keydown)

기본적으로 Popover가 열려 있을 때 Escape 키를 누르면 팝오버가 닫혀요. Bits UI는 이 동작을 바꿀 수 있는 몇 가지 방법을 제공해요.

escapeKeydownBehavior

Popover.Content 컴포넌트의 escapeKeydownBehavior prop을 'ignore'로 설정하면 Escape 키를 눌러도 팝오버가 닫히지 않게 할 수 있어요.

<Popover.Content escapeKeydownBehavior="ignore">
  <!-- ... -->
</Popover.Content>

onEscapeKeydown

Popover.Content 컴포넌트의 onEscapeKeydown 콜백에 전달된 이벤트를 취소해 기본 동작을 바꿀 수도 있어요.

<Popover.Content onEscapeKeydown={(e) => e.preventDefault()}>
  <!-- ... -->
</Popover.Content>

바깥 상호작용 (Interact Outside)

기본적으로 Popover가 열려 있을 때 콘텐츠 바깥에서 pointer down 이벤트가 발생하면 Popover가 닫혀요. Bits UI는 이 동작을 바꿀 수 있는 몇 가지 방법을 제공해요.

interactOutsideBehavior

Popover.Content 컴포넌트의 interactOutsideBehavior prop을 'ignore'로 설정하면 사용자가 콘텐츠 바깥과 상호작용해도 팝오버가 닫히지 않게 할 수 있어요.

<Popover.Content interactOutsideBehavior="ignore">
  <!-- ... -->
</Popover.Content>

onInteractOutside

Popover.Content 컴포넌트의 onInteractOutside 콜백에 전달된 이벤트를 취소해 기본 동작을 바꿀 수도 있어요.

<Popover.Content onInteractOutside={(e) => e.preventDefault()}>
  <!-- ... -->
</Popover.Content>

커스텀 앵커 (Custom Anchor)

기본적으로 Popover.Content는 Popover.Trigger 컴포넌트에 고정돼요. 이 고정 지점이 콘텐츠의 위치를 결정하죠.

대신 콘텐츠를 다른 요소에 고정하고 싶다면, Popover.Content 컴포넌트의 customAnchor prop에 셀렉터 string이나 HTMLElement를 전달하면 돼요.

<script lang="ts">
  import { Popover } from "bits-ui";
  let customAnchor = $state<HTMLElement>(null!);
</script>
<div bind:this={customAnchor}></div>
<Popover.Root>
  <Popover.Trigger />
  <Popover.Content {customAnchor}>
    <!-- ... -->
  </Popover.Content>
</Popover.Root>

Svelte 트랜지션 (Svelte Transitions)

더 많은 제어가 필요한 Svelte Transitions나 다른 애니메이션 라이브러리를 쓰려면, forceMount prop과 child snippet을 함께 사용해 Popover.Content 컴포넌트를 강제로 마운트할 수 있어요.

<script lang="ts">
  import { Popover } from "bits-ui";
  import { fly } from "svelte/transition";
</script>
<Popover.Content forceMount>
  {#snippet child({ wrapperProps, props, open })}
    {#if open}
      <div {...wrapperProps}>
        <div {...props} transition:fly>
          <!-- ... -->
        </div>
      </div>
    {/if}
  {/snippet}
</Popover.Content>

물론 이 구문이 가장 보기 좋은 건 아니에요. 이 방식을 쓸 계획이라면 이 로직을 처리하는 재사용 가능한 콘텐츠 컴포넌트를 직접 만드는 걸 권장해요. Bits UI 컴포넌트와 트랜지션을 함께 쓰는 방법에 대한 자세한 내용은 Transitions 문서를 참고하세요.

코드 펼치기 (Expand Code)

<script lang="ts">
  import { Popover, Separator, Toggle } from "bits-ui";
  import ImageSquare from "phosphor-svelte/lib/ImageSquare";
  import LinkSimpleHorizontalBreak from "phosphor-svelte/lib/LinkSimpleHorizontalBreak";
  import { fly } from "svelte/transition";
  let width = $state(1024);
  let height = $state(768);
</script>
<Popover.Root>
  <Popover.Trigger
    class="rounded-input bg-dark
	text-background shadow-mini hover:bg-dark/95 inline-flex h-10 select-none items-center justify-center whitespace-nowrap px-[21px] text-[15px] font-medium transition-all hover:cursor-pointer active:scale-[0.98]"
  >
    Resize
  </Popover.Trigger>
  <Popover.Portal>
    <Popover.Content
      class="border-dark-10 bg-background shadow-popover z-30 w-full max-w-[328px] rounded-[12px] border p-4"
      sideOffset={8}
      forceMount
    >
      {#snippet child({ wrapperProps, props, open })}
        {#if open}
          <div {...wrapperProps}>
            <div {...props} transition:fly={{ duration: 300 }}>
              <div class="flex items-center">
                <div
                  class="bg-muted mr-3 flex size-12 items-center justify-center rounded-full"
                >
                  <ImageSquare class="size-6" />
                </div>
                <div class="flex flex-col">
                  <h4
                    class="text-[17px] font-semibold leading-5 tracking-[-0.01em]"
                  >
                    Resize image
                  </h4>
                  <p class="text-muted-foreground text-sm font-medium">
                    Resize your photos easily
                  </p>
                </div>
              </div>
              <Separator.Root
                class="bg-dark-10 -mx-4 mb-6 mt-[17px] block h-px"
              />
              <div class="flex items-center pb-2">
                <div class="mr-2 flex items-center">
                  <div class="relative mr-2">
                    <span class="sr-only">Width</span>
                    <span
                      aria-hidden="true"
                      class="text-xxs text-muted-foreground absolute left-5 top-4"
                      >W</span
                    >
                    <input
                      type="number"
                      class="h-input rounded-10px border-border-input bg-background text-foreground w-[119px] border pl-10 pr-2 text-base sm:text-sm"
                      bind:value={width}
                    />
                  </div>
                  <div class="relative">
                    <span class="sr-only">Height</span>
                    <span
                      aria-hidden="true"
                      class="text-xxs text-muted-foreground absolute left-5 top-4"
                      >H</span
                    >
                    <input
                      type="number"
                      class="h-input rounded-10px border-border-input bg-background text-foreground w-[119px] border pl-10 pr-2 text-base sm:text-sm"
                      bind:value={height}
                    />
                  </div>
                </div>
                <Toggle.Root
                  aria-label="toggle constrain portions"
                  class="bg-background hover:bg-muted data-[state=on]:bg-muted inline-flex size-10 items-center justify-center rounded-[9px] transition-all active:scale-[0.98]"
                >
                  <LinkSimpleHorizontalBreak class="size-6" />
                </Toggle.Root>
              </div>
            </div>
          </div>
        {/if}
      {/snippet}
    </Popover.Content>
  </Popover.Portal>
</Popover.Root>

오버레이 컴포넌트 (Overlay Component)

Popover.Overlay 컴포넌트를 사용하면 Popover가 열려 있을 때 그 뒤에 나타나는 오버레이를 만들 수 있어요.

코드 펼치기 (Expand Code)

<script lang="ts">
  import { Popover, Separator, Toggle } from "bits-ui";
  import ImageSquare from "phosphor-svelte/lib/ImageSquare";
  import LinkSimpleHorizontalBreak from "phosphor-svelte/lib/LinkSimpleHorizontalBreak";
  let width = $state(1024);
  let height = $state(768);
</script>
<Popover.Root>
  <Popover.Trigger
    class="rounded-input bg-dark
	text-background shadow-mini hover:bg-dark/95 inline-flex h-10 select-none items-center justify-center whitespace-nowrap px-[21px] text-[15px] font-medium transition-all hover:cursor-pointer active:scale-[0.98]"
  >
    Resize
  </Popover.Trigger>
  <Popover.Portal>
    <Popover.Overlay
      class="data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/80"
    />
    <Popover.Content
      class="border-dark-10 bg-background shadow-popover data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-(--bits-popover-content-transform-origin) z-50 w-full max-w-[328px] rounded-[12px] border p-4"
      sideOffset={8}
    >
      <div class="flex items-center">
        <div
          class="bg-muted mr-3 flex size-12 items-center justify-center rounded-full"
        >
          <ImageSquare class="size-6" />
        </div>
        <div class="flex flex-col">
          <h4 class="text-[17px] font-semibold leading-5 tracking-[-0.01em]">
            Resize image
          </h4>
          <p class="text-muted-foreground text-sm font-medium">
            Resize your photos easily
          </p>
        </div>
      </div>
      <Separator.Root class="bg-dark-10 -mx-4 mb-6 mt-[17px] block h-px" />
      <div class="flex items-center pb-2">
        <div class="mr-2 flex items-center">
          <div class="relative mr-2">
            <span class="sr-only">Width</span>
            <span
              aria-hidden="true"
              class="text-xxs text-muted-foreground absolute left-5 top-4"
              >W</span
            >
            <input
              type="number"
              class="h-input rounded-10px border-border-input bg-background text-foreground w-[119px] border pl-10 pr-2 text-base sm:text-sm"
              bind:value={width}
            />
          </div>
          <div class="relative">
            <span class="sr-only">Height</span>
            <span
              aria-hidden="true"
              class="text-xxs text-muted-foreground absolute left-5 top-4"
              >H</span
            >
            <input
              type="number"
              class="h-input rounded-10px border-border-input bg-background text-foreground w-[119px] border pl-10 pr-2 text-base sm:text-sm"
              bind:value={height}
            />
          </div>
        </div>
        <Toggle.Root
          aria-label="toggle constrain portions"
          class="bg-background hover:bg-muted data-[state=on]:bg-muted inline-flex size-10 items-center justify-center rounded-[9px] transition-all active:scale-[0.98]"
        >
          <LinkSimpleHorizontalBreak class="size-6" />
        </Toggle.Root>
      </div>
    </Popover.Content>
  </Popover.Portal>
</Popover.Root>

API Reference

Popover.Root

The root component used to manage the state of the state of the popover.

Property Type Description Details
open $bindable boolean The open state of the component.Default: false
onOpenChange function - (open: boolean) => void A callback function called when the open state changes.Default:  —— undefined
onOpenChangeComplete function - (open: boolean) => void A callback function called after the open state changes and all animations have completed.Default:  —— undefined
children Snippet The children content to render.Default:  —— undefined

Popover.Trigger

A component which toggles the opening and closing of the popover on press.

Property Type Description Details
openOnHover boolean Whether the popover should open when the trigger is hovered.Default: false
openDelay number The delay in milliseconds before the popover opens after hovering the trigger. Only applies when openOnHover is true.Default: 700
closeDelay number The delay in milliseconds before the popover closes after the mouse leaves the trigger or content. Only applies when openOnHover is true.Default: 300
ref $bindable HTMLButtonElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet The children content to render.Default:  —— undefined
child Snippet - type SnippetProps = { props: Record<string, unknown>; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-state enum - 'open' | 'closed' Whether the popover is open or closed.
data-popover-trigger '' Present on the trigger element.

Popover.Content

The contents of the popover which are displayed when the popover is open.

Property Type Description Details
side enum - 'top' | 'bottom' | 'left' | 'right' The preferred side of the anchor to render the floating element against when open. Will be reversed when collisions occur.Default: 'bottom'
sideOffset number The distance in pixels from the anchor to the floating element.Default: 0
align enum - 'start' | 'center' | 'end' The preferred alignment of the anchor to render the floating element against when open. This may change when collisions occur.Default: 'start'
alignOffset number The distance in pixels from the anchor to the floating element.Default: 0
arrowPadding number The amount in pixels of virtual padding around the viewport edges to check for overflow which will cause a collision.Default: 0
avoidCollisions boolean When true, overrides the side and align options to prevent collisions with the boundary edges.Default: true
collisionBoundary union - Element | null A boundary element or array of elements to check for collisions against.Default:  —— undefined
collisionPadding union - number | Partial<Record<Side, number>> The amount in pixels of virtual padding around the viewport edges to check for overflow which will cause a collision.Default: 0
sticky enum - 'partial' | 'always' The sticky behavior on the align axis. 'partial' will keep the content in the boundary as long as the trigger is at least partially in the boundary whilst 'always' will keep the content in the boundary regardless.Default: 'partial'
hideWhenDetached boolean When true, hides the content when it is detached from the DOM. This is useful for when you want to hide the content when the user scrolls away.Default: true
updatePositionStrategy enum - 'optimized' | 'always' The strategy to use when updating the position of the content. When 'optimized' the content will only be repositioned when the trigger is in the viewport. When 'always' the content will be repositioned whenever the position changes.Default: 'optimized'
strategy enum - 'fixed' | 'absolute' The positioning strategy to use for the floating element. When 'fixed' the element will be positioned relative to the viewport. When 'absolute' the element will be positioned relative to the nearest positioned ancestor.Default: 'fixed'
preventScroll boolean When true, prevents the body from scrolling when the content is open. This is useful when you want to use the content as a modal.Default: false
customAnchor union - string | HTMLElement | Measurable | null Use an element other than the trigger to anchor the content to. If provided, the content will be anchored to the provided element instead of the trigger.Default: null
onInteractOutside function - (event: PointerEvent) => void Callback fired when an outside interaction event occurs, which is a pointerdown event. You can call event.preventDefault() to prevent the default behavior of handling the outside interaction.Default:  —— undefined
onFocusOutside function - (event: FocusEvent) => void Callback fired when focus leaves the dismissible layer. You can call event.preventDefault() to prevent the default behavior on focus leaving the layer.Default:  —— undefined
interactOutsideBehavior enum - 'close' | 'ignore' | 'defer-otherwise-close' | 'defer-otherwise-ignore' The behavior to use when an interaction occurs outside of the floating content. 'close' will close the content immediately. 'ignore' will prevent the content from closing. 'defer-otherwise-close' will defer to the parent element if it exists, otherwise it will close the content. 'defer-otherwise-ignore' will defer to the parent element if it exists, otherwise it will ignore the interaction.Default: 'close'
onEscapeKeydown function - (event: KeyboardEvent) => void Callback fired when an escape keydown event occurs in the floating content. You can call event.preventDefault() to prevent the default behavior of handling the escape keydown event.Default:  —— undefined
escapeKeydownBehavior enum - 'close' | 'ignore' | 'defer-otherwise-close' | 'defer-otherwise-ignore' The behavior to use when an escape keydown event occurs in the floating content. 'close' will close the content immediately. 'ignore' will prevent the content from closing. 'defer-otherwise-close' will defer to the parent element if it exists, otherwise it will close the content. 'defer-otherwise-ignore' will defer to the parent element if it exists, otherwise it will ignore the interaction.Default: 'close'
onOpenAutoFocus function - (event: Event) => void Event handler called when auto-focusing the content as it is opened. Can be prevented.Default:  —— undefined
onCloseAutoFocus function - (event: Event) => void Event handler called when auto-focusing the content as it is closed. Can be prevented.Default:  —— undefined
trapFocus boolean Whether or not to trap the focus within the content when open.Default: true
preventOverflowTextSelection boolean When true, prevents the text selection from overflowing the bounds of the element.Default: true
forceMount boolean Whether or not to forcefully mount the content. This is useful if you want to use Svelte transitions or another animation library for the content.Default: false
dir enum - 'ltr' | 'rtl' The reading direction of the app.Default: 'ltr'
ref $bindable HTMLDivElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet The children content to render.Default:  —— undefined
child Snippet - type ChildSnippetProps = { /** * Props for the positioning wrapper * Do not style this element - * styling should be applied to the content element */ wrapperProps: Record<string, unknown>; /** * Props for your content element * Apply your custom styles here */ props: Record<string, unknown>; /** * Content visibility state * Use this for conditional rendering with * Svelte transitions */ open: boolean; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-state enum - 'open' | 'closed' Whether the popover is open or closed.
data-starting-style '' Present during the initial open frame. Use this to define the starting styles for CSS transitions.
data-ending-style '' Present while closing before unmount. Use this to define the ending styles for CSS transitions.
data-popover-content '' Present on the content element.
CSS Variable Description Details
--bits-popover-content-transform-origin The transform origin of the content element.
--bits-popover-content-available-width The available width of the content element.
--bits-popover-content-available-height The available height of the content element.
--bits-popover-anchor-width The width of the anchor element.
--bits-popover-anchor-height The height of the anchor element.

Popover.ContentStatic

The contents of the popover which are displayed when the popover is open. (Static/No Floating UI)

Property Type Description Details
onInteractOutside function - (event: PointerEvent) => void Callback fired when an outside interaction event occurs, which is a pointerdown event. You can call event.preventDefault() to prevent the default behavior of handling the outside interaction.Default:  —— undefined
onFocusOutside function - (event: FocusEvent) => void Callback fired when focus leaves the dismissible layer. You can call event.preventDefault() to prevent the default behavior on focus leaving the layer.Default:  —— undefined
interactOutsideBehavior enum - 'close' | 'ignore' | 'defer-otherwise-close' | 'defer-otherwise-ignore' The behavior to use when an interaction occurs outside of the floating content. 'close' will close the content immediately. 'ignore' will prevent the content from closing. 'defer-otherwise-close' will defer to the parent element if it exists, otherwise it will close the content. 'defer-otherwise-ignore' will defer to the parent element if it exists, otherwise it will ignore the interaction.Default: 'close'
onEscapeKeydown function - (event: KeyboardEvent) => void Callback fired when an escape keydown event occurs in the floating content. You can call event.preventDefault() to prevent the default behavior of handling the escape keydown event.Default:  —— undefined
escapeKeydownBehavior enum - 'close' | 'ignore' | 'defer-otherwise-close' | 'defer-otherwise-ignore' The behavior to use when an escape keydown event occurs in the floating content. 'close' will close the content immediately. 'ignore' will prevent the content from closing. 'defer-otherwise-close' will defer to the parent element if it exists, otherwise it will close the content. 'defer-otherwise-ignore' will defer to the parent element if it exists, otherwise it will ignore the interaction.Default: 'close'
onOpenAutoFocus function - (event: Event) => void Event handler called when auto-focusing the content as it is opened. Can be prevented.Default:  —— undefined
onCloseAutoFocus function - (event: Event) => void Event handler called when auto-focusing the content as it is closed. Can be prevented.Default:  —— undefined
trapFocus boolean Whether or not to trap the focus within the content when open.Default: true
preventOverflowTextSelection boolean When true, prevents the text selection from overflowing the bounds of the element.Default: true
preventScroll boolean When true, prevents the body from scrolling when the content is open. This is useful when you want to use the content as a modal.Default: false
forceMount boolean Whether or not to forcefully mount the content. This is useful if you want to use Svelte transitions or another animation library for the content.Default: false
dir enum - 'ltr' | 'rtl' The reading direction of the app.Default: 'ltr'
ref $bindable HTMLDivElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet The children content to render.Default:  —— undefined
child Snippet - type SnippetProps = { props: Record<string, unknown>; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-state enum - 'open' | 'closed' Whether the popover is open or closed.
data-starting-style '' Present during the initial open frame. Use this to define the starting styles for CSS transitions.
data-ending-style '' Present while closing before unmount. Use this to define the ending styles for CSS transitions.
data-popover-content '' Present on the content element.

Popover.Overlay

An overlay that can be used to create a semi-transparent overlay behind the popover when open.

Property Type Description Details
forceMount boolean Whether or not to forcefully mount the content. This is useful if you want to use Svelte transitions or another animation library for the content.Default: false
ref $bindable HTMLDivElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet The children content to render.Default:  —— undefined
child Snippet - type SnippetProps = { props: Record<string, unknown>; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-popover-overlay '' Present on the overlay element.
data-state enum - 'open' | 'closed' Whether the popover is open or closed.
data-starting-style '' Present during the initial open frame. Use this to define the starting styles for CSS transitions.
data-ending-style '' Present while closing before unmount. Use this to define the ending styles for CSS transitions.

Popover.Close

A button which closes the popover when pressed and is typically placed in the content.

Property Type Description Details
ref $bindable HTMLButtonElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet The children content to render.Default:  —— undefined
child Snippet - type SnippetProps = { props: Record<string, unknown>; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-popover-close '' Present on the close button.

Popover.Arrow

An optional arrow element which points to the trigger when the popover is open.

Property Type Description Details
width number The width of the arrow in pixels.Default: 8
height number The height of the arrow in pixels.Default: 8
ref $bindable HTMLDivElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet The children content to render.Default:  —— undefined
child Snippet - type SnippetProps = { props: Record<string, unknown>; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-arrow '' Present on the arrow element.
data-popover-arrow '' Present on the arrow element.

Popover.Portal

When used, will render the popover content into the body or custom to element when open

Property Type Description Details
to union - Element | string Where to render the content when it is open. Defaults to the body.Default: document.body
disabled boolean Whether the portal is disabled or not. When disabled, the content will be rendered in its original DOM location.Default: false
children Snippet The children content to render.Default:  —— undefined

더 알아보기 (Learn more)

Popover는 간단한 콘텐츠를 트리거 근처에 띄울 때 쓰고, 더 강한 상호작용이 필요하면 Dialog를 사용해요. 트리거 위치에 맞춰 배치되는 동작은 Tooltip과도 비슷하니 상황에 맞게 골라 쓸 수 있어요.