fluid-ui-svelte 0.1.7 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
2
  import Container from "../primitives/Container.svelte";
3
3
  import Button from "../primitives/Button.svelte";
4
- import type { Snippet } from "svelte";
4
+ import { onMount, type Snippet } from "svelte";
5
5
  import type { DropdownOptions } from "../types.js";
6
6
  let {
7
7
  class: className,
@@ -23,8 +23,8 @@
23
23
  shouldCloseOnClickOutside: boolean;
24
24
  dropdownTrigger: Snippet<[options: { isOpen: boolean; toggleDropdown: Function }]>;
25
25
  dropdownContent: Snippet<[options: { isOpen: boolean; toggleDropdown: Function }]>;
26
- triggerRawElement: HTMLElement;
27
- contentRawElement: HTMLElement;
26
+ triggerRawElement?: HTMLElement;
27
+ contentRawElement?: HTMLElement;
28
28
  } = $props();
29
29
 
30
30
  const componentOptions: DropdownOptions = {
@@ -33,15 +33,18 @@
33
33
  isOpen = !isOpen;
34
34
  },
35
35
  };
36
- if (shouldCloseOnClickOutside) {
37
- document.addEventListener("click", (e) => {
38
- if (isOpen && e.target) {
39
- if (!triggerRawElement.contains(e.target as HTMLElement) && !contentRawElement.contains(e.target as HTMLElement)) {
40
- isOpen = false;
36
+
37
+ onMount(() => {
38
+ if (shouldCloseOnClickOutside) {
39
+ document.addEventListener("click", (e) => {
40
+ if (isOpen && e.target) {
41
+ if (!triggerRawElement!.contains(e.target as HTMLElement) && !contentRawElement!.contains(e.target as HTMLElement)) {
42
+ isOpen = false;
43
+ }
41
44
  }
42
- }
43
- });
44
- }
45
+ });
46
+ }
47
+ });
45
48
  </script>
46
49
 
47
50
  <Container bind:rawElement={triggerRawElement} class={(overrideDefaultStyling ? "" : "fluid-dropdown") + (className ? ` ${className}` : "")} overrideDefaultStyling={true}>
@@ -1,4 +1,4 @@
1
- import type { Snippet } from "svelte";
1
+ import { type Snippet } from "svelte";
2
2
  declare const Dropdown: import("svelte").Component<{
3
3
  class?: string;
4
4
  triggerClass?: string;
@@ -14,7 +14,7 @@ declare const Dropdown: import("svelte").Component<{
14
14
  isOpen: boolean;
15
15
  toggleDropdown: Function;
16
16
  }]>;
17
- triggerRawElement: HTMLElement;
18
- contentRawElement: HTMLElement;
17
+ triggerRawElement?: HTMLElement;
18
+ contentRawElement?: HTMLElement;
19
19
  }, {}, "isOpen">;
20
20
  export default Dropdown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fluid-ui-svelte",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "author": {
5
5
  "name": "Emre Ayaz",
6
6
  "email": "emreayaz@frostium.io",