Skip to content

Commit 6cada70

Browse files
author
gjulivan
committed
fix: e2e and styling and icons
1 parent eb9422e commit 6cada70

15 files changed

Lines changed: 123 additions & 105 deletions

File tree

6.05 KB
Loading
6.55 KB
Loading
6.69 KB
Loading

packages/pluggableWidgets/rich-text-web/src/__tests__/__snapshots__/RichText.spec.tsx.snap

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ exports[`Rich Text renders richtext widget with different config 1`] = `
576576
>
577577
<button
578578
class="icon-button"
579-
title="Blockquote"
579+
title="Block quote"
580580
type="button"
581581
>
582582
<span
@@ -661,7 +661,9 @@ exports[`Rich Text renders richtext widget with different config 1`] = `
661661
title="Keyboard shortcuts"
662662
type="button"
663663
>
664-
?
664+
<span
665+
class="icons icon-Help"
666+
/>
665667
</button>
666668
</div>
667669
</div>
Binary file not shown.

packages/pluggableWidgets/rich-text-web/src/components/toolbars/Toolbar.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,14 @@ $rte-shadow-color: #00000014 !default;
8989
.toolbar-dropdown-button {
9090
display: flex;
9191
gap: 4px;
92-
padding: 6px 6px 3px;
92+
padding: 6px 2px 2px 2px;
9393
min-width: 120px;
9494
justify-content: space-between;
9595
background: none;
9696
border: none;
97+
margin: 0 var(--spacing-smallest, 2px);
98+
border-radius: var(--border-radius-s, 4px);
99+
background-color: var(--gray-50, var(--gray-lighter, #f8f8f8));
97100

98101
.dropdown-label {
99102
flex: 1;

packages/pluggableWidgets/rich-text-web/src/components/toolbars/components/Dialog.scss

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,7 @@
106106
}
107107

108108
.image-dialog-entity {
109-
margin-bottom: 12px;
110-
padding: 12px;
111-
border: 1px solid var(--border-color-default, #ced0d3);
112-
border-radius: 4px;
113-
background: #fafafa;
109+
margin: 0 var(--spacing-medium, 16px);
114110
min-height: 100px;
115111
}
116112

packages/pluggableWidgets/rich-text-web/src/components/toolbars/components/HelpButton.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { ToolbarDefaultButton } from "./ToolbarDefaultButton";
44
import { useT } from "../../../utils/i18n";
55

66
/**
7-
* Toolbar help button. Renders a text "?" (the icon font has no help glyph) and
8-
* toggles the keyboard-shortcuts modal.
7+
* Toolbar help button. Renders the help icon and toggles the keyboard-shortcuts
8+
* modal.
99
*/
1010
export function HelpButton(): ReactElement {
1111
const [isOpen, setIsOpen] = useState(false);
@@ -19,10 +19,9 @@ export function HelpButton(): ReactElement {
1919
aria-label={t("help.title")}
2020
aria-haspopup="dialog"
2121
aria-expanded={isOpen}
22+
icon="Help"
2223
onClick={() => setIsOpen(true)}
23-
>
24-
?
25-
</ToolbarDefaultButton>
24+
/>
2625
{isOpen && <HelpDialog onClose={() => setIsOpen(false)} />}
2726
</>
2827
);

packages/pluggableWidgets/rich-text-web/src/components/toolbars/helpers/__tests__/colorPickerHelpers.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,33 @@ describe("colorPickerHelpers.handleColorClear", () => {
108108

109109
expect(editor.getHTML()).not.toContain("<mark");
110110
});
111+
112+
it("renders the text highlight as a span with a background color", () => {
113+
editor = makeEditor();
114+
editor.commands.setContent("<p>hello</p>");
115+
editor.commands.selectAll();
116+
117+
colorPickerHelpers.handleColorChange(editor, "textHighlight", "#ffff00");
118+
119+
const html = editor.getHTML();
120+
expect(html).not.toContain("<mark");
121+
expect(html).toContain("<span");
122+
expect(html).toContain("background-color");
123+
});
124+
125+
it("preserves highlighted text pasted from Microsoft Word", () => {
126+
editor = makeEditor();
127+
// Word emits highlights as spans using the `background` shorthand (never a
128+
// <mark>). The CSSOM expands `background` into `backgroundColor`, so our span
129+
// parser picks it up. A keyword like `yellow` is validated by isSafeCssColor
130+
// via CSS.supports in real browsers; here we use an explicit rgb value so the
131+
// assertion is deterministic under jsdom (which lacks CSS.supports).
132+
editor.commands.setContent(
133+
'<p><span style="background:rgb(255, 255, 0);mso-highlight:yellow">highlighted</span></p>'
134+
);
135+
136+
const html = editor.getHTML();
137+
expect(html).not.toContain("<mark");
138+
expect(html).toContain("background-color");
139+
});
111140
});

packages/pluggableWidgets/rich-text-web/src/extensions/TextHighlightClass.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Extension } from "@tiptap/core";
1+
import { Extension, mergeAttributes } from "@tiptap/core";
22
import { Highlight } from "@tiptap/extension-highlight";
33
import { isSafeCssColor } from "../utils/helpers";
44

@@ -60,6 +60,7 @@ export const TextHighlightClass = Extension.create<TextHighlightClassOptions>({
6060
};
6161
} else {
6262
return {
63+
class: "has-text-highlight",
6364
style: `background-color: ${attributes.color}`
6465
};
6566
}
@@ -70,22 +71,29 @@ export const TextHighlightClass = Extension.create<TextHighlightClassOptions>({
7071
parseHTML() {
7172
return [
7273
{
73-
tag: "mark",
74+
tag: "span",
7475
getAttrs: element => {
7576
const htmlElement = element as HTMLElement;
76-
const hasStyles =
77-
htmlElement.hasAttribute("style") ||
78-
htmlElement.hasAttribute("data-text-highlight") ||
79-
htmlElement.style.backgroundColor;
77+
// Only treat a span as a highlight when it actually carries a
78+
// background (inline mode, incl. Word's `background` shorthand which
79+
// the CSSOM expands into `backgroundColor`) or our data attribute
80+
// (class mode). This avoids capturing color-only text-style spans.
81+
const hasHighlight =
82+
styleDataFormat === "class"
83+
? !!htmlElement.dataset.textHighlight
84+
: !!htmlElement.style.backgroundColor;
8085

81-
if (!hasStyles) {
86+
if (!hasHighlight) {
8287
return false;
8388
}
8489

8590
return {};
8691
}
8792
}
8893
];
94+
},
95+
renderHTML({ HTMLAttributes }) {
96+
return ["span", mergeAttributes(HTMLAttributes), 0];
8997
}
9098
}).configure({
9199
multicolor: this.options.multicolor

0 commit comments

Comments
 (0)