Skip to content

Commit fa6bff7

Browse files
committed
feat(pat tooltip): Keep the title attribute for source ajax and content.
The tooltip element's title attribute is only stripped if the source is set to title (the default) and kept otherwise. Fixes: #945
1 parent 321845a commit fa6bff7

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

src/pat/tooltip/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ <h4>source</h4>
141141
<code>source: content</code> and <code>href="#"</code>. Click
142142
the following link to show
143143
<a class="pat-tooltip"
144+
title="This is the title attribute"
144145
data-pat-tooltip="source: content">the same content in the link</a>
145146
inside the tooltip.
146147
</p>
@@ -150,20 +151,23 @@ <h4>source</h4>
150151
show
151152
<a href="#tooltip-source"
152153
class="pat-tooltip"
154+
title="This is the title attribute"
153155
data-pat-tooltip="source: ajax">the content of the element matching the given selector</a>
154156
inside the tooltip.
155157
</p>
156158
<p>
157159
<code>source: ajax</code>. Mouse over the following link to show
158160
<a href="pattern-test-response.html#myTip"
159161
class="pat-tooltip"
162+
title="This is the title attribute"
160163
data-pat-tooltip="source: ajax; trigger: click">the content of pattern-test-response.html#myTip</a>
161164
loaded by ajax inside the tooltip.
162165
</p>
163166
<p>
164167
<code>source: ajax</code>. Click the following link to show
165168
<a href="pattern-test-response.html#myTip"
166169
class="pat-tooltip"
170+
title="This is the title attribute"
167171
data-pat-tooltip="source: ajax; trigger: click">the content of pattern-test-response.html#myTip</a
168172
>
169173
loaded by ajax inside the tooltip.
@@ -173,6 +177,7 @@ <h4>source</h4>
173177
<button
174178
class="pat-tooltip"
175179
type="button"
180+
title="This is the title attribute"
176181
data-pat-tooltip="
177182
source: ajax;
178183
url: pattern-test-response.html#myTip;
@@ -189,6 +194,7 @@ <h4>ajax-data-type</h4>
189194
tooltip with content in markdown
190195
<a href="documentation.md#Display"
191196
class="pat-tooltip"
197+
title="This is the title attribute"
192198
data-pat-tooltip="source: ajax; ajax-data-type: markdown">on click</a>.
193199
</p>
194200

src/pat/tooltip/tooltip.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ export default Base.extend({
9191
Tippy.setDefaultProps(defaultProps);
9292
this.tippy = new Tippy(el, this.tippy_options);
9393

94-
if (el.getAttribute("title")) {
95-
// Remove title attribute to disable browser's built-in tooltip feature
94+
if (this.options.source === "title") {
95+
// Remove ``title`` attribute when source is set to ``title`` to
96+
// disable the browser's built-in tooltip feature
9697
el.removeAttribute("title");
9798
}
9899

src/pat/tooltip/tooltip.test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,4 +1587,47 @@ this will be extracted.
15871587
expect(parts.selector).toBeFalsy();
15881588
});
15891589
});
1590+
1591+
describe("10 - Strip the title attribute ...", () => {
1592+
it("... only if the tooltip has source-title", async () => {
1593+
document.body.innerHTML = `
1594+
<a class="pat-tooltip"
1595+
data-pat-tooltip="source: title"
1596+
title="This is the title attribute"
1597+
>test</a>
1598+
`;
1599+
new pattern(document.querySelector(".pat-tooltip"));
1600+
await utils.timeout(1);
1601+
1602+
expect(document.querySelector(".pat-tooltip").title).toBeFalsy();
1603+
});
1604+
it("... not for source-content", async () => {
1605+
document.body.innerHTML = `
1606+
<a class="pat-tooltip"
1607+
data-pat-tooltip="source: content"
1608+
title="This is the title attribute"
1609+
>test</a>
1610+
`;
1611+
new pattern(document.querySelector(".pat-tooltip"));
1612+
await utils.timeout(1);
1613+
1614+
expect(document.querySelector(".pat-tooltip").title).toBe(
1615+
"This is the title attribute"
1616+
);
1617+
});
1618+
it("... not for source-ajax", async () => {
1619+
document.body.innerHTML = `
1620+
<a class="pat-tooltip"
1621+
data-pat-tooltip="source: ajax"
1622+
title="This is the title attribute"
1623+
>test</a>
1624+
`;
1625+
new pattern(document.querySelector(".pat-tooltip"));
1626+
await utils.timeout(1);
1627+
1628+
expect(document.querySelector(".pat-tooltip").title).toBe(
1629+
"This is the title attribute"
1630+
);
1631+
});
1632+
});
15901633
});

0 commit comments

Comments
 (0)