Skip to content

Commit 9075d6e

Browse files
committed
fix(show): fix initial positioning of tooltip using show
1 parent e639d84 commit 9075d6e

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

docs/src/App.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</div>
3030

3131
<div class="example">
32-
<p>This tooltip should appear to the <b use:tooltip={{ content: 'Whoa! I appear to the right.', hideOnClickOutside: true, action: 'click', position: 'right', theme: 'tooltip-theme' }}>right</b> when clicked. It will also hide itself once you click outside of the tooltip.</p>
32+
<p>This tooltip should appear to the <b use:tooltip={{ content: 'Whoa! I appear to the right.', hideOnClickOutside: true, action: 'click', position: 'right', theme: 'tooltip-theme', show: true }}>right</b> when clicked. It will also hide itself once you click outside of the tooltip.</p>
3333

3434
<Prism code={"<b use:tooltip={{ content: 'Whoa! I appear to the right.', position: 'right', action: 'click', theme: 'tooltip-theme' }}>right</b>"} />
3535

@@ -81,7 +81,7 @@
8181
<h2>Examples using component</h2>
8282

8383
<div class="example">
84-
This tooltip should appear on the <Tooltip content="hello world!"><u>top</u></Tooltip> and use the content in the <code>title</code> attribute.
84+
This tooltip should appear on the <Tooltip content="hello world!" action="click" show={!showTooltip}><u>top</u></Tooltip> and use the content in the <code>title</code> attribute.
8585
</div>
8686

8787
<div class="example">

src/action-tooltip.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
$: isComponent = typeof content === 'object';
143143
$: tooltipRef && show
144144
? setTimeout(() => (visible = true), animationDelay)
145-
: (visible = false);
145+
: setTimeout(() => (visible = false), animationDelay);
146146
</script>
147147

148148
{#if content}

src/action.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ export const tooltip = (element, props) => {
5454
if (element !== null) {
5555
removeListeners();
5656

57-
if (config.show) {
58-
onShow();
59-
}
60-
6157
if (action === 'click') {
6258
element.addEventListener('click', onClick);
6359

@@ -90,6 +86,10 @@ export const tooltip = (element, props) => {
9086

9187
addListeners();
9288

89+
if (config.show) {
90+
setTimeout(onShow, 0);
91+
}
92+
9393
return {
9494
destroy() {
9595
removeListeners();

src/tooltip.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220
221221
$: isComponent = typeof content === 'object';
222222
$: action, addListeners();
223-
$: tooltipRef && show ? onShow() : onHide();
223+
$: tooltipRef && show ? setTimeout(onShow, 0) : setTimeout(onHide, 0);
224224
</script>
225225
226226
{#if content}

0 commit comments

Comments
 (0)