@sierra-95/svelte-scaffold 1.0.22 → 1.0.23

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,4 +1,5 @@
1
1
  <script lang="ts">
2
+ import { tick } from 'svelte';
2
3
  import { browser } from '$app/environment';
3
4
  import { onMount, onDestroy } from 'svelte';
4
5
  import { scale } from 'svelte/transition';
@@ -18,12 +19,15 @@
18
19
 
19
20
  const adjustDropdownPosition = () => {
20
21
  if (!container || !dropdown) return;
22
+
21
23
  const rect = container.getBoundingClientRect();
22
- const dropdownWidth = dropdown.offsetWidth;
23
- const viewportWidth = window.innerWidth;
24
+ const dropdownWidth = dropdown.getBoundingClientRect().width;
25
+ const viewportWidth = document.documentElement.clientWidth;
26
+
27
+ const overflowsRight = rect.left + dropdownWidth > viewportWidth;
28
+ const overflowsLeft = rect.right - dropdownWidth < 0;
24
29
 
25
- // Check if dropdown would overflow right
26
- if (rect.left + dropdownWidth > viewportWidth) {
30
+ if (overflowsRight && !overflowsLeft) {
27
31
  dropdownStyle = { left: 'auto', right: '0' };
28
32
  } else {
29
33
  dropdownStyle = { left: '0', right: 'auto' };
@@ -31,9 +35,12 @@
31
35
  };
32
36
 
33
37
  $effect(() => {
34
- if (open) {
35
- adjustDropdownPosition();
36
- }
38
+ if (!open) return;
39
+ tick().then(() => {
40
+ requestAnimationFrame(() => {
41
+ adjustDropdownPosition();
42
+ });
43
+ });
37
44
  });
38
45
 
39
46
  // Close dropdown on outside click
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sierra-95/svelte-scaffold",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",