Skip to content

Commit 7a6cdd7

Browse files
fix: remove sdt hover in view mode (#2560)
* fix: remove sdt hover in view mode * test(behavior): add regression tests for SDT hover in viewing mode (SD-2232) Verify that hovering block and inline SDT containers in viewing mode does not show background highlights. Covers both standard and lock-mode hover paths across Chromium, Firefox, and WebKit. --------- Co-authored-by: Caio Pizzol <caio@harbourshare.com>
1 parent c1d6397 commit 7a6cdd7

3 files changed

Lines changed: 85 additions & 1 deletion

File tree

packages/layout-engine/painters/dom/src/styles.test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest';
2-
import { ensureNativeSelectionStyles } from './styles.js';
2+
import { ensureNativeSelectionStyles, ensureSdtContainerStyles } from './styles.js';
33

44
/**
55
* Tests for style injection functions.
@@ -111,3 +111,22 @@ describe('ensureNativeSelectionStyles', () => {
111111
expect(document.head.contains(styleEl)).toBe(true);
112112
});
113113
});
114+
115+
describe('ensureSdtContainerStyles', () => {
116+
it('suppresses structured-content hover backgrounds in viewing mode, including grouped hover', () => {
117+
ensureSdtContainerStyles(document);
118+
119+
const styleEl = document.querySelector('[data-superdoc-sdt-container-styles="true"]');
120+
const cssText = styleEl?.textContent ?? '';
121+
122+
expect(cssText).toContain('.presentation-editor--viewing .superdoc-structured-content-block.sdt-group-hover');
123+
expect(cssText).toContain('.presentation-editor--viewing .superdoc-structured-content-block.sdt-hover');
124+
expect(cssText).toContain(
125+
'.presentation-editor--viewing .superdoc-structured-content-block[data-lock-mode].sdt-hover',
126+
);
127+
expect(cssText).toContain(
128+
'.presentation-editor--viewing .superdoc-structured-content-inline[data-lock-mode]:hover',
129+
);
130+
expect(cssText).toContain('background: none;');
131+
});
132+
});

packages/layout-engine/painters/dom/src/styles.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,23 @@ const SDT_CONTAINER_STYLES = `
544544
border: none;
545545
}
546546
547+
.presentation-editor--viewing .superdoc-structured-content-block.sdt-group-hover,
548+
.presentation-editor--viewing .superdoc-structured-content-block.sdt-hover,
549+
.presentation-editor--viewing .superdoc-structured-content-block[data-lock-mode].sdt-hover {
550+
background: none;
551+
border: none;
552+
}
553+
547554
.presentation-editor--viewing .superdoc-structured-content-inline:hover {
548555
background: none;
549556
border: none;
550557
}
551558
559+
.presentation-editor--viewing .superdoc-structured-content-inline[data-lock-mode]:hover {
560+
background: none;
561+
border: none;
562+
}
563+
552564
.presentation-editor--viewing .superdoc-structured-content__label,
553565
.presentation-editor--viewing .superdoc-structured-content-inline__label {
554566
display: none !important;

tests/behavior/tests/sdt/structured-content.spec.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,59 @@ test.describe('viewing mode hides SDT affordances', () => {
271271

272272
await superdoc.snapshot('inline SDT viewing mode');
273273
});
274+
275+
test('block SDT hover does not show background in viewing mode (SD-2232)', async ({ superdoc }) => {
276+
await superdoc.type('Some text');
277+
await superdoc.newLine();
278+
await superdoc.waitForStable();
279+
await insertBlockSdt(superdoc.page, 'Hover Block', 'Content');
280+
await superdoc.waitForStable();
281+
282+
await superdoc.setDocumentMode('viewing');
283+
await superdoc.waitForStable();
284+
285+
// Move mouse over the block SDT
286+
const center = await getCenter(superdoc.page, BLOCK_SDT);
287+
await superdoc.page.mouse.move(center.x, center.y);
288+
await superdoc.waitForStable();
289+
290+
// Even if the sdt-hover class gets applied, the CSS override should
291+
// suppress any visible background in viewing mode.
292+
const bg = await superdoc.page.evaluate((sel) => {
293+
const el = document.querySelector(sel);
294+
if (!el) return null;
295+
return getComputedStyle(el).backgroundColor;
296+
}, BLOCK_SDT);
297+
298+
expect(bg === 'rgba(0, 0, 0, 0)' || bg === 'transparent').toBe(true);
299+
300+
await superdoc.snapshot('block SDT hover suppressed in viewing mode');
301+
});
302+
303+
test('inline SDT hover does not show background in viewing mode (SD-2232)', async ({ superdoc }) => {
304+
await superdoc.type('Hello ');
305+
await superdoc.waitForStable();
306+
await insertInlineSdt(superdoc.page, 'Hover Inline', 'value');
307+
await superdoc.waitForStable();
308+
309+
await superdoc.setDocumentMode('viewing');
310+
await superdoc.waitForStable();
311+
312+
// Move mouse over the inline SDT
313+
const center = await getCenter(superdoc.page, INLINE_SDT);
314+
await superdoc.page.mouse.move(center.x, center.y);
315+
await superdoc.waitForStable();
316+
317+
const bg = await superdoc.page.evaluate((sel) => {
318+
const el = document.querySelector(sel);
319+
if (!el) return null;
320+
return getComputedStyle(el).backgroundColor;
321+
}, INLINE_SDT);
322+
323+
expect(bg === 'rgba(0, 0, 0, 0)' || bg === 'transparent').toBe(true);
324+
325+
await superdoc.snapshot('inline SDT hover suppressed in viewing mode');
326+
});
274327
});
275328

276329
// ==========================================================================

0 commit comments

Comments
 (0)