# Popover

> Position Driver.js popovers with the side and align options, choose which buttons they show, change the button text, and add your own buttons and click handlers.

Every step and highlight can show a popover next to its element. This page covers where it sits and which buttons it has. To change how it looks, see [Theming](https://driverjs.com/docs/theming.md).

## Position

`side` picks the side of the element the popover sits on: `"top"`, `"right"`, `"bottom"` (default) or `"left"`. `align` places it along that side: `"start"` (default), `"center"` or `"end"`.

```js
import { driver } from "driver.js";
import "driver.js/dist/driver.css";

const driverObj = driver();

driverObj.highlight({
  element: "#sample-box",
  popover: {
    title: "Left Start",
    description: "On the left, aligned with the top edge.",
    side: "left",
    align: "start",
  },
});
```

When the popover doesn't fit on that side, it moves to one where it does. Scroll the box near an edge of the window and try again.

## Buttons

`showButtons` picks the buttons: `"next"`, `"previous"` and `"close"`. A tour shows all three by default. Set it on the driver for every step, or on a step's `popover`.

```js
import { driver } from "driver.js";
import "driver.js/dist/driver.css";

const driverObj = driver({
  showButtons: ["next", "previous"],
  steps: [
    { element: "#search", popover: { title: "Search" } },
    { element: "#export", popover: { title: "Export" } },
  ],
});

driverObj.drive();
```

- `disableButtons` takes the same values and shows the button greyed out. Previous is disabled on the first step.
- The arrow keys follow the buttons: they do nothing when their button is hidden or disabled. Escape does nothing when the close button is disabled.
- `highlight()` shows no buttons by default. Outside a tour, Next and Previous only do something if you set `onNextClick` and `onPrevClick`.
- A step with [`popover.instruction`](https://driverjs.com/docs/action-driven-tours.md#make-the-user-act) keeps the Next button but shows it disabled until the user has done it.

### Change Button Text

`nextBtnText`, `prevBtnText` and `doneBtnText` set the button text, and HTML is allowed. `closeBtnLabel` sets the screen reader label of the close button.

```js
import { driver } from "driver.js";
import "driver.js/dist/driver.css";

const driverObj = driver({
  nextBtnText: "Next &rarr;",
  prevBtnText: "&larr; Back",
  doneBtnText: "Finish",
  closeBtnLabel: "Close tour",
  steps: [
    // ...
  ],
});

driverObj.drive();
```

### Event Handlers

`onNextClick`, `onPrevClick`, `onCloseClick` and `onDoneClick` run instead of the button's default action. The tour then only moves or ends when you call `moveNext()`, `movePrevious()` or `destroy()`. Set them on the driver for every step, or on a step's `popover`.

`onDoneClick` runs on the last step instead of `onNextClick`, so it tells you the user finished the tour.

```js
import { driver } from "driver.js";
import "driver.js/dist/driver.css";

const driverObj = driver({
  steps: [
    // ...
  ],
  onNextClick: () => {
    console.log("Next clicked");
    driverObj.moveNext();
  },
  onPrevClick: () => {
    console.log("Previous clicked");
    driverObj.movePrevious();
  },
  onCloseClick: () => {
    console.log("Close clicked");
    driverObj.destroy();
  },
  onDoneClick: () => {
    console.log("Done clicked");
    driverObj.destroy();
  },
});

driverObj.drive();
```

`onNextClick` also runs when the step is completed another way: the right arrow key, an overlay click with `overlayClickBehavior: "nextStep"`, [`advanceOn`](https://driverjs.com/docs/interactive-tours.md#advance-on-click) or `advance()`. For loading something before the next step, see [Wait for a Save](https://driverjs.com/docs/wait-for-a-save.md#when-next-does-the-work).

To add your own buttons, like Skip or Restart, or translate the built-in ones, see [Custom Buttons](https://driverjs.com/docs/custom-buttons.md).
