mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-20 20:33:02 +00:00
fix(ToolTip): better toggling logic
This commit is contained in:
parent
07655aed3e
commit
0f2ad1abaf
1 changed files with 15 additions and 6 deletions
|
@ -89,10 +89,19 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function openMenu() {
|
function onFocus() {
|
||||||
open = true;
|
open = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onMousedown() {
|
||||||
|
// determine the desired state before the focus event triggers.
|
||||||
|
const shouldClose = open;
|
||||||
|
// ensure changes are scheduled at the end, i.e. after the possible focus event.
|
||||||
|
setTimeout(() => {
|
||||||
|
open = shouldClose ? false : true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
afterUpdate(() => {
|
afterUpdate(() => {
|
||||||
if (open) {
|
if (open) {
|
||||||
const button = ref.getBoundingClientRect();
|
const button = ref.getBoundingClientRect();
|
||||||
|
@ -174,7 +183,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open = false;
|
if (!ref.contains(target)) open = false;
|
||||||
}
|
}
|
||||||
}}"
|
}}"
|
||||||
/>
|
/>
|
||||||
|
@ -190,8 +199,8 @@
|
||||||
bind:this="{refIcon}"
|
bind:this="{refIcon}"
|
||||||
{...buttonProps}
|
{...buttonProps}
|
||||||
aria-describedby="{tooltipId}"
|
aria-describedby="{tooltipId}"
|
||||||
on:click|preventDefault|stopPropagation="{openMenu}"
|
on:mousedown="{onMousedown}"
|
||||||
on:focus="{openMenu}"
|
on:focus="{onFocus}"
|
||||||
on:blur="{onBlur}"
|
on:blur="{onBlur}"
|
||||||
on:keydown="{onKeydown}"
|
on:keydown="{onKeydown}"
|
||||||
>
|
>
|
||||||
|
@ -205,8 +214,8 @@
|
||||||
bind:this="{ref}"
|
bind:this="{ref}"
|
||||||
{...buttonProps}
|
{...buttonProps}
|
||||||
aria-describedby="{tooltipId}"
|
aria-describedby="{tooltipId}"
|
||||||
on:click|preventDefault|stopPropagation="{openMenu}"
|
on:mousedown="{onMousedown}"
|
||||||
on:focus="{openMenu}"
|
on:focus="{onFocus}"
|
||||||
on:blur="{onBlur}"
|
on:blur="{onBlur}"
|
||||||
on:keydown="{onKeydown}"
|
on:keydown="{onKeydown}"
|
||||||
>
|
>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue