Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui-components): Update tab underline width on content change #3500

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions packages/ui-components/src/components/layout/tabs/Horizontal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,22 @@ import { isClient } from '@vueuse/core'
import { ArrowLongRightIcon, ArrowLongLeftIcon } from '@heroicons/vue/24/outline'
import type { Nullable } from '@speckle/shared'
import { throttle } from '#lodash'
import { useElementSize } from '@vueuse/core'

const props = defineProps<{
items: LayoutPageTabItem[]
}>()

const activeItem = defineModel<LayoutPageTabItem>('activeItem', { required: true })

const buttonContainer = ref(null as Nullable<HTMLDivElement>)
const scrollContainer = ref<HTMLElement | null>(null)
const showLeftArrow = ref(false)
const showRightArrow = ref(false)
const isInitialSetup = ref(true)

const { width } = useElementSize(buttonContainer)

const buttonClass = computed(() => {
return (item: LayoutPageTabItem) => {
const isActive = activeItem.value?.id === item.id
Expand Down Expand Up @@ -148,11 +152,16 @@ const activeItemRef = computed(() => {
})

const borderStyle = computed<CSSProperties>(() => {
const element = activeItemRef.value
return {
left: `${element?.offsetLeft || 0}px`,
width: `${element?.clientWidth || 0}px`
}
// Using width in calculation to force dependency
return width.value
? {
left: `${activeItemRef.value?.offsetLeft || 0}px`,
width: `${activeItemRef.value?.clientWidth || 0}px`
}
: {
left: '0px',
width: '0px'
}
})

const setActiveItem = (item: LayoutPageTabItem) => {
Expand Down