useUserTaskbarTabLink.ts 626 B

12345678910111213141516171819202122232425262728
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { ref, watch } from 'vue'
  3. type CommonLinkInstance = {
  4. isExactActive: boolean
  5. $el?: HTMLElement
  6. }
  7. export const useUserTaskbarTabLink = (exactActiveCallback?: () => void) => {
  8. const tabLinkInstance = ref<CommonLinkInstance>()
  9. watch(
  10. () => tabLinkInstance.value?.isExactActive,
  11. (isExactActive) => {
  12. if (!isExactActive) return
  13. exactActiveCallback?.()
  14. // Scroll the tab into view when it becomes active.
  15. tabLinkInstance.value?.$el?.scrollIntoView?.()
  16. },
  17. )
  18. return {
  19. tabLinkInstance,
  20. }
  21. }