Skip to content

BbHoverCard

A preview card that opens on hover or keyboard focus, as a component or as the v-bb-hover-card directive.

import { BbHoverCard } from 'bitboss-ui';

On this page

Use it for

Reach for BbHoverCard to preview what a link points at without leaving the page. The person behind a name, an event in a calendar, a commit in a feed.

Use something else when

  • BbTooltip: one line of text that names or explains the control
  • BbPopover: the user works in the panel, with a form, a picker or settings
  • BbDropdown: it is a list of actions

Put nothing in a hover card that the reader cannot reach another way. A touch screen never shows it, and a screen reader in browse mode may never open it.

Passthrough

Hover or tap a part to outline it. The toggles turn on loading, errors and warnings where the component has them; only parts get a row.

A preview behind a link

Put a link in the activator slot and spread its props onto it.

Deploy of invoice-export approved by Amara Okonkwo two hours ago.

The activator must take focus, so a keyboard user can open the card too. A <span> cannot; a link can, and it already goes where the card points.

Shortcuts in the card

A card may hold shortcuts, as long as each one also exists on the page the link opens.

Tab from the activator moves into the card, and Tab past its last control moves on and closes it. Escape closes it and puts focus back on the activator. The header and footer slots stay outside the scrolling body, and every slot gets close.

Timing and the safe zone

delay is how long the pointer or focus rests on the activator before the card opens: 350 ms by default.

Closing has no prop. Once the pointer has left both the activator and the card, the card waits 200 ms. A pointer heading diagonally for a button in the card stays inside a safe zone, so the card stays open. Try it on the events above.

A press on the activator, a right-click included, closes the card at once. When something the user opened on purpose is on screen, a menu or a dialog, the cards outside it stay closed. A click never toggles the card: the link does what links do.

To open or close the card from your own code, bind v-model. disabled keeps it shut, and closes it if it is open.

One per row with v-bb-hover-card

For a card on every row, use v-bb-hover-card and write the body once in a <BbHoverCardPortal>.

No component exists until the pointer or focus reaches the row, so a thousand rows cost what a thousand links cost. The value takes three forms:

vue
<!-- a portal name: mind the inner quotes -->
<a v-bb-hover-card="'person-card'" :href="person.url">Amara Okonkwo</a>

<!-- a component: the keys of data become its props -->
<a v-bb-hover-card="{ portal: PersonCard, data: { person } }" :href="person.url">
    Amara Okonkwo
</a>

<!-- any BbHoverCard prop next to the portal; the argument is the placement -->
<a v-bb-hover-card:right="{ portal: 'person-card', data: { person }, width: 240 }" :href="person.url">
    Amara Okonkwo
</a>

Without the inner quotes, person-card is person minus card, and nothing opens. npx bitboss-ui check and the ESLint rule bitboss-ui/portal-names catch that, and any name no <BbHoverCardPortal> declares. A named portal's slot gets { data, close }, where data is the binding's data. A component portal gets no close: when the content needs one, use a named portal.

Importing vBbHoverCard registers the directive locally, as these demos do; the plugin's injectDirectives registers it globally.

Restyling with passthrough

Restyle the card through pt:<part>: root, panel, header, content and footer, the same parts as BbPopover.

Fixed in 4f780d9 by Hugo Ferreira.