noph-ui 0.12.6 → 0.12.7

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.
@@ -23,21 +23,33 @@
23
23
  }
24
24
 
25
25
  const refreshValues = () => {
26
- if (element && anchor && !('anchorName' in document.documentElement.style)) {
27
- const docClientWidth = document.documentElement.clientWidth
26
+ if (element && anchor) {
28
27
  const anchorRect = anchor.getBoundingClientRect()
29
- if (anchorRect.bottom + clientHeight > innerHeight && anchorRect.top - clientHeight > 0) {
30
- element.style.top = `${anchorRect.top - clientHeight - 2}px`
28
+ let maxHeight: number
29
+ if (innerHeight - anchorRect.bottom > anchorRect.top) {
30
+ maxHeight = innerHeight - anchorRect.bottom
31
31
  } else {
32
- element.style.top = `${anchorRect.bottom + 2}px`
32
+ maxHeight = anchorRect.top
33
33
  }
34
- const left = anchorRect.left + anchorRect.width / 2 - clientWidth / 2
35
- if (left < 2) {
36
- element.style.left = '2px'
37
- } else if (left > docClientWidth - clientWidth) {
38
- element.style.left = `${docClientWidth - clientWidth - 4}px`
39
- } else {
40
- element.style.left = `${anchorRect.left + anchorRect.width / 2 - clientWidth / 2}px`
34
+ element.style.maxHeight =
35
+ maxHeight > innerHeight - anchorRect.height
36
+ ? `${innerHeight - anchorRect.height - 20}px`
37
+ : `${maxHeight - 20}px`
38
+ if (!('anchorName' in document.documentElement.style)) {
39
+ const docClientWidth = document.documentElement.clientWidth
40
+ if (anchorRect.bottom + clientHeight > innerHeight && anchorRect.top - clientHeight > 0) {
41
+ element.style.top = `${anchorRect.top - clientHeight - 2}px`
42
+ } else {
43
+ element.style.top = `${anchorRect.bottom + 2}px`
44
+ }
45
+ const left = anchorRect.left + anchorRect.width / 2 - clientWidth / 2
46
+ if (left < 2) {
47
+ element.style.left = '2px'
48
+ } else if (left > docClientWidth - clientWidth) {
49
+ element.style.left = `${docClientWidth - clientWidth - 4}px`
50
+ } else {
51
+ element.style.left = `${anchorRect.left + anchorRect.width / 2 - clientWidth / 2}px`
52
+ }
41
53
  }
42
54
  }
43
55
  }
@@ -45,17 +57,17 @@
45
57
 
46
58
  $effect(() => {
47
59
  if (anchor && element) {
60
+ window.addEventListener(
61
+ 'scroll',
62
+ () => {
63
+ refreshValues()
64
+ },
65
+ { passive: true },
66
+ )
48
67
  if (!('anchorName' in document.documentElement.style)) {
49
68
  anchor.addEventListener('click', () => {
50
69
  refreshValues()
51
70
  })
52
- window.addEventListener(
53
- 'scroll',
54
- () => {
55
- refreshValues()
56
- },
57
- { passive: true },
58
- )
59
71
  } else if (!anchor.style.getPropertyValue('anchor-name')) {
60
72
  const generatedId = `--${crypto.randomUUID()}`
61
73
  element.style.setProperty('position-anchor', generatedId)
@@ -71,22 +83,6 @@
71
83
  bind:this={element}
72
84
  bind:clientWidth
73
85
  bind:clientHeight
74
- ontoggle={(event) => {
75
- const { newState, currentTarget } = event
76
- if (newState === 'open') {
77
- const rect = currentTarget.getBoundingClientRect()
78
- const viewportHeight = innerHeight
79
-
80
- if (rect.bottom > viewportHeight && rect.top < viewportHeight / 2) {
81
- const maxHeight = viewportHeight - rect.top - 18
82
- currentTarget.style.maxHeight = `${maxHeight}px`
83
- }
84
- }
85
- if (newState === 'closed') {
86
- currentTarget.style.maxHeight = '80dvh'
87
- }
88
- attributes.ontoggle?.(event)
89
- }}
90
86
  popover="auto"
91
87
  class={['np-menu', attributes.class]}
92
88
  role="menu"
@@ -105,7 +101,6 @@
105
101
  box-shadow: var(--np-elevation-2);
106
102
  margin: var(--np-menu-margin, 2px);
107
103
  inset: auto;
108
- max-height: 80dvh;
109
104
  scrollbar-color: var(--np-color-on-surface-variant) transparent;
110
105
  scrollbar-width: thin;
111
106
  transition:
@@ -114,7 +109,7 @@
114
109
  opacity: 0;
115
110
  justify-self: var(--np-menu-justify-self, anchor-center);
116
111
  position-area: var(--np-menu-position-area, bottom center);
117
- position-try: normal flip-block;
112
+ position-try: most-height flip-block;
118
113
  }
119
114
 
120
115
  .np-menu:popover-open {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "noph-ui",
3
- "version": "0.12.6",
3
+ "version": "0.12.7",
4
4
  "license": "MIT",
5
5
  "homepage": "https://noph.dev",
6
6
  "repository": {