Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

saved_snippets: Dynamically calculate tooltip offset.

sandeepba6712a5231d
diff --git a/web/src/saved_snippets_ui.ts b/web/src/saved_snippets_ui.ts
index f6f6bb1f231..a981e634fc0 100644
--- a/web/src/saved_snippets_ui.ts
+++ b/web/src/saved_snippets_ui.ts
@@ -230,12 +230,13 @@ export function setup_saved_snippets_dropdown_widget(widget_selector: string): v
on_exit_with_escape_callback: () => get_dropdown_target_textarea()?.trigger("focus"),
focus_target_on_hidden: false,
prefer_top_start_placement: true,
- tippy_props: {
- // Using -100 as x offset makes saved snippet icon be in the center
- // of the dropdown widget and 5 as y offset is what we use in compose
- // recipient dropdown widget.
- offset: [-100, 5],
+ on_mount_callback(instance: tippy.Instance) {
+ const ref_rect = instance.reference.getBoundingClientRect();
+ const popper_rect = instance.popper.getBoundingClientRect();
+ const x_offset = -(popper_rect.width / 2 - ref_rect.width / 2);
+ instance.setProps({offset: [x_offset, 5]});
},
+ tippy_props: {},
});
saved_snippets_widget.setup();
}