noph-ui 0.12.7 → 0.12.8

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.
@@ -55,20 +55,44 @@
55
55
  }
56
56
  $effect(refreshValues)
57
57
 
58
+ const getScrollableParent = (start: HTMLElement) => {
59
+ let element: HTMLElement | null = start
60
+ while (element) {
61
+ const style = getComputedStyle(element)
62
+ const overflowY = style.overflowY
63
+ const overflowX = style.overflowX
64
+ const isScrollableY =
65
+ (overflowY === 'auto' || overflowY === 'scroll') &&
66
+ element.scrollHeight > element.clientHeight
67
+ const isScrollableX =
68
+ (overflowX === 'auto' || overflowX === 'scroll') &&
69
+ element.scrollWidth > element.clientWidth
70
+
71
+ if (isScrollableY || isScrollableX) {
72
+ return element
73
+ }
74
+
75
+ element = element.parentElement
76
+ }
77
+ return window
78
+ }
79
+
58
80
  $effect(() => {
59
81
  if (anchor && element) {
60
- window.addEventListener(
82
+ getScrollableParent(element).addEventListener(
61
83
  'scroll',
62
84
  () => {
63
85
  refreshValues()
64
86
  },
65
87
  { passive: true },
66
88
  )
67
- if (!('anchorName' in document.documentElement.style)) {
68
- anchor.addEventListener('click', () => {
69
- refreshValues()
70
- })
71
- } else if (!anchor.style.getPropertyValue('anchor-name')) {
89
+ anchor.addEventListener('click', () => {
90
+ refreshValues()
91
+ })
92
+ if (
93
+ 'anchorName' in document.documentElement.style &&
94
+ !anchor.style.getPropertyValue('anchor-name')
95
+ ) {
72
96
  const generatedId = `--${crypto.randomUUID()}`
73
97
  element.style.setProperty('position-anchor', generatedId)
74
98
  anchor.style.setProperty('anchor-name', generatedId)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "noph-ui",
3
- "version": "0.12.7",
3
+ "version": "0.12.8",
4
4
  "license": "MIT",
5
5
  "homepage": "https://noph.dev",
6
6
  "repository": {