mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
Merge branch 'master' of https://github.com/carbon-design-system/carbon-components-svelte
This commit is contained in:
commit
0383a2fe40
1 changed files with 21 additions and 7 deletions
|
@ -89,10 +89,19 @@
|
|||
}
|
||||
}
|
||||
|
||||
function openMenu() {
|
||||
function onFocus() {
|
||||
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(() => {
|
||||
if (open) {
|
||||
const button = ref.getBoundingClientRect();
|
||||
|
@ -173,8 +182,13 @@
|
|||
ref.focus();
|
||||
}
|
||||
}
|
||||
|
||||
open = false;
|
||||
}
|
||||
}}"
|
||||
on:click|capture="{({ target }) => {
|
||||
if (open && !ref.contains(target) && !refTooltip.contains(target)) {
|
||||
setTimeout(() => {
|
||||
open = false;
|
||||
});
|
||||
}
|
||||
}}"
|
||||
/>
|
||||
|
@ -190,8 +204,8 @@
|
|||
bind:this="{refIcon}"
|
||||
{...buttonProps}
|
||||
aria-describedby="{tooltipId}"
|
||||
on:click|preventDefault|stopPropagation="{openMenu}"
|
||||
on:focus="{openMenu}"
|
||||
on:mousedown="{onMousedown}"
|
||||
on:focus="{onFocus}"
|
||||
on:blur="{onBlur}"
|
||||
on:keydown="{onKeydown}"
|
||||
>
|
||||
|
@ -205,8 +219,8 @@
|
|||
bind:this="{ref}"
|
||||
{...buttonProps}
|
||||
aria-describedby="{tooltipId}"
|
||||
on:click|preventDefault|stopPropagation="{openMenu}"
|
||||
on:focus="{openMenu}"
|
||||
on:mousedown="{onMousedown}"
|
||||
on:focus="{onFocus}"
|
||||
on:blur="{onBlur}"
|
||||
on:keydown="{onKeydown}"
|
||||
>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue