Skip to content

Build your personal knowledge base with Trilium Notes

client/ui/icon picker: make sure the picker won't overflow the viewport

Adorian Doran75ca7b81758b
diff --git a/apps/client/src/widgets/react/IconPicker.css b/apps/client/src/widgets/react/IconPicker.css
index cb54c1389b..a2efd839bd 100644
--- a/apps/client/src/widgets/react/IconPicker.css
+++ b/apps/client/src/widgets/react/IconPicker.css
@@ -15,8 +15,14 @@
font-weight: bold;
}
+/*
+ * Tall enough to pick from, and never taller than the screen. The menu is placed by Popper, which
+ * keeps it in view by moving it, and can only do that while it is smaller than the view; a grid of
+ * a fixed height hung off a button near an edge is what runs past one. The subtraction leaves room
+ * for the search row above the grid, the menu's own padding, and the button it hangs from.
+ */
.icon-picker .icon-list {
- height: 500px;
+ height: clamp(12rem, 100vh - 8rem, 500px);
overflow: auto;
}
diff --git a/apps/client/src/widgets/react/IconPicker.tsx b/apps/client/src/widgets/react/IconPicker.tsx
index fe91f91879..a7829165a6 100644
--- a/apps/client/src/widgets/react/IconPicker.tsx
+++ b/apps/client/src/widgets/react/IconPicker.tsx
@@ -163,7 +163,20 @@ function IconPickerDropdownButton({
disabled={disabled}
dropdownRef={dropdownRef}
dropdownContainerStyle={{ width: "620px" }}
- dropdownOptions={{ autoClose: "outside" }}
+ dropdownOptions={{
+ autoClose: "outside",
+ // Popper guards only the main axis against overflow, so a menu this tall, hung off
+ // a button with room for it neither above nor below, was left hanging off the
+ // bottom of the screen. Guarding the other axis too slides it back into view; the
+ // side it opens on is still `flip`'s to choose.
+ popperConfig: (defaults) => ({
+ ...defaults,
+ modifiers: [
+ ...(defaults.modifiers ?? []),
+ { name: "preventOverflow", options: { altAxis: true, padding: 8 } }
+ ]
+ })
+ }}
// The menu is wider than some of the places a button stands in, and the inline title
// establishes a backdrop root that would flatten its blur into a tint; hand the menu to
// the page rather than leaving it to be clipped or dulled.