Skip to content

Commit 562d291

Browse files
aviu16nivedinjamesgeorge007
authored
fix(common): constrain variable tooltip to viewport for long values (hoppscotch#5878)
Co-authored-by: aviu16 <aviu16@users.noreply.github.com> Co-authored-by: nivedin <nivedinp@gmail.com> Co-authored-by: James George <25279263+jamesgeorge007@users.noreply.github.com>
1 parent c687473 commit 562d291

5 files changed

Lines changed: 661 additions & 32 deletions

File tree

packages/hoppscotch-common/assets/themes/tippy-themes.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@
1616
@apply flex-col;
1717
}
1818

19+
// Constrained tooltip styles to prevent overflow beyond the viewport
20+
// when environment variable values are very long (fixes #5876)
21+
.env-tooltip-constrained {
22+
@apply flex-col;
23+
@apply w-full;
24+
@apply box-border;
25+
@apply overflow-hidden;
26+
27+
.env-tooltip-value {
28+
@apply break-words;
29+
@apply break-all;
30+
@apply whitespace-pre-wrap;
31+
@apply overflow-hidden;
32+
@apply inline-block;
33+
@apply max-w-full;
34+
@apply align-top;
35+
}
36+
}
37+
1938
.tippy-content {
2039
@apply flex;
2140
@apply text-tiny;

packages/hoppscotch-common/src/helpers/editor/extensions/HoppEnvironment.ts

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ import {
4141
ENV_VAR_NAME_REGEX,
4242
HOPP_ENVIRONMENT_REGEX,
4343
} from "~/helpers/environment-regex"
44+
import {
45+
constrainTooltipToViewport,
46+
createTooltipValueRow,
47+
} from "~/helpers/utils/tooltip"
4448

4549
const HOPP_ENV_HIGHLIGHT =
4650
"cursor-help transition rounded px-1 focus:outline-none mx-0.5 env-highlight"
@@ -49,6 +53,8 @@ const HOPP_COLLECTION_ENVIRONMENT_HIGHLIGHT = "collection-variable-highlight"
4953
const HOPP_ENVIRONMENT_HIGHLIGHT = "environment-variable-highlight"
5054
const HOPP_GLOBAL_ENVIRONMENT_HIGHLIGHT = "global-variable-highlight"
5155
const HOPP_ENV_HIGHLIGHT_NOT_FOUND = "environment-not-found-highlight"
56+
// Keep value rows above overlapping CodeMirror decoration layers inside tooltip content.
57+
const TOOLTIP_ENV_CONTAINER_Z_INDEX_CLASS = "!z-[1002]"
5258

5359
const secretEnvironmentService = getService(SecretEnvironmentService)
5460
const currentEnvironmentValueService = getService(CurrentValueService)
@@ -282,36 +288,31 @@ const cursorTooltipField = (aggregateEnvs: AggregateEnvironment[]) =>
282288

283289
const envContainer = document.createElement("div")
284290
tooltipContainer.appendChild(envContainer)
285-
envContainer.className =
286-
"flex flex-col items-start space-y-1 flex-1 w-full mt-2 !z-[1002]"
287-
288-
const initialValueBlock = document.createElement("div")
289-
initialValueBlock.className = "flex items-center space-x-2"
290-
const initialValueTitle = document.createElement("div")
291-
initialValueTitle.textContent = "Initial"
292-
initialValueTitle.className = "font-bold mr-4 "
293-
const initialValue = document.createElement("span")
294-
initialValue.textContent = envInitialValue || ""
295-
initialValueBlock.appendChild(initialValueTitle)
296-
initialValueBlock.appendChild(initialValue)
297-
298-
const currentValueBlock = document.createElement("div")
299-
currentValueBlock.className = "flex items-center space-x-2"
300-
const currentValueTitle = document.createElement("div")
301-
currentValueTitle.textContent = "Current"
302-
currentValueTitle.className = "font-bold mr-1.5"
303-
const currentValue = document.createElement("span")
304-
currentValue.textContent = envCurrentValue || ""
305-
currentValueBlock.appendChild(currentValueTitle)
306-
currentValueBlock.appendChild(currentValue)
307-
308-
envContainer.appendChild(initialValueBlock)
309-
envContainer.appendChild(currentValueBlock)
310-
311-
tooltipContainer.className = "tippy-content env-tooltip-content"
291+
envContainer.className = `flex flex-col items-start space-y-1 flex-1 w-full mt-2 ${TOOLTIP_ENV_CONTAINER_Z_INDEX_CLASS}`
292+
envContainer.style.overflow = "hidden"
293+
294+
// Use createTooltipValueRow for overflow-safe value display
295+
const initialValueRow = createTooltipValueRow(
296+
"Initial",
297+
envInitialValue
298+
)
299+
const currentValueRow = createTooltipValueRow(
300+
"Current",
301+
envCurrentValue
302+
)
303+
304+
envContainer.appendChild(initialValueRow)
305+
envContainer.appendChild(currentValueRow)
306+
307+
tooltipContainer.className =
308+
"tippy-content env-tooltip-content env-tooltip-constrained"
312309
dom.className = "tippy-box"
313310
dom.dataset.theme = "tooltip"
314311
dom.appendChild(tooltipContainer)
312+
313+
// Apply viewport-aware overflow constraints to the tooltip
314+
constrainTooltipToViewport(dom, tooltipContainer)
315+
315316
return { dom }
316317
},
317318
}

packages/hoppscotch-common/src/helpers/editor/extensions/HoppPredefinedVariables.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import { HOPP_SUPPORTED_PREDEFINED_VARIABLES } from "@hoppscotch/data"
99

1010
import IconSquareAsterisk from "~icons/lucide/square-asterisk?raw"
1111
import { isComment } from "./helpers"
12+
import {
13+
constrainTooltipToViewport,
14+
truncateText,
15+
} from "~/helpers/utils/tooltip"
1216

1317
const HOPP_PREDEFINED_VARIABLES_REGEX = /(<<\$[a-zA-Z0-9-_]+>>)/g
1418

@@ -76,7 +80,7 @@ const cursorTooltipField = () =>
7680
const variableIcon = `<span class="inline-flex items-center justify-center my-1">${IconSquareAsterisk}</span>`
7781
const variableDescription =
7882
variable !== undefined
79-
? `${variableName} - ${variable.description}`
83+
? `${variableName} - ${truncateText(variable.description)}`
8084
: `${variableName} is not a valid predefined variable.`
8185

8286
return {
@@ -114,14 +118,18 @@ const cursorTooltipField = () =>
114118
tooltipContainer.appendChild(envContainer)
115119
envContainer.className =
116120
"flex flex-col items-start space-y-1 flex-1 w-full mt-2"
121+
envContainer.style.overflow = "hidden"
117122

118123
const valueBlock = document.createElement("div")
119-
valueBlock.className = "flex items-center space-x-2"
124+
valueBlock.className = "flex items-start space-x-2"
125+
valueBlock.style.width = "100%"
120126
const valueTitle = document.createElement("div")
121127
const value = document.createElement("span")
122-
value.textContent = variableDescription || ""
128+
value.className = "env-tooltip-value"
129+
value.textContent = variableDescription
123130
valueTitle.textContent = "Value"
124-
valueTitle.className = "font-bold mr-4 "
131+
valueTitle.className = "font-bold mr-4"
132+
valueTitle.style.flexShrink = "0"
125133
valueBlock.appendChild(valueTitle)
126134
valueBlock.appendChild(value)
127135

@@ -130,9 +138,14 @@ const cursorTooltipField = () =>
130138
dom.className = "tippy-box"
131139
dom.dataset.theme = "tooltip"
132140

133-
tooltipContainer.className = "tippy-content env-tooltip-content"
141+
tooltipContainer.className =
142+
"tippy-content env-tooltip-content env-tooltip-constrained"
134143

135144
dom.appendChild(tooltipContainer)
145+
146+
// Apply viewport-aware overflow constraints
147+
constrainTooltipToViewport(dom, tooltipContainer)
148+
136149
return { dom }
137150
},
138151
}

0 commit comments

Comments
 (0)