> For the complete documentation index, see [llms.txt](https://docs.rierino.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rierino.com/sdk-core-ui/components/popover.md). Agents can also search and read this documentation through its [MCP server](https://docs.rierino.com/~gitbook/mcp).

# Popover

Shows extra content or a small form next to the element that opened it.

{% code title="popover/demo.tsx" %}

```tsx
import { Button, Popover } from "@rierino-open/core-ui";

export default function PopoverDemo() {
  return (
    <Popover>
      <Button appearance="outline">Stock details</Button>
      <Popover.Content aria-label="Stock details">
        <Popover.Header>
          <Popover.Title>Linen shirt</Popover.Title>
          <Popover.Description>Stock across all warehouses.</Popover.Description>
        </Popover.Header>
        <Popover.Body>
          <p style={{ fontSize: 13 }}>Istanbul: 42 · Berlin: 17 · Lisbon: 8</p>
        </Popover.Body>
        <Popover.Footer>
          <Popover.Close>Close</Popover.Close>
        </Popover.Footer>
      </Popover.Content>
    </Popover>
  );
}
```

{% endcode %}

## Usage

{% tabs %}
{% tab title="React app" %}

```tsx
import { Button, Popover } from '@rierino-open/core-ui';

<Popover>
  <Button appearance="outline">Stock details</Button>
  <Popover.Content aria-label="Stock details">
    <Popover.Header>
      <Popover.Title>Linen shirt</Popover.Title>
    </Popover.Header>
    <Popover.Body>…</Popover.Body>
  </Popover.Content>
</Popover>
```

{% endtab %}

{% tab title="Hosted editor" %}

```jsx
import CoreUI from '@rierino-open/core-ui';
const { Button, Popover } = CoreUI;

<Popover>
  <Button appearance="outline">Stock details</Button>
  <Popover.Content aria-label="Stock details">
    <Popover.Header>
      <Popover.Title>Linen shirt</Popover.Title>
    </Popover.Header>
    <Popover.Body>…</Popover.Body>
  </Popover.Content>
</Popover>
```

{% endtab %}
{% endtabs %}

`Popover` takes two children: the trigger, and `Popover.Content`. The trigger can be any Core UI `Button`. Pressing it toggles the popover. Pressing `Esc` or clicking outside closes it.

### Which overlay to use

| Use                                                               | When                                                                                      |
| ----------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
| **Popover**                                                       | Extra information or a small form that belongs to one element, and doesn't block the page |
| [Menu](https://docs.rierino.com/sdk-core-ui/components/menu.md)   | A list of actions to choose from                                                          |
| [Modal](https://docs.rierino.com/sdk-core-ui/components/modal.md) | A task or decision that needs full attention before going back to the page                |

### Parts

| Part                  | Purpose                                                            |
| --------------------- | ------------------------------------------------------------------ |
| `Popover`             | Connects the trigger to the content and holds the open state       |
| `Popover.Trigger`     | An unstyled button to open the popover. Any `Button` works instead |
| `Popover.Content`     | The floating box, with an arrow pointing at the trigger            |
| `Popover.Header`      | Groups the title and description at the top                        |
| `Popover.Title`       | The heading                                                        |
| `Popover.Description` | A line of text under the title                                     |
| `Popover.Body`        | The main content                                                   |
| `Popover.Footer`      | Buttons at the bottom                                              |
| `Popover.Close`       | An outline button that closes the popover                          |
| `Popover.Primitive`   | React Aria's `Popover`, unstyled                                   |

## Examples

### Placement

`placement` sets which side of the trigger the popover opens on: `top`, `bottom`, `start`, `end`, `left` or `right`, optionally followed by an alignment such as `bottom start`. It flips to the other side when there isn't room.

{% code title="popover/placement.tsx" %}

```tsx
import { Button, Popover } from "@rierino-open/core-ui";

export default function PopoverPlacement() {
  return (
    <div style={{ display: "flex", gap: 12 }}>
      {(["top", "bottom", "start", "end"] as const).map((placement) => (
        <Popover key={placement}>
          <Button appearance="outline">{placement}</Button>
          <Popover.Content aria-label={`Placed ${placement}`} placement={placement} className="min-w-0">
            <p style={{ fontSize: 13 }}>Placed {placement}</p>
          </Popover.Content>
        </Popover>
      ))}
    </div>
  );
}
```

{% endcode %}

Popover content is at least 20rem wide. The example above uses `className="min-w-0"` to let short content shrink.

### Without an arrow

{% code title="popover/no-arrow\.tsx" %}

```tsx
import { Button, Popover } from "@rierino-open/core-ui";

export default function PopoverNoArrow() {
  return (
    <Popover>
      <Button appearance="outline">Without arrow</Button>
      <Popover.Content aria-label="Without arrow" showArrow={false}>
        <p style={{ fontSize: 13 }}>No arrow points at the trigger.</p>
      </Popover.Content>
    </Popover>
  );
}
```

{% endcode %}

### Forms in a popover

A popover suits quick edits. Control it with `isOpen` and `onOpenChange` on `Popover`, so you can close it after saving. `Popover.Close` closes it without saving.

{% code title="popover/form.tsx" %}

```tsx
import { useState } from "react";
import { Button, Popover, TextField } from "@rierino-open/core-ui";

export default function PopoverForm() {
  const [open, setOpen] = useState(false);
  const [price, setPrice] = useState("49.90");
  const [saved, setSaved] = useState("49.90");

  return (
    <div style={{ display: "grid", gap: 12, justifyItems: "center", fontSize: 12 }}>
      <Popover isOpen={open} onOpenChange={setOpen}>
        <Button appearance="outline">Edit price</Button>
        <Popover.Content aria-label="Edit price">
          <Popover.Header>
            <Popover.Title>Price</Popover.Title>
          </Popover.Header>
          <Popover.Body>
            <TextField aria-label="Price" type="number" value={price} onChange={(e) => setPrice(e.target.value)} />
          </Popover.Body>
          <Popover.Footer>
            <Popover.Close>Cancel</Popover.Close>
            <Button
              intent="g-button"
              onPress={() => {
                setSaved(price);
                setOpen(false);
              }}
            >
              Save
            </Button>
          </Popover.Footer>
        </Popover.Content>
      </Popover>
      <span>Saved price: {saved}</span>
    </div>
  );
}
```

{% endcode %}

{% hint style="info" %}
**Popover.Close only closes**

`Popover.Close` runs its own `onPress` to close the popover. Passing `onPress` replaces that, so the popover stays open. To save and close in one press, use a normal `Button` and set the controlled `isOpen` to `false`, as above.
{% endhint %}

## On small screens

On screens up to 600px wide, the content opens as a full-width sheet at the bottom of the screen instead of next to the trigger. Set `respectScreen={false}` on `Popover.Content` to keep it next to the trigger at every size.

## Accessibility

* **Name the content** with `aria-label` on `Popover.Content`.
* The trigger gets `aria-expanded` while the popover is open.
* Focus stays on the trigger when the popover opens. `Tab` moves into the popover's content, and `Esc` closes it and returns focus to the trigger.
* Don't put essential information only in a popover: people have to know to open it.

## Styling

| Target               | How                                                                                                                               |
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| The box              | `className` on `Popover.Content`                                                                                                  |
| The arrow            | Takes its colour from `--primary` ([theme variables](https://docs.rierino.com/sdk-core-ui/foundations/colors.md#theme-variables)) |
| Header, body, footer | `className` on each part                                                                                                          |

The footer stacks its buttons on small screens, last button on top, and lines them up in a row with space between from the `sm` breakpoint (640px) up.

`Popover.Content` sets `data-placement` to the side it opened on, and `data-entering` and `data-exiting` while it animates.

## API reference

### Popover

| Prop           | Type                          | Default | Description                                                   |
| -------------- | ----------------------------- | ------- | ------------------------------------------------------------- |
| `isOpen`       | `boolean`                     |         | Whether the overlay is open by default (controlled).          |
| `defaultOpen`  | `boolean`                     |         | Whether the overlay is open by default (uncontrolled).        |
| `onOpenChange` | `((isOpen: boolean) => void)` |         | Handler that is called when the overlay's open state changes. |

### Popover.Content

| Prop              | Type                            | Default    | Description                                                                                                                                                                        |
| ----------------- | ------------------------------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `placement`       | `Placement`                     | `'bottom'` | The placement of the element with respect to its anchor element.                                                                                                                   |
| `crossOffset`     | `number`                        | `0`        | The additional offset applied along the cross axis between the element and its anchor element.                                                                                     |
| `shouldFlip`      | `boolean`                       | `true`     | Whether the element should flip its orientation (e.g. top to bottom or left to right) when there is insufficient room for it to render completely.                                 |
| `offset`          | `number`                        | `8`        | The additional offset applied along the main axis between the element and its anchor element.                                                                                      |
| `className`       | `string \| ((state) => string)` |            | The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. |
| `showArrow`       | `boolean`                       | `true`     | Shows an arrow pointing at the trigger.                                                                                                                                            |
| `respectScreen`   | `boolean`                       | `true`     | On screens up to 600px wide, shows the content as a sheet at the bottom of the screen instead of next to the trigger.                                                              |
| `aria-label`      | `string`                        |            |                                                                                                                                                                                    |
| `aria-labelledby` | `string`                        |            |                                                                                                                                                                                    |

These also accept the other props of React Aria's [Popover](https://react-spectrum.adobe.com/react-aria/Popover.html#props) and [DialogTrigger](https://react-spectrum.adobe.com/react-aria/Dialog.html#dialogtrigger).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rierino.com/sdk-core-ui/components/popover.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
