<!--
  canonical-url: https://www.avonture.be/blog/docusaurus-ask-my-blog-bubble
  published:     2026-10-05
  This is a static plain-Markdown mirror generated at build time.
  Visit the canonical URL above for the fully rendered page, with images and interactive components.
-->

# The Third Door: A Floating Chat Bubble, and the Feature Nobody Could Find

> A feature your visitors cannot find does not exist. This article adds a floating "Ask my blog" bubble to a Docusaurus site — a third entry point into the same question index, and the first one that needs no prior knowledge. Includes the overlay mutual-exclusion trick that keeps two independent floating dialogs from ever opening at once.

---
![The Third Door: A Floating Chat Bubble, and the Feature Nobody Could Find](/img/v2/ask-my-blog-chatbox.webp)

**TL;DR**

I had built a corpus map, a 2,050-question index and a six-mode command palette — and then noticed that every way into the question index required already knowing it was there. This article is the cheap half of that story: a floating chat bubble that opens the question search from any page, and a first-visit hint that mentions the keyboard shortcut once. Plus the small pub-sub trick that guarantees two independent floating dialogs never end up open at the same time.

There is a particular kind of embarrassment reserved for people who build things alone. I had spent weeks on features I was genuinely proud of: an interactive [map of the whole blog](/blog/docusaurus-blog-map), a [question index](/blog/docusaurus-ask-my-blog) generated by a local model, a [command palette](/blog/?q=docker) with six modes.

Then I asked myself a simpler question than usual: how would a reader who has never been here find the question index? There were exactly two ways in. Press `Ctrl`+`K`, then `?` to switch the palette into question mode — which requires knowing both the shortcut and that the mode exists. Or navigate to `/faq`, which requires knowing the page is there.

Both doors were open. Both of them only worked for someone who had already read the article announcing them, which is to say: me.

**Quick Jump:** [What Changed](#what-changed) | [Building the Bubble](#building-the-bubble)

## What Changed

Two things, neither of them a new feature:

```plaintext
1. A floating bubble              2. A first-visit pill
   ┌────────────────┐               ┌─────────────────┐
   │ 🦫 Ask my blog │               │ Press ⌘K to     │
   ├────────────────┤               │ search      ✕   │
   │ [Ask a questi…]│               └─────────────────┘
   │  › How do I …  │                 once per browser,
   │  › What is …   │                 then never again
   └────────────────┘
     bottom-right, every page
```

The bubble is the interesting one, because it is the **third** way into exactly the same question index: `Ctrl+K` then `?`, the standalone `/faq` page, and now a chat-shaped button that follows the reader around. Same corpus, same ranking, same results — three doors.

## Why Three Doors Is Not Redundancy

I resisted the bubble for a while, on the grounds that the palette already did the job. That was wrong, and here is the reasoning that changed my mind:

* **Each door serves a different reader.** The palette serves people who already know it exists. `/faq` serves search engines and people who want to browse a topic. The bubble serves the reader who is stuck in the middle of an article and would never think to press a keyboard shortcut.
* **A floating button is the one affordance everyone already understands.** Nobody needs to be taught what a chat bubble in the corner does. That is precisely why it is worth spending a corner on — and why the panel header wears the same [meerkat mascot](/blog/docusaurus-easter-eggs) that shows up everywhere else on this site.
* **It costs almost nothing to add.** The bubble does not reimplement search — it mounts the existing search component inside a panel. About 150 lines, most of them focus management.
* **The expensive part was already paid for.** The question corpus, the ranking, the lazy fetch: all of it existed. Adding an entry point to a built feature is the highest-leverage work available, and it is the work that gets skipped.

There is a limit to this reasoning, and it is worth stating before you go and add a fourth door. The test is not "how many entry points can I fit?" but "does this one reach a reader the others miss?". I had also planned a homepage tile pointing at the palette, and dropped it: the navbar already shows a permanently visible search box with the shortcut printed in it, on every page. Three doors serving three different readers, yes. Three reminders of the same door, no.

## Building the Bubble

The component is deliberately thin. When the panel is closed, nothing search-related is mounted at all — so the 468 KB question corpus is still only fetched by a reader who actually opens it:

**Project: src/components/AskMyBlogWidget**

**src/components/AskMyBlogWidget/index.tsx**

```typescript
/**
 * AskMyBlogWidget — a third, always-visible entry point into "Ask my blog" (alongside
 * Ctrl+K → `?` and the standalone /faq page): a floating bubble, bottom-right, that opens a
 * small panel wrapping the existing <AskMyBlog> search box (src/components/AskMyBlog). It
 * doesn't reimplement search — <AskMyBlog> is only mounted once the panel is actually open,
 * so the question corpus fetch stays on-demand exactly as it already is for CommandPalette's
 * `?` mode (see AskMyBlog/questionsIndex.js for why that fetch is lazy).
 *
 * Reserves a fixed slot stacked above the scroll-to-top button's corner
 * (src/components/ScrollToTopButton, mounted on every page by src/theme/Layout) rather than
 * detecting its presence at runtime — that button stays hidden until the reader scrolls, and the
 * empty space above it meanwhile is harmless.
 */

import { useCallback, useEffect, useRef, useState, type JSX } from "react";
import { translate } from "@docusaurus/Translate";
import AskMyBlog from "@site/src/components/AskMyBlog";
import { setActiveOverlay } from "@site/src/components/CommandPalette/paletteBus";
import mascot from "@site/static/img/ask_my_blog.webp";
import styles from "./styles.module.css";

const HINT_STORAGE_KEY = "askmyblog_bubble_hint_shown";
const HINT_DELAY_MS = 15_000;

export default function AskMyBlogWidget(): JSX.Element {
  const [open, setOpen] = useState(false);
  const [showHint, setShowHint] = useState(false);
  const panelRef = useRef<HTMLDivElement | null>(null);
  const bubbleRef = useRef<HTMLButtonElement | null>(null);
  const clearOverlayRef = useRef<(() => void) | null>(null);

  // First-visit discoverability, shown at most once ever — same mechanic as
  // CommandPalette/Hint.tsx, offset from its 10s delay so the two don't animate in together.
  useEffect(() => {
    if (localStorage.getItem(HINT_STORAGE_KEY)) return undefined;
    const timer = setTimeout(() => {
      localStorage.setItem(HINT_STORAGE_KEY, "1");
      setShowHint(true);
    }, HINT_DELAY_MS);
    return () => clearTimeout(timer);
  }, []);

  const close = useCallback(() => {
    setOpen(false);
    clearOverlayRef.current?.();
    bubbleRef.current?.focus();
  }, []);

  const toggle = () => {
    setShowHint(false);
    if (open) {
      close();
      return;
    }
    setOpen(true);
    clearOverlayRef.current = setActiveOverlay(close);
  };

  useEffect(() => {
    if (!open) return undefined;

    panelRef.current?.querySelector("input")?.focus();

    function onKeyDown(event: KeyboardEvent) {
      if (event.key === "Escape") {
        event.preventDefault();
        close();
      }
    }

    function onTab(event: KeyboardEvent) {
      if (event.key !== "Tab" || !panelRef.current) return;
      const focusable = panelRef.current.querySelectorAll<HTMLElement>(
        'button, [href], input, [tabindex]:not([tabindex="-1"])',
      );
      if (focusable.length === 0) return;
      const first = focusable[0];
      const last = focusable[focusable.length - 1];
      if (event.shiftKey && document.activeElement === first) {
        event.preventDefault();
        last.focus();
      } else if (!event.shiftKey && document.activeElement === last) {
        event.preventDefault();
        first.focus();
      }
    }

    document.addEventListener("keydown", onKeyDown);
    document.addEventListener("keydown", onTab);
    return () => {
      document.removeEventListener("keydown", onKeyDown);
      document.removeEventListener("keydown", onTab);
    };
  }, [open, close]);

  return (
    <>
      {open && (
        <div
          ref={panelRef}
          className={styles.panel}
          role="dialog"
          aria-modal="true"
          aria-label={translate({ id: "askMyBlogWidget.title", message: "Ask my blog" })}
        >
          <div className={styles.panelHead}>
            <span className={styles.panelHeadTitle}>
              <img
                src={mascot}
                alt=""
                className={styles.panelHeadMascot}
                width="40"
                height="40"
              />
              {translate({ id: "askMyBlogWidget.title", message: "Ask my blog" })}
            </span>
            <button
              type="button"
              className={styles.panelClose}
              aria-label={translate({
                id: "theme.common.askMyBlogClose",
                message: "Close",
                description: "The aria label for closing the Ask my blog chat panel",
              })}
              onClick={close}
            >
              &times;
            </button>
          </div>
          <div className={styles.panelBody}>
            <AskMyBlog
              placeholder={translate({
                id: "blog.askMyBlog.placeholder",
                message: "Ask a question…",
              })}
              maxResults={5}
              showLabel={false}
            />
          </div>
        </div>
      )}
      <button
        ref={bubbleRef}
        type="button"
        className={styles.bubble}
        onClick={toggle}
        aria-haspopup="dialog"
        aria-expanded={open}
        aria-label={translate({
          id: "theme.common.askMyBlog",
          message: "Ask my blog",
          description: "The aria label for the floating Ask my blog chat bubble",
        })}
      >
        {showHint && <span className={styles.pulseRing} aria-hidden="true" />}
        <svg
          className={styles.bubbleIcon}
          viewBox="0 0 24 24"
          fill="none"
          stroke="currentColor"
          strokeWidth="2"
          strokeLinecap="round"
          strokeLinejoin="round"
          aria-hidden="true"
        >
          <path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" />
        </svg>
      </button>
    </>
  );
}
```

**src/components/AskMyBlogWidget/styles.module.css**

```css
.bubble {
  position: fixed;
  right: 30px;
  /* 16px clear of the scroll-to-top button below it (ScrollToTopButton: bottom 30px, 60px
     tall → top edge at 90px) — the two used to sit 10px apart, easy to mis-tap in the
     bottom-right thumb zone. */
  bottom: 106px;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  padding: 0;
  cursor: pointer;
  background: var(--mk-primary);
  border: none;
  border-radius: 50%;
  box-shadow: var(--mk-shadow-3);
  transition:
    transform 0.2s,
    background 0.2s;
}

.bubble:hover {
  background: var(--ifm-color-primary-dark);
  transform: scale(1.06);
}

.bubble:focus-visible {
  outline: 2px solid var(--mk-primary);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .bubble,
  .bubble:hover {
    transform: none;
    transition: none;
  }
}

.bubbleIcon {
  width: 30px;
  height: 30px;
  color: var(--mk-on-line);
}

.pulseRing {
  position: absolute;
  inset: -4px;
  border: 2px solid var(--mk-primary);
  border-radius: 50%;
  animation: askPulse 2.2s ease-out 3;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .pulseRing {
    display: none;
    animation: none;
  }
}

@keyframes askPulse {
  0% {
    opacity: 0.7;
    transform: scale(1);
  }

  100% {
    opacity: 0;
    transform: scale(1.7);
  }
}

@media (max-width: 600px) {
  .bubble {
    right: 16px;
    /* Same 16px clearance above the mobile scroll-to-top button (bottom 16px, 44px tall →
       top edge at 60px). */
    bottom: 76px;
    width: 44px;
    height: 44px;
  }

  .bubbleIcon {
    width: 22px;
    height: 22px;
  }
}

.panel {
  position: fixed;
  right: 30px;
  bottom: 176px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  width: min(360px, calc(100vw - 2rem));
  max-height: min(480px, calc(100vh - 200px));
  overflow: hidden;
  background: var(--mk-surface);
  border: 1px solid var(--mk-border-strong);
  border-radius: var(--mk-radius-lg);
  box-shadow: var(--mk-shadow-3);
  animation: panelIn 0.15s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .panel {
    animation: none;
  }
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.panelHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 1rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--mk-on-line);
  background: var(--mk-primary);
}

.panelHeadTitle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.panelHeadMascot {
  flex-shrink: 0;
  object-fit: cover;
  border: 2px solid var(--mk-on-line);
  border-radius: 50%;
}

.panelClose {
  padding: 0.1rem 0.3rem;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--mk-on-line);
  opacity: 0.85;
  background: none;
  border: none;
  cursor: pointer;
}

.panelClose:hover {
  opacity: 1;
}

.panelBody {
  padding: 0.75rem 1rem 1rem;
  overflow-y: auto;
}

@media (max-width: 600px) {
  .panel {
    right: 16px;
    left: 16px;
    bottom: 128px;
    width: auto;
  }
}
```

It is mounted once per page, in the same `Layout` swizzle that mounts the palette:

```javascript title="src/theme/Layout/index.js"
export default function LayoutWrapper(props) {
  return (
    <Layout {...props}>
      {props.children}
      <CommandPalette />
      <CommandPaletteHint />
      <AskMyBlogWidget />
    </Layout>
  );
}
```

One layout decision worth copying: the bubble reserves a **fixed slot stacked above** the [scroll-to-top button](/blog/docusaurus-go-top)'s corner, rather than detecting that button's presence at runtime. Scroll-to-top is not mounted on every page, and a bit of empty space above it when it is absent is completely harmless — far more harmless than two floating buttons racing to occupy the same 60 pixels.

## The Two-Overlays Problem

The palette and the bubble panel are independent floating dialogs, each openable from several places, and neither knows the other exists. Open one while the other is open and you get two modals stacked, two focus traps fighting, and two `Esc` handlers.

The fix is eight lines, and it lives in the palette's own bus module — so neither component has to import the other:

```typescript title="src/components/CommandPalette/paletteBus.ts"
let activeCloser = null;

export function setActiveOverlay(closeFn) {
  if (activeCloser && activeCloser !== closeFn) activeCloser();
  activeCloser = closeFn;
  return () => {
    if (activeCloser === closeFn) activeCloser = null;
  };
}
```

Each dialog calls `setActiveOverlay(close)` when it opens, and calls the cleanup function it gets back when it closes. Whichever opens second closes whichever was open first. Adding a third overlay later requires changing nothing.

## A Hint That Is Allowed to Appear Exactly Once (skip this if you just want the bubble)

Both the palette's pill and the bubble's pulse ring are first-visit hints, and both follow the same three rules:

* The `localStorage` flag is written **when the hint is shown**, not when it is dismissed. A visitor who ignores it does not get it again on their next page.
* The delays are staggered — the palette's pill at 4 or 10 seconds, the bubble's pulse at 15 — so the two never animate in together and read as a pop-up.
* The pulse ring is removed entirely under `prefers-reduced-motion`, not just slowed down.

The palette's delay is deliberately different per page type, and the reason is worth stating: 10 seconds on an article exists so the pill never interrupts someone who has just started reading. The homepage has no reading to interrupt and is where visitors bounce fastest, so it gets 4 seconds — still long enough not to look like a load-time pop-up.

```typescript title="src/components/CommandPalette/Hint.tsx"
function delayFor(pathname) {
  if (HOME_PATH.test(pathname)) return HOME_DELAY_MS;
  if (ARTICLE_PATH.test(pathname)) return ARTICLE_DELAY_MS;
  return null;
}
```

Returning `null` — rather than a large number — is what makes "this path shows nothing" a distinct, readable state instead of a delay you have to squint at.

## Conclusion

The features in this series took weeks. Making them findable took an afternoon, and it is entirely possible that the afternoon mattered more.

There is a failure mode specific to building your own tools: you are the one user who can never evaluate discoverability, because you cannot un-know where things are. Every door looks obvious from the inside. The only fix I have found is mechanical — list the entry points to a feature, and for each one write down what the reader has to already know in order to use it. Anything whose answer is "that this feature exists" is not an entry point at all.

And when in doubt, put a button in the corner. Everybody knows what it does.
