# Keep app widgets above the bottom bar (https://docs.salla.dev/twilight/react/recipes/keep-app-widgets-above-the-bottom-bar)



Use this when your store app or snippet adds a button fixed to the bottom of the screen: a chat bubble, a WhatsApp button, a "back to top" arrow, a cookie bar.

**Goal:** on a phone, your widget sits just above the theme's bottom navigation bar instead of covering its tabs. On desktop, and on themes without a bar, it stays where you put it.

React themes that have a fixed bottom bar on phones register it with [`useBottomInset`](https://docs.salla.dev/twilight/react/hooks/use-bottom-inset). While the bar is visible, the engine sets this CSS variable on `<html>`:

```css
--twilight-bottom-inset: 64px; /* the height the bar takes, in pixels */
```

It is not set when the bar is hidden (desktop, or a bar that slides away), and not set on themes without a bar. The engine never moves your widget for you: you read the variable.

### Add the variable to your widget's `bottom` [#add-the-variable-to-your-widgets-bottom]

Keep the offset you already use, and add the variable to it. The `0px` fallback keeps the widget where it was wherever the variable is not set.

```css title="my-app-widget.css"
.my-chat-launcher {
  position: fixed;
  inset-inline-end: 16px;
  bottom: calc(var(--twilight-bottom-inset, 0px) + 16px);
}
```

A widget that uses `inset-block-end` works the same way: `inset-block-end: calc(var(--twilight-bottom-inset, 0px) + 16px)`.

### Or set it from JavaScript [#or-set-it-from-javascript]

If your widget positions itself in script, or is added by a third-party loader whose CSS you cannot edit, set the same value as an inline style. Custom properties are inherited, so `var()` works on any element in the page:

```js
const launcher = document.querySelector('#my-chat-launcher');
launcher.style.bottom = 'calc(var(--twilight-bottom-inset, 0px) + 16px)';
```

The browser updates the position on its own when the variable changes, so there is nothing to listen for. To read the number itself, for example to size a panel, read it from `<html>`:

```js
const inset = parseFloat(
  getComputedStyle(document.documentElement).getPropertyValue('--twilight-bottom-inset')
) || 0;
```

### Animate the move (optional) [#animate-the-move-optional]

The bar can hide and show while the customer scrolls. A transition on `bottom` makes the widget follow smoothly:

```css
.my-chat-launcher {
  transition: bottom 200ms ease;
}
```

## Check it worked [#check-it-worked]

Open the store at phone width (DevTools device mode) on a React theme with a bottom bar.

1. In the console, `getComputedStyle(document.documentElement).getPropertyValue('--twilight-bottom-inset')` returns a value such as `64px`.
2. Your widget sits 16px above the bar, and every tab of the bar can be tapped.
3. Widen the window past the phone breakpoint: the bar hides, the variable is empty, and your widget drops back to 16px from the bottom.

<Callout type="warn" title="Traps">
  * **Always give a fallback.** `var(--twilight-bottom-inset)` without `, 0px` makes the whole `calc()` invalid where the variable is not set, and the widget loses its `bottom`.
  * **Use `bottom`, not `transform`.** A `transform` on an element that contains other fixed elements becomes their containing block and moves them somewhere else. Many chat loaders nest a fixed iframe inside a fixed wrapper.
  * **Put it on the element that is fixed.** Setting `bottom` on a wrapper with no size, or on a parent that is not `position: fixed`, moves nothing.
  * **Leave full-screen panels alone.** An opened chat window that covers the screen should keep `bottom: 0`. Add the variable to the launcher only.
  * **Classic (Twig) themes do not set the variable.** The fallback keeps your widget correct there.
</Callout>

## Where to go next [#where-to-go-next]

* [useBottomInset](https://docs.salla.dev/twilight/react/hooks/use-bottom-inset), for what the variable holds and when it changes.
* [Run app code on a page](https://docs.salla.dev/twilight/react/recipes/run-app-code-on-a-page), for widgets that only belong on some pages.
