@volverjs/ui-vue 0.0.8-beta.11 → 0.0.8-beta.12

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.
@@ -578,7 +578,7 @@
578
578
  <slot name="dropdown::after">
579
579
  <!-- Close button if dropdown custom position is enabled and floating-ui disabled -->
580
580
  <VvButton
581
- v-if="dropdownEl?.dropdownCustomPosition === 'true'"
581
+ v-if="dropdownEl?.customPosition"
582
582
  label="Close"
583
583
  modifiers="secondary"
584
584
  @click="dropdownEl.hide()"
@@ -54,22 +54,24 @@
54
54
  })
55
55
 
56
56
  // ref to store the value of css-var "--dropdown-custom-position"
57
- const dropdownCustomPosition = ref()
58
-
59
- // set dropdownCustomPosition value from css-var "--dropdown-custom-position"
60
- const onChangeDropdownCustomPosition = () => {
61
- dropdownCustomPosition.value = window
62
- .getComputedStyle(floatingEl.value)
63
- .getPropertyValue('--dropdown-custom-position')
64
- ?.trim()
65
- }
57
+ const hasCustomPosition = ref(false)
66
58
 
67
59
  // observe dropdown style for "--dropdown-custom-position" css var to disable floating-ui
68
60
  onMounted(() => {
69
- useMutationObserver(floatingEl.value, onChangeDropdownCustomPosition, {
70
- attributeFilter: ['style'],
71
- window,
72
- })
61
+ useMutationObserver(
62
+ floatingEl.value,
63
+ () => {
64
+ hasCustomPosition.value =
65
+ window
66
+ .getComputedStyle(floatingEl.value)
67
+ .getPropertyValue('--dropdown-custom-position')
68
+ ?.trim() === 'true'
69
+ },
70
+ {
71
+ attributeFilter: ['style'],
72
+ window,
73
+ },
74
+ )
73
75
  })
74
76
 
75
77
  // floating ui
@@ -158,8 +160,8 @@
158
160
  },
159
161
  )
160
162
  const dropdownPlacement = computed(() => {
161
- if (dropdownCustomPosition?.value === 'true') {
162
- return {}
163
+ if (hasCustomPosition.value) {
164
+ return undefined
163
165
  }
164
166
  return {
165
167
  position: strategy.value,
@@ -175,31 +177,34 @@
175
177
  })
176
178
 
177
179
  // placement
178
- const side = computed(() => placement.value.split('-')[0])
179
- const staticSide = computed(
180
+ const side = computed(
180
181
  () =>
181
- ({
182
- top: 'bottom',
183
- right: 'left',
184
- bottom: 'top',
185
- left: 'right',
186
- }[side.value] ?? 'bottom'),
182
+ placement.value.split('-')[0] as
183
+ | 'top'
184
+ | 'right'
185
+ | 'bottom'
186
+ | 'left',
187
187
  )
188
188
  const arrowPlacement = computed(() => {
189
- if (dropdownCustomPosition?.value === 'true') {
190
- return {}
191
- }
192
- if (['bottom', 'top'].includes(staticSide.value)) {
193
- return {
194
- right: `${middlewareData.value.arrow?.x ?? 0}px`,
195
- [staticSide.value]: `${
196
- -(arrowEl.value?.offsetWidth ?? 0) / 2
197
- }px`,
198
- }
189
+ if (hasCustomPosition.value) {
190
+ return undefined
199
191
  }
192
+ const staticSide = {
193
+ top: 'bottom',
194
+ right: 'left',
195
+ bottom: 'top',
196
+ left: 'right',
197
+ }[side.value]
200
198
  return {
201
- top: `${middlewareData.value.arrow?.y ?? 0}px`,
202
- [staticSide.value]: `${-(arrowEl.value?.offsetWidth ?? 0) / 2}px`,
199
+ left:
200
+ middlewareData.value.arrow?.x !== undefined
201
+ ? `${middlewareData.value.arrow?.x}px`
202
+ : undefined,
203
+ top:
204
+ middlewareData.value.arrow?.y !== undefined
205
+ ? `${middlewareData.value.arrow?.y}px`
206
+ : undefined,
207
+ [staticSide]: `${-(arrowEl.value?.offsetWidth ?? 0) / 2}px`,
203
208
  }
204
209
  })
205
210
 
@@ -228,7 +233,13 @@
228
233
  const init = (el: HTMLElement) => {
229
234
  referenceEl.value = el
230
235
  }
231
- defineExpose({ toggle, show, hide, init, dropdownCustomPosition })
236
+ defineExpose({
237
+ toggle,
238
+ show,
239
+ hide,
240
+ init,
241
+ customPosition: hasCustomPosition,
242
+ })
232
243
  watch(expanded, (newValue) => {
233
244
  if (newValue && props.autofocusFirst) {
234
245
  nextTick(() => {