Skip to content

Build your personal knowledge base with Trilium Notes

fix(client): give an icon standing alone in a button no room to lean on

Elian Doran9289b81c6c2a
diff --git a/apps/client/src/stylesheets/theme-next/forms.css b/apps/client/src/stylesheets/theme-next/forms.css
index 3d08a03e24..5ca14c368f 100644
--- a/apps/client/src/stylesheets/theme-next/forms.css
+++ b/apps/client/src/stylesheets/theme-next/forms.css
@@ -74,6 +74,13 @@ button.btn.btn-success span.tn-icon {
font-size: 1.2em;
}
+/* An icon with no label beside it is the whole of the button, and the spacing above would only push
+ it off centre. A label is a text node, which no selector reaches, so the button says so itself
+ (see `tn-icon-only` in Button.tsx). Written after the rule it undoes, the two weighing the same. */
+button.btn.tn-icon-only span.tn-icon {
+ margin-inline-end: 0;
+}
+
/* Button's keyboard shortcut */
button.btn.btn-primary kbd,
button.btn.btn-secondary kbd,
diff --git a/apps/client/src/widgets/react/Button.tsx b/apps/client/src/widgets/react/Button.tsx
index 0b5420e832..2c7bf45724 100644
--- a/apps/client/src/widgets/react/Button.tsx
+++ b/apps/client/src/widgets/react/Button.tsx
@@ -32,6 +32,12 @@ function Button({ name, buttonRef, className, text, onClick, keyboardShortcut, i
const classes = useMemo(() => {
const classList: string[] = ["btn"];
+ // Said here because a stylesheet cannot see it: the label is a text node, which no selector
+ // reaches, so the spacing meant to part an icon from it has no way of knowing there is none.
+ if (icon && (text === undefined || text === null || text === "")) {
+ classList.push("tn-icon-only");
+ }
+
switch(kind) {
case "primary":
classList.push("btn-primary");
@@ -53,7 +59,7 @@ function Button({ name, buttonRef, className, text, onClick, keyboardShortcut, i
classList.push("btn-micro");
}
return classList.join(" ");
- }, [kind, className, size]);
+ }, [kind, className, size, icon, text]);
// Memoize keyboard shortcut rendering
const shortcutElements = useMemo(() => {