Skip to Content

Feedback Widget

<FoirFeedback> is a drop-in feedback form for your visitors, anchored to the record the page was rendered from. A reader presses its button or its shortcut, points at what they mean, and writes.

import { createFoirClient, createFoirSubjectRegistry } from '@foir/sdk/data'; import { FoirFeedback } from '@foir/sdk/react'; import * as generated from './foir.generated'; export const subjects = createFoirSubjectRegistry({ label: (record) => (typeof record.title === 'string' ? record.title : null), }); export const foir = createFoirClient({ apiUrl: process.env.PLATFORM_API_URL, apiKey: process.env.PLATFORM_API_KEY, generated, subjects, }); // Anywhere in your tree, once. The button stays in the bottom-right corner. <FoirFeedback client={foir} subjects={subjects} />

That is the entire setup. There is no route table, no per-page configuration, and nothing to keep in step when your URLs change.

Why it takes the client

Every other feedback widget annotates a page, because it is bolted onto a site it knows nothing about: a URL, a screenshot, a CSS selector. All three rot. You change your routes, you redesign, you add a locale prefix, and the comment now points at something else.

This one takes the client your page fetched through. That client already knows which records it read, and the subject registry recorded them, so the comment attaches to the record and survives all three.

It is a React component rather than a script tag for the same reason. A bundle loaded from a <script> tag cannot reach your client or your registry, so the only thing left to anchor to is the address bar. Nothing in this component reads window.location, and that is a property worth stating rather than assuming.

Pointing at what a note is about

The button, or the project’s shortcut key (F unless the project changed it), starts the picker. The element under the pointer is outlined, as far down as the reader points: a heading, one row of a table, an image, a button, a whole section. The bar at the bottom of the screen offers The whole page too.

What the note is filed on is the nearest mark around what was picked:

  • An entry you marked, one paragraph of a prose field, by its _id: the note names the record, the field and the entry, and your team’s notes open on that entry.
  • A field you marked: the note names the record and the field.
  • No mark around it: the note is filed on the page’s record, without a quote. The data API takes a quote only with the field it is in.

Whatever is narrower than its mark is quoted: its text, an image’s alt text, a control’s label. So one row of a link table reads as itself beside the field in your inbox, though the table has no key of its own. This is also the pick a design review makes. Text the reader had selected before they pressed the button or the key is the pick, with no pointing at all: the selection’s words become the quote when they are inside a field you marked.

A mouse points by clicking. The keyboard points with Tab and Enter: up and down step out of an element to the one around it, up to the whole page, and back in, and left and right step across to the element beside it. The bar shows the keys.

What a page shows only on hover can be pointed at too: an image beside a row, an icon on a card. Hold Shift and what hovering showed stays shown while you move to it. An image or icon the pointer passes through is found by where it is, so the pointer over its spot outlines it, and whatever the outline is on is shown for as long as it is outlined. A part with no words of its own is quoted by what it is and what is around it: “An image in “Heartbreaker Run your pop-up ops…””. A touch screen points by tapping. Escape, or Cancel on the bar, ends it. Every press is held while pointing, so pointing at a link does not follow it, and the page still scrolls.

The quote is never what a visitor typed into one of your form fields: a field is quoted by its label or its prompt. Nothing records a CSS selector or an element path. The next deploy would make it point at something else, while the quote reads the same beside the field in your inbox whatever your markup became.

Marking fields and entries

Mark each element that shows a field with the registry’s field. It returns one attribute to spread onto the element:

<> <nav {...subjects.field(menu, 'items', { label: 'Menu' })}>…</nav> <h1 {...subjects.field(page, 'title', { label: 'Title' })}>{page.title}</h1> </>

A prose field is made of entries, and node marks one of them by its _id. Mark the field’s own element too, so a reader can step out from an entry to the whole field:

<div {...subjects.field(page, 'body', { label: 'Body' })}> {page.body.entries.map((entry) => ( <Entry key={entry._id} {...subjects.field(page, 'body', { label: 'Body', node: entry._id })} /> ))} </div>

Ask for _id on every entry and every record, so there is something to mark. The data API leaves out a field it does not serve rather than failing the query.

The SDK’s renderers do all of this for you, given the field they show:

const body = { subjects, record: page, key: 'body', label: 'Body' }; <RichTextRenderer value={page.body} field={body} /> <Content items={page.sections} ctx={ctx} field={{ subjects, record: page, key: 'sections', label: 'Sections' }} />

They mark their own element as the field and each passage with an _id as an entry. A content renderer hands each embedded model’s component its entry’s mark, to spread on the component’s own element.

To file a note on a record the page shows inside another, a related product or a linked article, mark that record’s fields with it as the subject.

The attribute is an opaque token: the page prints none of the model, the record or the field, and the registry keeps what the token stands for. The same field gets the same token on the server and in the browser, so a server-rendered mark hydrates unchanged. Call field where the browser renders too: a mark only a server component made has nothing in the browser to read it back.

A visitor’s note may name a field the visitor can read, which is any field the page could have fetched for them; the data API refuses any other. label is the only thing about a field the widget shows. Without one, it names the record alone.

What it is about

For a pick that is not a field, three answers, in order:

  1. The subject prop, if you pass one.
  2. The last record the client addressed by name, from the registry.
  3. Nothing, said out loud.

The third is the interesting one. A record that only ever appeared inside a list or a search result is recorded but never promoted, so a page built from lists alone has no subject, and the panel says:

There is nothing on this page to give feedback on.

rather than picking one of the twelve, and rather than falling back to the URL. Name one yourself where that is wrong:

<FoirFeedback client={foir} subjects={subjects} subject={{ modelKey: 'article', recordId: id }} />

Or state that a page genuinely has none. The widget then shows nothing at all, whatever the registry still holds from the page before it:

<FoirFeedback client={foir} subjects={subjects} subject={null} />

What the visitor sees

A human label, or nothing.

About: Delivery and returns · Title

The label comes from your registry’s label function, or from the label prop, which wins. With neither, the widget renders the composer with no name on it. It never renders the model key or the record id: those are what the note is filed against, they are your project’s internal vocabulary, and a reader has no use for them.

The panel

The panel floats over the page, opened out of the button. It is not modal, so a reader can look at the page and point again with Change while they write. They can move it by its header, and it stays on screen. On a narrow screen it is a sheet from the bottom instead. Escape and its Close button shut it.

layout="inline" opens the panel under the button, in the page’s flow, instead.

Where the button sits

The button stays in a corner of the viewport as the page scrolls, bottom-right unless position names another: bottom-left, top-right or top-left. The panel opens from it toward the middle of the screen. position="static" leaves the button where you place the component, in a header or a toolbar, and the inline layout always does. Anything else about its place is style on the wrapper, or className.

icon is shown before the button’s text.

What the project decides

Whether the button shows, its text and the shortcut are the project’s, set in Notes → Settings or in foir.config.ts, so your team changes them without a deploy:

SettingDefaultWhat it does
Show the feedback buttonOnOff, the widget is reached through the shortcut alone.
Button textFeedbackThe button’s text.
Keyboard shortcutFThe key that starts pointing, or none.

The shortcut is ignored while the reader is typing, and with Ctrl, Alt or Cmd held. A device with a mouse shows the key on the button, with <FoirKbd>; a touch screen, which has no keyboard to press it on, shows the button alone.

What it asks before it renders

Mounting reads noteConfig, and that single call settles everything, because the API charges it notes:create and answers exactly the callers writeNote takes a note from:

The answerWhat the visitor gets
A signed-in userThe widget, with a capture button if screenshots are on
A visitor, on a project that takes their notesThe widget, with an optional field for an email to reply to, and no capture button
Sign-in requiredNothing at all
missing required scope: notes:createNothing at all

Until it answers, nothing renders either. A widget that could only say “you cannot” is not worth a button, so a visitor on a project that takes no visitors’ notes never sees one. In development the widget logs why, naming the project’s setting.

The scope case reads like a bad API key and is not one. The key reached the surface; the signed-in user’s role is short notes:create, which a new project’s default role does not carry. The widget logs that in full, so the person wiring it up is not sent looking at the key:

[foir] <FoirFeedback>: the API refused with "missing required scope: notes:create". This is not a bad API key: the key reached the surface. The signed-in USER's role does not grant notes:create ...

See Notes & Comments for how to grant it.

The probe runs again whenever the session in your <FoirProvider> changes, so a visitor who signs in sees the widget appear, and again each time the panel opens. A panel that was open when feedback closed says “Feedback is not open right now”, rather than asking the reader to try again.

A visitor who is not signed in

A site with no sign-in can take feedback too. Turn on Accept anonymous notes in the project’s Notes settings, and give notes:create to visitors on the publishable key the page uses. Nothing changes in your code: the client without a bearerToken is the visitor’s client.

A visitor’s note is nobody’s, so it differs from a signed-in user’s in three ways:

  • It may carry an address. The composer adds an optional email field, sent as contactEmail when it is filled in. Nothing verifies it, and nothing treats it as proof of who wrote the note.
  • It is answered with a receipt. Nothing reads a visitor’s note back, so the widget asks for the note’s id and createdAt alone, thanks the visitor, and hands both to onVisitorSubmitted. It shows no id: nothing opens a visitor’s note from one. onSubmitted is for a signed-in user’s note.
  • It carries no screenshot. The probe withholds the capture button from a visitor.

The note lands in the record’s notes panel like any other, as an anonymous note with the address it was left with. Per-address and per-project limits apply to visitors’ notes.

Agents

An agent reviewing your site can file what it finds the way a person does. In a browser it drives, every control has a name and the picker answers the keyboard.

Where the browser offers WebMCP , the widget also offers the page as two tools, while the caller may write:

ToolWhat it does
list_feedback_targetsLists the page and each marked field on screen, by label, with the start of its text and an id. Read-only, and marked as returning the page’s own content, which an agent must read as data.
send_feedbackSends a note about the page or one of those targets, with an optional quote of part of a target, through the same write as the composer.

The tools tell an agent what the widget tells a reader: labels, never a model key or a record id. A note an agent sends is written under the same credential and the same limits as one a person sends, and the picker’s outline shows what it is about while it is sent. A browser without WebMCP is the page as it was.

Screenshots

The capture button appears only when the project allows screenshots and the browser can capture. Pressing it opens the browser’s own picker, which is the consent gate: nothing is captured without the reader choosing a window or a tab in a dialog your site does not control, and dismissing that dialog is treated as a decision rather than an error.

For a pick that is not the whole page, the button reads Add a screenshot of it, and the still is cropped to what was picked, with this tab offered first. A reader who shares another tab or their whole screen instead gets the frame whole, since a rectangle measured on this page means nothing in it.

A reader can also draw one. While pointing, S switches to drawing: drag a box around what you want to show, and letting go asks the browser for the frame, cropped to the box. The picker then asks what the screenshot is about: point at it, or take the whole page. Escape goes back from drawing to pointing. Drawing is offered where capture is: to a signed-in user, with screenshots on, in a browser that can capture, with a mouse.

Capture is opt-in per submission. A reader who never presses the button, or who presses Remove screenshot, sends a note that names no file at all.

A still is uploaded through the ordinary upload: uploadFile, a PUT of the bytes, then the upload’s own token says they have landed. So your plan’s per-file limit and your project’s storage allowance apply to it and the size recorded is the authoritative one. An upload that fails fails the whole submission: a note that arrived without the picture is worse than one that did not arrive, because the author cannot tell.

Attaching needs files:write as well as notes:create, on the key and on the user’s role.

The capture itself is available on its own if you are building your own form:

import { captureFoirScreen, isFoirScreenCaptureSupported } from '@foir/sdk/media'; if (isFoirScreenCaptureSupported()) { const still = await captureFoirScreen(); // null when the picker is dismissed still?.blob; // the bytes, for upload still?.dataUrl; // the same bytes, for a preview // Or one part of the page, as getBoundingClientRect() measures it. const part = await captureFoirScreen({ crop: element.getBoundingClientRect() }); }

Styling

The built-in styles take their colours, radius and type from tokens, with a plain look as the default: borders in the text colour, and the type your page already uses. Set the tokens with appearance:

<FoirFeedback client={foir} appearance={{ colorText: '#171717', colorMuted: '#737373', colorBackground: '#ffffff', colorBorder: '#e5e5e5', colorPrimary: '#171717', colorPrimaryText: '#ffffff', radius: '12px', }} />
TokenCSS custom propertyDefault
colorText--foir-feedback-textInherited; the browser’s canvas text over the page
colorMuted--foir-feedback-mutedThe text at three quarters
colorBackground--foir-feedback-backgroundNone inline; the browser’s canvas over the page
colorBorder--foir-feedback-bordercurrentColor
colorPrimary--foir-feedback-primaryNo fill; the picker’s outline in the browser’s highlight
colorPrimaryText--foir-feedback-primary-textInherited
colorDanger--foir-feedback-danger#c0392b
radius--foir-feedback-radius8px; controls take three quarters
fontFamily--foir-feedback-font-familyInherited
fontSize--foir-feedback-font-sizeInherited; the smaller lines are relative to it

Each token is a CSS custom property on the wrapper, so a stylesheet can set it instead, from your design system’s own variables:

[data-foir-feedback] { --foir-feedback-border: hsl(var(--border)); --foir-feedback-radius: var(--radius); }

The picker’s outline and bar sit in their own shadow root, so your stylesheet cannot hide or restyle them by accident. They read the same tokens.

Your own styles

Passing className turns the built-in inline styles off entirely, tokens included, so there is nothing to override. The parts carry stable attributes:

AttributePart
data-foir-feedbackThe wrapper, with data-foir-feedback-layout naming the layout and data-foir-feedback-position the corner
data-foir-feedback-triggerThe button
data-foir-kbdThe shortcut on the button
data-foir-feedback-popoverThe floating panel’s holder, sheet on a narrow screen
data-foir-feedback-panelThe panel
data-foir-feedback-headerThe heading and the Close button; dragging it moves the panel
data-foir-feedback-closeThe Close button
data-foir-feedback-titleThe heading
data-foir-feedback-subjectThe label line, with the Change button (data-foir-feedback-point)
data-foir-feedback-quoteThe quote of what was picked
data-foir-feedback-bodyThe textarea
data-foir-feedback-contactA visitor’s email field
data-foir-feedback-captureThe capture button
data-foir-feedback-screenshotThe preview image
data-foir-feedback-removeThe remove button
data-foir-feedback-submitThe submit button
data-foir-feedback-statusA status line
data-foir-feedback-errorA failure line
data-foir-feedback-overlayThe host of the picker’s shadow root

FoirKbd

<FoirKbd> shows one key the way the button shows the shortcut, so your own copy can say the same thing:

import { FoirKbd } from '@foir/sdk/react'; <p>Press <FoirKbd>F</FoirKbd> to comment on anything on this page.</p>

It takes className, which turns its built-in look off as on the widget, and style.

Props

PropTypeDescription
clientFoirFeedbackClientYour data client. Required.
subjectsFoirSubjectRegistryThe registry you passed to createFoirClient. It makes your marked fields pickable. Without it, only the subject prop can name a subject.
subjectFoirSubject | nullPin what the page is about. null states there is nothing here, and the widget shows nothing.
labelstringWhat to call the page’s subject on screen. Wins over the registry’s label.
titlestringThe panel heading. Default Send feedback.
placeholderstringThe composer placeholder.
defaultOpenbooleanStart with the panel open, about the whole page.
layout'popover' | 'inline'Float the panel over the page, or open it under the button. Default popover.
position'bottom-right' | 'bottom-left' | 'top-right' | 'top-left' | 'static'The corner the button stays in. Default bottom-right; static leaves it where it is placed.
iconReactNodeShown before the button’s text.
appearanceFoirFeedbackAppearanceThe built-in styles’ tokens. Ignored with className.
onSubmitted(note: FoirUserNote) => voidCalled with a signed-in user’s note once it is written.
onVisitorSubmitted(receipt: FoirNoteReceipt) => voidCalled with a visitor’s receipt, { id, createdAt }, once their note is written.
onError(error: unknown) => voidCalled with anything that failed. It is logged either way.
classNamestringStyle it yourself, and drop the inline styles and their tokens.
styleCSSPropertiesStyle on the wrapper, for its place.

The client prop is typed structurally, so a client generated by foir types satisfies it without a cast. Its files namespace is optional: a credential that cannot upload still type-checks, and simply never offers capture. Notes are written through writeNote. A module generated before the data API served it cannot send a visitor’s note: re-run foir types.

A client made without a generated module satisfies it too. A site that reads nothing else through Foir, and renders its pages some other way, can make one for the widget alone and pin the subject:

const foir = createFoirClient({ apiUrl, apiKey, announceManifestFallback: false }); <FoirFeedback client={foir} subject={{ modelKey: 'page', recordId: page.id }} label={page.title} />

It fetches GET /v1/manifest once, when the widget mounts, and prints from what the data API serves, so it has no module to fall out of date.

What it never does

  • Read window.location, or derive anything from it.
  • Show the model key or the record id to a visitor, or to an agent.
  • Record a CSS selector or an element path.
  • Quote what a visitor typed into one of your form fields.
  • Invent a subject when there is none.
  • Send a note whose attachment failed to upload.
  • Capture anything the reader did not press a button for.
Last updated on