Skip to Content
Soundor Components
Components

Popover

A floating editor for interactive controls.

Use Popover for a small editor beside a control or graph handle. It accepts ordinary controls, including a nested Select or ContextMenu.

import { Button, Knob, Popover, Select, ValueField } from '@soundor/components';
import { useTheme } from '@soundor/components/theme';
import { View } from '@soundor/react';
import { useRef, useState } from 'react';
import type { UiNode } from 'soundor:ui';

export default function Demo() {
  const theme = useTheme();
  const [open, setOpen] = useState(false);
  const [shifted, setShifted] = useState(false);
  const anchor = useRef<UiNode | null>(null);
  return (
    <View style={{ alignItems: 'center', gap: theme.spacing.spaceMd }}>
      <Popover>
        <Popover.Trigger>
          <Button>Settings</Button>
        </Popover.Trigger>
        <Popover.Content accessibilityLabel="Settings">
          <Select
            label="Quality"
            options={[
              { value: 'draft', label: 'Draft' },
              { value: 'studio', label: 'Studio' },
            ]}
          />
          <Knob label="Drive" min={0} max={12} defaultValue={3} />
        </Popover.Content>
      </Popover>
      <Button onPress={() => setOpen(!open)}>
        {open ? 'Close editor' : 'Open editor'}
      </Button>
      <Button
        ref={anchor}
        onPress={() => setShifted(!shifted)}
        style={{ marginLeft: shifted ? theme.spacing.spaceXl * 3 : 0 }}
      >
        Move anchor
      </Button>
      <Popover open={open} onOpenChange={setOpen}>
        <Popover.Content
          anchor={anchor}
          side="right"
          accessibilityLabel="Floating editor"
          autoFocus={false}
          dismissOnOutside={false}
        >
          <ValueField label="Trim" min={-12} max={12} defaultValue={0} />
        </Popover.Content>
      </Popover>
    </View>
  );
}
popover.tsx, running in the web runtime.Source
<Popover>
  <Popover.Trigger>
    <Button>Settings</Button>
  </Popover.Trigger>
  <Popover.Content side="bottom" accessibilityLabel="Settings">
    <Popover.Arrow />
    <Knob parameter={parameters.gain} />
    <ValueField parameter={parameters.gain} />
  </Popover.Content>
</Popover>

Popover accepts defaultOpen or a controlled open and onOpenChange. Popover.Trigger enhances one Button, Pressable or compatible control in place and reports its expanded state. Popover.Content requires an accessible label and uses dialog semantics. Configure side, align and offset to choose its preferred placement; it flips and clamps at the editor's edges. The content and its padding scroll together when they are taller than the available space. Use style, styles.root or theme.components.Popover.root to style it.

Arrow

Render one optional <Popover.Arrow /> inside Popover.Content. It uses the surface's background and border and points at the anchor centre, following flips and shifts as space allows without overlapping rounded corners. offset is the gap to the arrow tip when present, or to the surface when absent. Use style, styles.root or theme.components.PopupArrow.root to override the arrow's base width (12), protruding height (6), backgroundColor, borderColor or borderWidth. The size values are in logical pixels.

import { Button, Popover } from '@soundor/components';
import { Text, View, useViewSize } from '@soundor/react';
import { useState } from 'react';

type Side = 'top' | 'bottom' | 'left' | 'right';

function Example({
  label,
  side,
  align = 'center',
  cornerRadius,
}: {
  label: string;
  side: Side;
  align?: 'start' | 'center' | 'end';
  cornerRadius?: number;
}) {
  const [arrow, setArrow] = useState(true);
  return (
    <Popover>
      <Popover.Trigger>
        <Button>{label}</Button>
      </Popover.Trigger>
      <Popover.Content
        side={side}
        align={align}
        accessibilityLabel={`${label} example`}
        autoFocus={false}
        style={[
          { width: 156 },
          cornerRadius !== undefined && {
            borderBottomLeftRadius: cornerRadius,
          },
        ]}
      >
        {arrow && (
          <>
            <Popover.Arrow debugId="popover-arrow" />
          </>
        )}
        <Button onPress={() => setArrow(!arrow)}>
          {arrow ? 'Hide arrow' : 'Show arrow'}
        </Button>
      </Popover.Content>
    </Popover>
  );
}

export default function Demo() {
  const { width, height } = useViewSize();
  return (
    <View
      style={{
        width: Math.max(0, width - 40),
        height: Math.max(0, height - 40),
        alignItems: 'center',
        justifyContent: 'center',
        gap: 8,
      }}
    >
      <View style={{ position: 'absolute', top: 0 }}>
        <Example label="Flip at top edge" side="top" />
      </View>
      <View style={{ position: 'absolute', left: 0, bottom: 0 }}>
        <Example label="Shift" side="top" />
      </View>
      <View style={{ position: 'absolute', left: -18, bottom: 42 }}>
        <Example label="Edge" side="top" cornerRadius={30} />
      </View>
      <Text>Choose a side to see the arrow follow its trigger.</Text>
      <View style={{ flexDirection: 'row', gap: 8 }}>
        <Example label="Top" side="top" />
        <Example label="Bottom" side="bottom" />
      </View>
      <View style={{ flexDirection: 'row', gap: 8 }}>
        <Example label="Left" side="left" align="start" />
        <Example label="Right" side="right" align="end" />
      </View>
    </View>
  );
}
popover-arrows.tsx, running in the web runtime.Source

For a triggerless editor set anchor to a node ref, a point or rectangle in logical view coordinates, or a stable { getRegion } reader. Supplying a new point follows React state; a reader or ref can follow movement outside React.

<Popover open={editing} onOpenChange={setEditing}>
  <Popover.Content
    anchor={markerRef}
    accessibilityLabel="Point editor"
    autoFocus={false}
    dismissOnOutside={false}
  >
    <ValueField {...valueProps} />
    <Button onPress={() => setEditing(false)}>Done</Button>
  </Popover.Content>
</Popover>

By default, focus moves to the first control; on close it returns to where it was unless it has moved elsewhere. Set autoFocus or restoreFocus to false to opt out. Escape closes from inside the panel or while focused on its trigger or node anchor. Tab stays available. A non-modal surface leaves the background interactive; its outside dismissal lets the press through. Set modal to trap focus and block background pointer input. Use non-modal mode with dismissOnOutside={false} and an explicit close control for persistent editors.

Props

Popover

Prop

Type

Popover.Trigger

Prop

Type

Popover.Content

Prop

Type

Popover.Arrow

Prop

Type

See Popup anchors for the supported anchor shapes.

On this page