mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 11:36:36 +00:00
use theetrain
requested change with
`svelte:window` instead of `mousedown` and `blur`
This commit is contained in:
parent
6b84b51238
commit
4d8a32b719
2 changed files with 16 additions and 4 deletions
|
@ -98,7 +98,7 @@
|
|||
/** Obtain a reference to the button HTML element */
|
||||
export let ref = null;
|
||||
|
||||
import { createEventDispatcher } from "svelte";
|
||||
import { createEventDispatcher, onMount } from "svelte";
|
||||
import WarningFilled from "../icons/WarningFilled.svelte";
|
||||
import WarningAltFilled from "../icons/WarningAltFilled.svelte";
|
||||
import {
|
||||
|
@ -148,8 +148,22 @@
|
|||
const dispatchSelect = () => {
|
||||
dispatch("select", { selectedId, selectedItem });
|
||||
};
|
||||
|
||||
const pageClickHandler = ({ target }) => {
|
||||
if (open && ref && !ref.contains(target)) {
|
||||
open = false;
|
||||
}
|
||||
};
|
||||
|
||||
onMount(() => {
|
||||
if (parent) {
|
||||
parent.addEventListener("click", pageClickHandler);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:window on:click="{pageClickHandler}" />
|
||||
|
||||
<div
|
||||
class:bx--dropdown__wrapper="{true}"
|
||||
class:bx--list-box__wrapper="{true}"
|
||||
|
@ -237,7 +251,6 @@
|
|||
open = false;
|
||||
}
|
||||
}}"
|
||||
on:blur="{() => (open = false)}"
|
||||
on:keyup="{(e) => {
|
||||
const { key } = e;
|
||||
if ([' '].includes(key)) {
|
||||
|
@ -281,7 +294,7 @@
|
|||
active="{selectedId === item.id}"
|
||||
highlighted="{highlightedIndex === i}"
|
||||
disabled="{item.disabled}"
|
||||
on:mousedown="{(e) => {
|
||||
on:click="{(e) => {
|
||||
if (item.disabled) {
|
||||
e.stopPropagation();
|
||||
return;
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
disabled="{disabled ? true : undefined}"
|
||||
{...$$restProps}
|
||||
on:click
|
||||
on:mousedown
|
||||
on:mouseenter
|
||||
on:mouseleave
|
||||
>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue