Fix TooltipOnTruncate child target under Vue 3
What does this MR do and why?
TooltipOnTruncate shows a tooltip only when its content overflows. With truncate-target="child", it measures the first child of its root <span>.
The component read this.$el.childNodes[0]. That node is not always an element:
- Under Vue 3, the slot renders as a fragment. The first child node is an empty text node.
- Under both Vue versions, a
v-ifthat renders nothing leaves a comment node.
Text and comment nodes have no scrollWidth. The overflow check returns false. The tooltip never shows. Nothing is logged, so the bug is silent.
This MR changes the lookup to this.$el.firstElementChild. This skips text and comment nodes and returns the slotted element.
About seven components pass truncate-target="child". Examples:
app/assets/javascripts/ci/pipelines_page/components/pipeline_url.vueapp/assets/javascripts/vue_shared/components/commit.vueapp/assets/javascripts/vue_merge_request_widget/components/mr_widget_pipeline.vue
How to set up and validate locally
- Run GDK with
VUE_VERSION=3. - Open a project's pipelines list.
- Make the browser window narrow so a commit title is cut off.
- Hover the commit title. Confirm a tooltip with the full title appears.
Run the spec under both Vue versions:
yarn jest spec/frontend/vue_shared/components/tooltip_on_truncate_spec.js
VUE_VERSION=3 yarn jest spec/frontend/vue_shared/components/tooltip_on_truncate_spec.jsThe new test mounts the component through a real parent template. The slot contains a v-if that renders nothing, followed by a <div>. The test asserts that the overflow check receives the <div> element. With the fix reverted, the test fails under both Vue 2 and Vue 3.
References
- Found while reviewing !251472 (comment 3853520260) (reviewer suggestion in the
firstChildfix formodalKeyboardNavigationMixin) - Same bug pattern as !251210 (merged) (
firstChildinglobal_search.vue)