Skip to main content

Popover

A popover is a floating container whose content becomes visible when its trigger button is clicked. It's useful for displaying contextual information, menus, or actions without navigating away from the current view.

The popover is a compound component composed of Root, Button, and Content subcomponents.

Popover

Usage

Example
import type { NubeSDK } from "@tiendanube/nube-sdk-types";
import { Popover, Text } from "@tiendanube/nube-sdk-jsx";

function MyComponent() {
return (
<Popover.Root>
<Popover.Button variant="primary">More info</Popover.Button>
<Popover.Content
padding={16}
gap={8}
width="260px"
background="var(--main-background)"
borderRadius={8}
>
<Text heading={4} modifiers={["bold"]}>
Shipping &amp; returns
</Text>
<Text>Free shipping on all orders over $50.</Text>
<Text>Easy 30-day returns, no questions asked.</Text>
</Popover.Content>
</Popover.Root>
);
}

export function App(nube: NubeSDK) {
nube.send("ui:slot:set", () => ({
ui: {
slots: {
after_product_description: <MyComponent />,
},
},
}));
}

Open by default

Use the defaultOpen property on Popover.Root to render the popover with its content already visible.

Popover open by default
<Popover.Root defaultOpen>
<Popover.Button variant="secondary">Promotion</Popover.Button>
<Popover.Content>
<Text>Use the code WELCOME10 to get 10% off.</Text>
</Popover.Content>
</Popover.Root>

Custom trigger with asChild

By default Popover.Button renders its own button element. Set asChild to merge the trigger behavior onto a single custom child element instead, letting you use any component as the trigger.

Custom trigger
<Popover.Root>
<Popover.Button asChild>
<Link>Need help?</Link>
</Popover.Button>
<Popover.Content>
<Text>Contact our support team at support@example.com.</Text>
</Popover.Content>
</Popover.Root>

Positioning

The popover positions its content automatically — there are no placement props to configure:

  • Desktop: the content is anchored to the trigger and is right-aligned by default (its right edge lines up with the trigger, growing leftward). It automatically flips to left-aligned when right-alignment would overflow the left edge of the viewport.
  • Mobile (narrow viewports): the content is presented as a bottom sheet instead of an anchored panel.

You can still pass the style prop on Popover.Content for advanced overrides, but it's not required for normal use and may interfere with the automatic alignment.

Subcomponents

Popover.Root

The root container that wraps the trigger and content and controls the popover's visibility.

PropertyTypeRequiredDescription
childrenNubeChildrenComponentNoThe Popover.Button and Popover.Content elements.
defaultOpenbooleanNoWhether the popover is open on initial render.
styleStyleSheetNoCustom styles for the popover root.
idstringNoOptional unique identifier for the component.

Popover.Button

The trigger that toggles the visibility of the popover content. It inherits the style and props of the Button component, except for onClick, which is managed internally to control the popover.

PropertyTypeRequiredDescription
childrenstringNoText or content of the trigger button.
asChildbooleanNoWhen true, merges the trigger behavior onto a single custom child instead of rendering its own button.
disabledbooleanNoWhether the button is disabled.
variant"primary"
"secondary"
"transparent"
"link"
NoButton style variant.
widthSizeNoWidth of the button (e.g., "100%", "200px").
heightSizeNoHeight of the button.
styleStyleSheetNoCustom styles for the button.

Popover.Content

The floating container that holds the content shown when the popover is open. It inherits the style and props of the Box component and uses theme variables for its default background, border, and box shadow.

PropertyTypeRequiredDescription
childrenNubeChildrenComponentNoContent to be displayed when the popover is open.
widthSizeNoWidth of the content (e.g., "100%", "200px").
heightSizeNoHeight of the content.
marginSizeNoOuter spacing around the content.
paddingSizeNoInner spacing of the content (e.g., "16px").
gapSizeNoSpacing between child elements (e.g., "1rem").
borderRadiusSizeNoBorder radius of the content (e.g., "8px").
backgroundstringNoBackground color (can be a CSS variable like "var(--primary-color)").
colorstringNoContent color (can be a CSS variable like "var(--primary-color)").
alignItemsFlexItemsNoThe CSS property align-items
alignContentFlexContentNoThe CSS property align-content
justifyContentFlexContentNoThe CSS property justify-content
direction"row"
"col"
NoLayout direction for children (row for horizontal, col for vertical).
styleStyleSheetNoCustom styles for advanced overrides. Not required for normal use, and may interfere with the automatic positioning.
idstringNoOptional unique identifier for the component.

Help us improve NubeSDK

Found an issue or have a suggestion? Let us know on GitHub.