Skip to content

Commit

Permalink
fix(kbadge): fix resize observer helper usage [KHCP-8992]
Browse files Browse the repository at this point in the history
  • Loading branch information
portikM committed Nov 30, 2023
1 parent faae555 commit 4eb0e67
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/components/KBadge/KBadge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@

<script lang="ts">
import type { PropType } from 'vue'
import { ref, computed, onMounted, onBeforeUnmount } from 'vue'
import { ref, computed, onMounted, onUnmounted } from 'vue'
import KButton from '@/components/KButton/KButton.vue'
import KTooltip from '@/components/KTooltip/KTooltip.vue'
import type { BadgeAppearance } from '@/types'
import { BadgeAppearances, BadgeMethodAppearances } from '@/types'
import useUtilities from '@/composables/useUtilities'
import { resizeObserverHelper } from '@/utilities/resizeObserverHelper'
import { ResizeObserverHelper } from '@/utilities/resizeObserverHelper'
const { getSizeFromString } = useUtilities()
Expand Down Expand Up @@ -125,7 +125,7 @@ const isMethodBadge = computed(() => {
const badgeTextElement = ref<HTMLDivElement>()
const resizeObserver = ref()
const resizeObserver = ref<ResizeObserverHelper>()
const isTruncated = ref<boolean>(false)
const badgeCustomStyles = computed(() => {
Expand Down Expand Up @@ -174,18 +174,14 @@ const showTooltip = computed((): boolean => {
})
onMounted(() => {
if (badgeTextElement.value) {
resizeObserver.value = new ResizeObserver(entries => {
resizeObserverHelper(entries, setTruncation)
})
resizeObserver.value = ResizeObserverHelper.create(setTruncation)
resizeObserver.value.observe(badgeTextElement.value as HTMLDivElement)
}
resizeObserver.value.observe(badgeTextElement.value as HTMLDivElement)
})
onBeforeUnmount(() => {
if (badgeTextElement.value) {
resizeObserver.value?.unobserve(badgeTextElement.value)
onUnmounted(() => {
if (resizeObserver.value) {
resizeObserver.value.unobserve(badgeTextElement.value as HTMLDivElement)
}
})
</script>
Expand Down

0 comments on commit 4eb0e67

Please sign in to comment.