Skip to content

Commit 2139b02

Browse files
authored
Merge pull request #2119 from Parvinmh/title_renderAsHtml_parvin
Title render as html
2 parents 3471c05 + 5aa003f commit 2139b02

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

example/html-tooltip/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ <h4>Section Six</h4>
7575
intro.setOptions({
7676
steps: [
7777
{
78+
title: '<p>Welcome</p>',
7879
element: '#step1',
7980
intro: "This is a <b>bold</b> tooltip."
8081
},
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Header } from "./TourTooltip";
2+
3+
describe("Header", () => {
4+
it("renders plain text title when renderAsHtml is false", () => {
5+
const el = Header({
6+
title: "<strong>Bold Text</strong>",
7+
skipLabel: "Skip",
8+
renderAsHtml: false,
9+
onSkipClick: jest.fn(),
10+
});
11+
12+
const h1 = el.querySelector("h1")!;
13+
14+
expect(h1.innerHTML).toBe(
15+
'<div class="introjs-tooltiptext">&lt;strong&gt;Bold Text&lt;/strong&gt;'
16+
);
17+
expect(h1.querySelector("strong")).toBeNull();
18+
});
19+
20+
it("renders HTML title when renderAsHtml is true", () => {
21+
const el = Header({
22+
title: "<strong>Bold Text</strong>",
23+
skipLabel: "Skip",
24+
renderAsHtml: true,
25+
onSkipClick: jest.fn(),
26+
});
27+
28+
const h1 = el.querySelector("h1")!;
29+
30+
expect(h1.innerHTML).toBe(
31+
'<div class="introjs-tooltiptext"><strong>Bold Text</strong>'
32+
);
33+
expect(h1.querySelector("strong")?.textContent).toBe("Bold Text");
34+
});
35+
});

src/packages/tour/components/TourTooltip.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,19 +326,24 @@ const Buttons = ({
326326
);
327327
};
328328

329-
const Header = ({
329+
export const Header = ({
330330
title,
331-
332331
skipLabel,
332+
renderAsHtml,
333333
onSkipClick,
334334
}: {
335335
title: string;
336-
337336
skipLabel: string;
337+
renderAsHtml?: boolean;
338338
onSkipClick: (e: any) => void;
339339
}) => {
340+
const titleEl = TooltipContent({
341+
text: title,
342+
tooltipRenderAsHtml: renderAsHtml,
343+
className: tooltipTextClassName,
344+
});
340345
return div({ className: tooltipHeaderClassName }, [
341-
h1({ className: tooltipTitleClassName }, title),
346+
h1({ className: tooltipTitleClassName }, titleEl),
342347
Button({
343348
className: skipButtonClassName,
344349
label: skipLabel,
@@ -452,7 +457,7 @@ export const TourTooltip = ({
452457
const text = step.intro;
453458
const position = step.position;
454459

455-
children.push(Header({ title, skipLabel, onSkipClick }));
460+
children.push(Header({ title, skipLabel, renderAsHtml, onSkipClick }));
456461

457462
children.push(
458463
TooltipContent({

0 commit comments

Comments
 (0)