|
263 | 263 | }); |
264 | 264 | }); |
265 | 265 |
|
| 266 | + describe('Viewport overflow', () => { |
| 267 | + it('Should show tooltip above button when near viewport bottom', () => { |
| 268 | + editor.destruct(); |
| 269 | + |
| 270 | + // Move the box to the very bottom of the viewport |
| 271 | + box.style.position = 'fixed'; |
| 272 | + box.style.bottom = '0'; |
| 273 | + box.style.left = '0'; |
| 274 | + box.style.right = '0'; |
| 275 | + box.style.minHeight = '60px'; |
| 276 | + box.style.padding = '0'; |
| 277 | + |
| 278 | + editor = getJodit({ |
| 279 | + ...OPTIONS, |
| 280 | + toolbarAdaptive: false |
| 281 | + }); |
| 282 | + |
| 283 | + const boldBtn = getButton('bold', editor); |
| 284 | + expect(boldBtn).is.not.null; |
| 285 | + |
| 286 | + // Mock viewport height to simulate overflow |
| 287 | + const ow = editor.ownerWindow; |
| 288 | + const originalInnerHeight = Object.getOwnPropertyDescriptor( |
| 289 | + HTMLElement.prototype, |
| 290 | + 'clientHeight' |
| 291 | + ); |
| 292 | + const btnRect = |
| 293 | + boldBtn.parentElement.getBoundingClientRect(); |
| 294 | + // Set viewport height so tooltip will overflow below it |
| 295 | + Object.defineProperty(ow, 'innerHeight', { |
| 296 | + value: Math.round(btnRect.bottom + 5), |
| 297 | + configurable: true, |
| 298 | + writable: true |
| 299 | + }); |
| 300 | + |
| 301 | + simulateEvent('mouseenter', boldBtn.parentElement); |
| 302 | + timers.delay(100); |
| 303 | + |
| 304 | + const tooltip = getTooltipElm(); |
| 305 | + expect(tooltip).is.not.null; |
| 306 | + expect(tooltip.textContent).equals('Bold'); |
| 307 | + |
| 308 | + const tooltipRect = tooltip.getBoundingClientRect(); |
| 309 | + |
| 310 | + // Tooltip should be above the button, not below |
| 311 | + expect(tooltipRect.bottom).is.below(btnRect.top + 1); |
| 312 | + |
| 313 | + simulateEvent('mouseleave', boldBtn.parentElement); |
| 314 | + timers.delay(100); |
| 315 | + |
| 316 | + // Restore |
| 317 | + delete ow.innerHeight; |
| 318 | + box.style.position = ''; |
| 319 | + box.style.bottom = ''; |
| 320 | + box.style.left = ''; |
| 321 | + box.style.right = ''; |
| 322 | + }); |
| 323 | + }); |
| 324 | + |
266 | 325 | describe('Inside popup', () => { |
267 | 326 | describe('Hiding popup', () => { |
268 | 327 | it('should hide it tooltip', () => { |
|
0 commit comments