Skip to content

Build your personal knowledge base with Trilium Notes

refactor(attributes): lay the detail popup out as settings rows

Elian Doran4168ec1ba8bf
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 33596be71e..ae29871867 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -522,20 +522,19 @@
},
"attribute_detail": {
"close_button_title": "Cancel changes and close",
- "attr_name_title": "Attribute name can be composed of alphanumeric characters, colon and underscore only",
"name": "Name",
"value": "Value",
- "target_note_title": "Relation is a named connection between source note and target note.",
+ "target_note_title": "The note this relation points to.",
"target_note": "Target note",
- "promoted_title": "Promoted attribute is displayed prominently on the note.",
+ "promoted_title": "Shown as an editable field on every note that has this attribute.",
"promoted": "Promoted",
- "promoted_alias_title": "The name to be displayed in the promoted attributes UI.",
+ "promoted_alias_title": "Shown on the promoted field in place of the attribute's own name.",
"promoted_alias": "Alias",
- "multiplicity_title": "Multiplicity defines how many attributes of the same name can be created - at max 1 or more than 1.",
+ "multiplicity_title": "Whether a note can carry this attribute more than once.",
"multiplicity": "Multiplicity",
"single_value": "Single value",
"multi_value": "Multi value",
- "label_type_title": "Type of the label will help Trilium to choose suitable interface to enter the label value.",
+ "label_type_title": "Decides which kind of field the value is entered in.",
"label_type": "Type",
"text": "Text",
"textarea": "Multi-line Text",
@@ -545,12 +544,12 @@
"date_time": "Date & Time",
"time": "Time",
"url": "URL",
- "precision_title": "What number of digits after floating point should be available in the value setting interface.",
+ "precision_title": "How many decimal places the value can be entered with.",
"precision": "Precision",
"digits": "digits",
- "inverse_relation_title": "Optional setting to define to which relation is this one opposite. Example: Father - Son are inverse relations to each other.",
+ "inverse_relation_title": "The relation pointing back the other way, such as Son for Father. Optional.",
"inverse_relation": "Inverse relation",
- "inheritable_title": "Inheritable attribute will be inherited to all descendants under this tree.",
+ "inheritable_title": "Applies to this note and to everything below it in the tree.",
"inheritable": "Inheritable",
"save_and_close_button": "Save & close",
"delete": "Delete",
@@ -662,6 +661,20 @@
"add_new_relation_definition": "Add new relation definition",
"placeholder": "Type the labels and relations here"
},
+ "attribute_list_panel": {
+ "title": "Attributes",
+ "no_attributes": "No attributes",
+ "inherited_one": "{{count}} inherited",
+ "inherited_other": "{{count}} inherited",
+ "inheritable": "Inheritable: applies to this note and to its whole subtree",
+ "delete": "Delete this attribute",
+ "no_target": "No target note",
+ "inverse_of": "inverse of {{name}}",
+ "type_label": "Label",
+ "type_relation": "Relation",
+ "type_label_definition": "Label definition",
+ "type_relation_definition": "Relation definition"
+ },
"abstract_bulk_action": {
"remove_this_search_action": "Remove this search action"
},
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.css b/apps/client/src/widgets/attribute_widgets/attribute_detail.css
index 9e749eb808..8a988f4954 100644
--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.css
+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.css
@@ -13,28 +13,37 @@
contain: none;
}
-.attr-help td {
- color: var(--muted-text-color);
- padding: 5px;
+/* The help sits beside the name rather than under it: only a handful of names have any, and the ones
+ that do run to several lines, which would push the rest of the form out of reach. */
+.attr-name-field {
+ display: flex;
+ align-items: center;
+ gap: 4px;
}
-.attr-help .attr-help-page-button {
- margin-inline-start: 5px;
- vertical-align: middle;
+.attr-name-field > input {
+ flex: 1;
+ min-width: 0;
}
-.attr-edit-table {
- width: 100%;
+/*
+ * Settings-style rows, but in 500px rather than a settings page: the fields are what the popup is for, so
+ * they get a column of their own wide enough to type a note title into, instead of being sized to their
+ * content and pushed against the right edge. Every control fills that column, so they share an edge.
+ */
+.attr-edit-rows .option-row-input {
+ flex: 0 0 260px;
}
-.attr-edit-table th {
- text-align: start;
+.attr-edit-rows .option-row-input > input,
+.attr-edit-rows .option-row-input > select {
+ width: 100%;
}
-/* The switch carries no label of its own here — the row header names it, as it does for every
- other field — so it does not need the gap it would otherwise keep for one. */
-.attr-edit-table .switch-button {
- margin-inline-start: 0;
+/* A toggle takes no such column: nothing is typed into it, so leaving it at its own width keeps it at the
+ end of the row as in the settings, and gives the label and its description the rest of the room. */
+.attr-edit-rows .option-row:has(.switch-widget) .option-row-input {
+ flex: 0 0 auto;
}
/* The title takes the leftover room, so the badge follows it and the close button stays at the end. */
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
index c47d5a7025..69258f3ab7 100644
--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
@@ -1,6 +1,7 @@
import "./attribute_detail.css";
import type { DefinitionObject, LabelType, Multiplicity } from "@triliumnext/commons";
+import { ComponentProps } from "preact";
import { useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";
import appContext from "../../components/app_context.js";
@@ -22,13 +23,12 @@ import FormAutocomplete, { AUTOCOMPLETE_DROPDOWN_SELECTOR } from "../react/FormA
import { FormDropdownDivider, FormListItem } from "../react/FormList.jsx";
import FormSelect from "../react/FormSelect.jsx";
import FormTextBox, { FormTextBoxWithUnit } from "../react/FormTextBox.jsx";
-import FormToggle from "../react/FormToggle.jsx";
-import HelpButton from "../react/HelpButton.jsx";
+import HelpTooltipButton from "../react/HelpTooltipButton.jsx";
import NoteAutocomplete from "../react/NoteAutocomplete.jsx";
import NoteLink, { NewNoteLink } from "../react/NoteLink.jsx";
-import RawHtml from "../react/RawHtml.jsx";
import { disposeReactWidget, ParentComponent, renderReactWidgetAtElement } from "../react/react_utils.jsx";
-import { ATTR_HELP } from "./attr_help.js";
+import OptionsRow, { OptionsRowWithToggle } from "../type_widgets/options/components/OptionsRow.jsx";
+import { ATTR_HELP, AttrHelpEntry } from "./attr_help.js";
export interface AttributeDetailOpts {
allAttributes?: Attribute[];
@@ -313,6 +313,7 @@ function AttributeForm({ opts, attrType, currentNoteId, onCancel, onAttributesCh
// Committing mid-composition makes the spawning editor re-render and swallow the
// characters being composed: https://github.com/zadam/trilium/pull/3812
const isComposing = useRef(false);
+ const nameHelp = lookupAttributeHelp(attrType, name);
useEffect(() => {
if (focus === "name") {
@@ -381,180 +382,173 @@ function AttributeForm({ opts, attrType, currentNoteId, onCancel, onAttributesCh
</div>
)}
- <table class="attr-edit-table">
- <tbody>
- <tr title={t("attribute_detail.attr_name_title")}>
- <th>{t("attribute_detail.name")}</th>
- <td>
- <FormAutocomplete
- className="attr-input-name"
- inputRef={nameRef}
- currentValue={name}
- readOnly={!isOwned}
- source={suggestAttributeNames}
- openOnFocus
- onChange={(newName) => isComposing.current ? setName(newName) : commitName(newName)}
- onCompositionStart={() => isComposing.current = true}
- onCompositionEnd={(e) => {
- isComposing.current = false;
- commitName(e.currentTarget.value);
- }}
- />
- </td>
- </tr>
-
- <AttributeNameHelp attrType={attrType} name={name} />
-
- {attrType === "relation" && (
- <tr class="attr-row-target-note">
- <th title={t("attribute_detail.target_note_title")}>{t("attribute_detail.target_note")}</th>
- <td>
- <NoteAutocomplete
- noteId={attribute.value || undefined}
- readOnly={!isOwned}
- opts={TARGET_NOTE_OPTS}
- noteIdChanged={commitTargetNote}
- />
- </td>
- </tr>
- )}
-
- {attrType === "label" && (
- <tr class="attr-row-value">
- <th>{t("attribute_detail.value")}</th>
- <td>
- <FormAutocomplete
- className="attr-input-value"
- currentValue={value}
- readOnly={!isOwned}
- source={suggestLabelValues}
- openOnFocus
- onChange={(newValue) => isComposing.current ? setValue(newValue) : commitValue(newValue)}
- onCompositionStart={() => isComposing.current = true}
- onCompositionEnd={(e) => {
- isComposing.current = false;
- commitValue(e.currentTarget.value);
- }}
- />
- </td>
- </tr>
- )}
-
- {isDefinition(attrType) && (
- <tr class="attr-row-promoted" title={t("attribute_detail.promoted_title")}>
- <th>{t("attribute_detail.promoted")}</th>
- <td>
- <FormToggle
- currentValue={!!definition.isPromoted}
- disabled={!isOwned}
- onChange={(isPromoted) => commitDefinition({ isPromoted })}
- />
- </td>
- </tr>
- )}
-
- {isDefinition(attrType) && definition.isPromoted && (
- <tr class="attr-row-promoted-alias">
- <th title={t("attribute_detail.promoted_alias_title")}>{t("attribute_detail.promoted_alias")}</th>
- <td>
- <FormTextBox
- className="attr-input-promoted-alias"
- currentValue={definition.promotedAlias ?? ""}
- disabled={!isOwned}
- onChange={(promotedAlias) => commitDefinition({ promotedAlias })}
- />
- </td>
- </tr>
- )}
-
- {isDefinition(attrType) && !opts.hideMultiplicity && (
- <tr class="attr-row-multiplicity">
- <th title={t("attribute_detail.multiplicity_title")}>{t("attribute_detail.multiplicity")}</th>
- <td>
- <FormSelect
- className="attr-input-multiplicity"
- values={MULTIPLICITIES}
- keyProperty="value"
- titleProperty="title"
- currentValue={definition.multiplicity ?? "single"}
- disabled={!isOwned}
- onChange={(multiplicity) => commitDefinition({ multiplicity: multiplicity as Multiplicity })}
- />
- </td>
- </tr>
- )}
-
- {attrType === "label-definition" && (
- <tr class="attr-row-label-type">
- <th title={t("attribute_detail.label_type_title")}>{t("attribute_detail.label_type")}</th>
- <td>
- <FormSelect
- className="attr-input-label-type"
- values={LABEL_TYPES}
- keyProperty="value"
- titleProperty="title"
- currentValue={definition.labelType ?? "text"}
- disabled={!isOwned}
- onChange={(labelType) => commitDefinition({ labelType: labelType as LabelType })}
- />
- </td>
- </tr>
- )}
-
- {attrType === "label-definition" && definition.labelType === "number" && (
- <tr class="attr-row-number-precision">
- <th title={t("attribute_detail.precision_title")}>{t("attribute_detail.precision")}</th>
- <td>
- <FormTextBoxWithUnit
- className="attr-input-number-precision"
- type="number"
- min={0}
- unit={t("attribute_detail.digits")}
- currentValue={definition.numberPrecision?.toString() ?? ""}
- disabled={!isOwned}
- onChange={(precision) => commitDefinition({
- numberPrecision: precision === "" ? undefined : parseInt(precision, 10)
- })}
- />
- </td>
- </tr>
- )}
-
- {attrType === "relation-definition" && (
- <tr class="attr-row-inverse-relation">
- <th title={t("attribute_detail.inverse_relation_title")}>{t("attribute_detail.inverse_relation")}</th>
- <td>
- <FormAutocomplete
- className="attr-input-inverse-relation"
- currentValue={definition.inverseRelation ?? ""}
- disabled={!isOwned}
- source={suggestRelationNames}
- openOnFocus
- onChange={(inverseRelation) => commitDefinition({
- // A relation name, so the same characters are dropped as in the name field
- inverseRelation: utils.filterAttributeName(inverseRelation)
- })}
- />
- </td>
- </tr>
- )}
-
- <tr class="attr-row-inheritable" title={t("attribute_detail.inheritable_title")}>
- <th>{t("attribute_detail.inheritable")}</th>
- <td>
- <FormToggle
- currentValue={isInheritable}
- disabled={!isOwned}
- onChange={(checked) => {
- setIsInheritable(checked);
- attribute.isInheritable = checked;
- onAttributesChanged?.(allAttributes ?? []);
- }}
- />
- </td>
- </tr>
- </tbody>
- </table>
+ <div class="attr-edit-rows">
+ <OptionsRow name="attr-name" label={t("attribute_detail.name")}>
+ <AttributeNameField
+ help={nameHelp}
+ className="attr-input-name"
+ inputRef={nameRef}
+ currentValue={name}
+ readOnly={!isOwned}
+ source={suggestAttributeNames}
+ openOnFocus
+ onChange={(newName) => isComposing.current ? setName(newName) : commitName(newName)}
+ onCompositionStart={() => isComposing.current = true}
+ onCompositionEnd={(e) => {
+ isComposing.current = false;
+ commitName(e.currentTarget.value);
+ }}
+ />
+ </OptionsRow>
+
+ {attrType === "relation" && (
+ <OptionsRow
+ name="attr-target-note"
+ label={t("attribute_detail.target_note")}
+ description={t("attribute_detail.target_note_title")}
+ >
+ <NoteAutocomplete
+ noteId={attribute.value || undefined}
+ readOnly={!isOwned}
+ opts={TARGET_NOTE_OPTS}
+ noteIdChanged={commitTargetNote}
+ />
+ </OptionsRow>
+ )}
+
+ {attrType === "label" && (
+ <OptionsRow name="attr-value" label={t("attribute_detail.value")}>
+ <FormAutocomplete
+ className="attr-input-value"
+ currentValue={value}
+ readOnly={!isOwned}
+ source={suggestLabelValues}
+ openOnFocus
+ onChange={(newValue) => isComposing.current ? setValue(newValue) : commitValue(newValue)}
+ onCompositionStart={() => isComposing.current = true}
+ onCompositionEnd={(e) => {
+ isComposing.current = false;
+ commitValue(e.currentTarget.value);
+ }}
+ />
+ </OptionsRow>
+ )}
+
+ {isDefinition(attrType) && (
+ <OptionsRowWithToggle
+ name="attr-promoted"
+ label={t("attribute_detail.promoted")}
+ description={t("attribute_detail.promoted_title")}
+ currentValue={!!definition.isPromoted}
+ disabled={!isOwned}
+ onChange={(isPromoted) => commitDefinition({ isPromoted })}
+ />
+ )}
+
+ {isDefinition(attrType) && definition.isPromoted && (
+ <OptionsRow
+ name="attr-promoted-alias"
+ label={t("attribute_detail.promoted_alias")}
+ description={t("attribute_detail.promoted_alias_title")}
+ >
+ <FormTextBox
+ className="attr-input-promoted-alias"
+ currentValue={definition.promotedAlias ?? ""}
+ disabled={!isOwned}
+ onChange={(promotedAlias) => commitDefinition({ promotedAlias })}
+ />
+ </OptionsRow>
+ )}
+
+ {isDefinition(attrType) && !opts.hideMultiplicity && (
+ <OptionsRow
+ name="attr-multiplicity"
+ label={t("attribute_detail.multiplicity")}
+ description={t("attribute_detail.multiplicity_title")}
+ >
+ <FormSelect
+ className="attr-input-multiplicity"
+ values={MULTIPLICITIES}
+ keyProperty="value"
+ titleProperty="title"
+ currentValue={definition.multiplicity ?? "single"}
+ disabled={!isOwned}
+ onChange={(multiplicity) => commitDefinition({ multiplicity: multiplicity as Multiplicity })}
+ />
+ </OptionsRow>
+ )}
+
+ {attrType === "label-definition" && (
+ <OptionsRow
+ name="attr-label-type"
+ label={t("attribute_detail.label_type")}
+ description={t("attribute_detail.label_type_title")}
+ >
+ <FormSelect
+ className="attr-input-label-type"
+ values={LABEL_TYPES}
+ keyProperty="value"
+ titleProperty="title"
+ currentValue={definition.labelType ?? "text"}
+ disabled={!isOwned}
+ onChange={(labelType) => commitDefinition({ labelType: labelType as LabelType })}
+ />
+ </OptionsRow>
+ )}
+
+ {attrType === "label-definition" && definition.labelType === "number" && (
+ <OptionsRow
+ name="attr-number-precision"
+ label={t("attribute_detail.precision")}
+ description={t("attribute_detail.precision_title")}
+ >
+ <FormTextBoxWithUnit
+ className="attr-input-number-precision"
+ type="number"
+ min={0}
+ unit={t("attribute_detail.digits")}
+ currentValue={definition.numberPrecision?.toString() ?? ""}
+ disabled={!isOwned}
+ onChange={(precision) => commitDefinition({
+ numberPrecision: precision === "" ? undefined : parseInt(precision, 10)
+ })}
+ />
+ </OptionsRow>
+ )}
+
+ {attrType === "relation-definition" && (
+ <OptionsRow
+ name="attr-inverse-relation"
+ label={t("attribute_detail.inverse_relation")}
+ description={t("attribute_detail.inverse_relation_title")}
+ >
+ <FormAutocomplete
+ className="attr-input-inverse-relation"
+ currentValue={definition.inverseRelation ?? ""}
+ disabled={!isOwned}
+ source={suggestRelationNames}
+ openOnFocus
+ onChange={(inverseRelation) => commitDefinition({
+ // A relation name, so the same characters are dropped as in the name field
+ inverseRelation: utils.filterAttributeName(inverseRelation)
+ })}
+ />
+ </OptionsRow>
+ )}
+
+ <OptionsRowWithToggle
+ name="attr-inheritable"
+ label={t("attribute_detail.inheritable")}
+ description={t("attribute_detail.inheritable_title")}
+ currentValue={isInheritable}
+ disabled={!isOwned}
+ onChange={(checked) => {
+ setIsInheritable(checked);
+ attribute.isInheritable = checked;
+ onAttributesChanged?.(allAttributes ?? []);
+ }}
+ />
+ </div>
{isOwned && (
<div class="attr-save-delete-button-container">
@@ -580,31 +574,25 @@ function AttributeForm({ opts, attrType, currentNoteId, onCancel, onAttributesCh
}
/**
- * Describes what a well-known attribute does, for the attribute currently being edited. Renders
- * nothing for names Trilium attaches no meaning to, which is most of them.
+ * The name field and, for a name Trilium attaches a meaning to, the button explaining what it does. The
+ * explanations run to several lines and most names have none, so they are not shown under the field.
*/
-function AttributeNameHelp({ attrType, name }: { attrType: AttrType; name: string }) {
- const entry = attrType ? ATTR_HELP[attrType]?.[name] : undefined;
-
- if (!entry) {
- return null;
- }
-
- const { description, helpPage } = typeof entry === "string" ? { description: entry, helpPage: undefined } : entry;
-
+function AttributeNameField({ help, ...autocompleteProps }: { help?: AttrHelpEntry } & ComponentProps<typeof FormAutocomplete>) {
return (
- <tr class="attr-help">
- {/* Descriptions carry markup of their own, e.g. <code> or a list of possible values. */}
- <td colSpan={2}>
- <strong>{name}</strong>
- {" - "}
- <RawHtml html={description} />
- {helpPage && <HelpButton className="attr-help-page-button" helpPage={helpPage} />}
- </td>
- </tr>
+ <div class="attr-name-field">
+ {/* The row's label is bound to the field by the id the row hands down, which lands here. */}
+ <FormAutocomplete {...autocompleteProps} />
+ {help && <HelpTooltipButton {...help} />}
+ </div>
);
}
+/** Normalised so that the shorthand entries, which are the description alone, read like the rest. */
+function lookupAttributeHelp(attrType: AttrType, name: string): AttrHelpEntry | undefined {
+ const entry = attrType ? ATTR_HELP[attrType]?.[name] : undefined;
+ return typeof entry === "string" ? { description: entry } : entry;
+}
+
/** Constant so it does not re-initialise the autocomplete on every render. */
const TARGET_NOTE_OPTS = { allowCreatingNotes: true };
@@ -613,7 +601,8 @@ const MULTIPLICITIES = [
{ value: "multi", title: t("attribute_detail.multi_value") }
];
-const LABEL_TYPES = [
+/** Exported so that hosts listing definitions can name their label type as the popup does. */
+export const LABEL_TYPES = [
{ value: "text", title: t("attribute_detail.text") },
{ value: "textarea", title: t("attribute_detail.textarea") },
{ value: "number", title: t("attribute_detail.number") },
@@ -768,7 +757,7 @@ const ATTR_TITLES: Record<string, string> = {
const isNewLayout = isExperimentalFeatureEnabled("new-layout");
-function positionPopup(popup: HTMLElement, { x, y }: AttributeDetailOpts, parentOffset: { top: number; left: number }) {
+function positionPopup(popup: HTMLElement, { x, y, anchor }: AttributeDetailOpts, parentOffset: { top: number; left: number }) {
const outerWidth = popup.offsetWidth;
const outerHeight = popup.offsetHeight;
const windowHeight = document.documentElement.clientHeight;
@@ -836,9 +825,9 @@ function toCssPos(value: number | string) {
return typeof value === "number" ? `${value}px` : value;
}
-type AttrType = "label" | "label-definition" | "relation" | "relation-definition" | undefined;
+export type AttrType = "label" | "label-definition" | "relation" | "relation-definition" | undefined;
-function getAttrType(attribute: Attribute): AttrType {
+export function getAttrType(attribute: Attribute): AttrType {
if (attribute.type === "label") {
// A bare prefix (`#label:`) defines nothing, so it stays an ordinary label — editing it as a
// definition would only offer a name-less one back.
diff --git a/apps/client/src/widgets/react/HelpTooltipButton.css b/apps/client/src/widgets/react/HelpTooltipButton.css
new file mode 100644
index 0000000000..e66349309a
--- /dev/null
+++ b/apps/client/src/widgets/react/HelpTooltipButton.css
@@ -0,0 +1,24 @@
+/*
+ * A flex box of its own, so the icon centres on whatever it sits beside rather than on the text baseline
+ * of the span holding it — which carries the line height around it and drops the icon below the middle.
+ * It centres on both axes: where the span is the icon itself, being a flex box takes the glyph out of
+ * the reach of the `text-align` the theme centres it with.
+ */
+.help-tooltip-button {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ line-height: 1;
+ color: var(--muted-text-color);
+ cursor: help;
+}
+
+.help-tooltip-button:hover {
+ color: var(--main-text-color);
+}
+
+/* Explanations run to several lines, which Bootstrap's default 200px would stack into a narrow column. */
+.help-tooltip .tooltip-inner {
+ max-width: 320px;
+ text-align: start;
+}
diff --git a/apps/client/src/widgets/react/HelpTooltipButton.tsx b/apps/client/src/widgets/react/HelpTooltipButton.tsx
new file mode 100644
index 0000000000..811e364b88
--- /dev/null
+++ b/apps/client/src/widgets/react/HelpTooltipButton.tsx
@@ -0,0 +1,47 @@
+import "./HelpTooltipButton.css";
+
+import clsx from "clsx";
+import { useRef } from "preact/hooks";
+
+import HelpButton from "./HelpButton";
+import { useStaticTooltip } from "./hooks";
+
+interface HelpTooltipButtonProps {
+ /** The explanation itself, shown on hover. May carry markup, e.g. `<code>` or a list of values. */
+ description: string;
+ /** When set, the button also opens this in-app help page on click. */
+ helpPage?: string;
+ className?: string;
+ /** Where the tooltip goes relative to the button. Above it, by default. */
+ placement?: "top" | "right" | "bottom" | "left";
+}
+
+/**
+ * A help icon explaining on hover whatever it sits beside — for explanations too long to be shown under
+ * a field as a description, or that only some of a set of fields have at all. Where the subject has an
+ * in-app help page of its own, the icon opens it on click.
+ */
+export default function HelpTooltipButton({ description, helpPage, className, placement }: HelpTooltipButtonProps) {
+ const ref = useRef<HTMLSpanElement>(null);
+
+ useStaticTooltip(ref, {
+ title: description,
+ // Explanations carry markup of their own, e.g. <code> or a list of possible values.
+ html: true,
+ placement: placement ?? "top",
+ customClass: "help-tooltip"
+ });
+
+ return (
+ <span
+ ref={ref}
+ class={clsx("help-tooltip-button", className, !helpPage && "icon-action bx bx-help-circle")}
+ // Focusable in its own right only when it holds no button of its own to tab to, so that the
+ // explanation is reachable from the keyboard without doubling up as a second stop.
+ tabIndex={helpPage ? undefined : 0}
+ >
+ {/* Suppressing the button's own title: the explanation is the tooltip here. */}
+ {helpPage && <HelpButton helpPage={helpPage} title="" />}
+ </span>
+ );
+}