@eturnity/eturnity_reusable_components 8.7.5 → 8.7.6

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eturnity/eturnity_reusable_components",
3
- "version": "8.7.5",
3
+ "version": "8.7.6",
4
4
  "files": [
5
5
  "dist",
6
6
  "src"
@@ -141,10 +141,13 @@
141
141
  <SelectDropdown
142
142
  v-show="isSelectDropdownShown"
143
143
  ref="dropdown"
144
+ :style="{
145
+ transform: `translate(${dropdownPosition?.left}px, ${
146
+ noRelative ? 'auto' : `${dropdownPosition?.top}px`
147
+ })`,
148
+ }"
144
149
  :bg-color="
145
- dropdownBgColor ||
146
- colorMode == 'dark' ||
147
- colorMode == 'transparent'
150
+ colorMode == 'dark' || colorMode == 'transparent'
148
151
  ? 'black'
149
152
  : 'white'
150
153
  "
@@ -397,9 +400,8 @@
397
400
  box-sizing: border-box;
398
401
  z-index: ${(props) => (props.isActive ? '2' : '99999')};
399
402
  position: absolute;
400
- top: ${(props) =>
401
- props.noRelative ? 'auto' : props.dropdownPosition?.top + 'px'};
402
- left: ${(props) => props.dropdownPosition?.left}px;
403
+ top: 0px;
404
+ left: 0px;
403
405
  border: ${BORDER_WIDTH} solid ${(props) => props.theme.colors.grey4};
404
406
  border-radius: 4px;
405
407
  display: flex;
@@ -664,6 +666,10 @@
664
666
  },
665
667
  dropdownWidth: null,
666
668
  hoveredValue: null,
669
+ isDisplayedAtBottom: true,
670
+ selectTopPosition: 0,
671
+ selectAndDropdownDistance: 0,
672
+ animationFrameId: null,
667
673
  }
668
674
  },
669
675
  computed: {
@@ -734,8 +740,13 @@
734
740
  }, 10)
735
741
  await this.$nextTick()
736
742
  this.handleSetDropdownOffet()
743
+ this.calculateSelectTopPosition()
737
744
  } else {
738
745
  this.dropdownPosition.left = null
746
+ if (this.animationFrameId) {
747
+ cancelAnimationFrame(this.animationFrameId)
748
+ this.animationFrameId = null
749
+ }
739
750
  setTimeout(() => {
740
751
  this.isClickOutsideActive = false
741
752
  }, 10)
@@ -748,11 +759,27 @@
748
759
  })
749
760
  }
750
761
  },
762
+ isSelectDropdownShown(isShown) {
763
+ if (!isShown) return
764
+
765
+ // Need to wait for 1ms to make sure the dropdown menu is shown in the DOM
766
+ // before getting the distance between the select and the dropdown menu
767
+ setTimeout(() => {
768
+ this.getDistanceBetweenSelectAndDropdownMenu()
769
+ }, 100)
770
+ },
771
+ selectTopPosition() {
772
+ this.dropdownPosition.top =
773
+ this.selectTopPosition +
774
+ this.$refs.select.$el.clientHeight +
775
+ this.selectAndDropdownDistance
776
+ },
751
777
  },
752
778
  mounted() {
753
779
  this.observeDropdownHeight()
754
780
  this.observeSelectWidth()
755
781
  window.addEventListener('resize', this.handleSetDropdownOffet)
782
+ document.body.addEventListener('scroll', this.calculateSelectTopPosition)
756
783
  },
757
784
  beforeMount() {
758
785
  this.selectedValue = this.value
@@ -761,6 +788,10 @@
761
788
  window.removeEventListener('resize', this.handleSetDropdownOffet)
762
789
  if (this.dropdownResizeObserver) this.dropdownResizeObserver.disconnect()
763
790
  if (this.selectResizeObserver) this.selectResizeObserver.disconnect()
791
+ document.body.removeEventListener(
792
+ 'scroll',
793
+ this.calculateSelectTopPosition
794
+ )
764
795
  },
765
796
  unmounted() {
766
797
  document.removeEventListener('click', this.clickOutside)
@@ -866,11 +897,11 @@
866
897
  return
867
898
  }
868
899
  await this.$nextTick()
869
- const isDisplayedAtBottom = await this.generateDropdownPosition()
900
+ this.isDisplayedAtBottom = await this.generateDropdownPosition()
870
901
  // If the dropdown menu is going to be displayed at the bottom,
871
902
  // we need reverify its position after a dom update (nextTick)
872
903
  await this.$nextTick()
873
- if (isDisplayedAtBottom) this.generateDropdownPosition()
904
+ if (this.isDisplayedAtBottom) this.generateDropdownPosition()
874
905
  },
875
906
  async generateDropdownPosition() {
876
907
  const isDropdownNotCompletelyVisible =
@@ -963,6 +994,25 @@
963
994
  }
964
995
  }
965
996
  },
997
+ getDistanceBetweenSelectAndDropdownMenu() {
998
+ const wholeSelectTopPosition =
999
+ this.selectTopPosition + this.$refs.select.$el.clientHeight
1000
+ this.selectAndDropdownDistance =
1001
+ this.dropdownPosition.top - wholeSelectTopPosition
1002
+ },
1003
+ calculateSelectTopPosition() {
1004
+ const selectRef = this.$refs.select
1005
+ if (selectRef) {
1006
+ const currentTopPosition =
1007
+ selectRef.$el.getBoundingClientRect().top + window.scrollY
1008
+ if (this.selectTopPosition !== currentTopPosition) {
1009
+ this.selectTopPosition = currentTopPosition
1010
+ }
1011
+ }
1012
+ this.animationFrameId = requestAnimationFrame(
1013
+ this.calculateSelectTopPosition
1014
+ )
1015
+ },
966
1016
  },
967
1017
  }
968
1018
  </script>