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(VTooltip): display intrinsic maximum width content #16350

Closed
wants to merge 1 commit into from

Conversation

yuwu9145
Copy link
Member

@yuwu9145 yuwu9145 commented Dec 30, 2022

fixes #16321

Cause: offsetWidth & offsetHeight returns different values between first activate and second activate.

  • When hover the first time, text displays as one line, everything calculates correctly
  • Due to contentBox.x -= parseFloat(el.style.left || 0). when hover from the second time and afterwards, contentBox will be initially rendered outside page and tooltip overlay initially shows as two lines so offsetWidth & offsetHeight returns inconsistent values

Solution so far:

display intrinsic maximum width content

Description

Motivation and Context

How Has This Been Tested?

Markup:

// Paste your FULL Playground.vue here
<script setup>
import { ref } from 'vue'

const show = ref(false);

</script>

<template>
  <v-app class="pa-4">
    <v-container
      fluid
      class="text-center"
    >
      <v-row
        class="flex"
        justify="space-between"
      >
        <v-col cols="12">
          <v-btn @click="show = !show">
            toggle
          </v-btn>
        </v-col>
  
        <v-col
          cols="12"
          class="mt-12"
        >
          <v-tooltip
            v-model="show"
            location="top"
          >
            <template v-slot:activator="{ props }">
              <v-btn
                icon
                v-bind="props"
              >
                <v-icon color="grey-lighten-1">
                  mdi-cart
                </v-icon>
              </v-btn>
            </template>
            <span>Programmatic tooltip</span>
          </v-tooltip>
        </v-col>
      </v-row>
    </v-container>
  </v-app>
</template>

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Improvement/refactoring (non-breaking change that doesn't add any features but makes things better)

Checklist:

  • The PR title is no longer than 64 characters.
  • The PR is submitted to the correct branch (master for bug fixes and documentation updates, dev for new features and backwards compatible changes and next for non-backwards compatible changes).
  • My code follows the code style of this project.
  • I've added relevant changes to the documentation (applies to new features and breaking changes in core library)

@yuwu9145 yuwu9145 marked this pull request as draft December 30, 2022 22:23
@yuwu9145 yuwu9145 marked this pull request as ready for review December 30, 2022 23:37
@yuwu9145
Copy link
Member Author

Find a one line change solution and PR has been updated

@yuwu9145 yuwu9145 changed the title fix(locationStrategies): fix offsetWidth/height changing during transition fix(VTooltip): enforce one line txt to make its container width consistent Dec 30, 2022
@yuwu9145 yuwu9145 changed the title fix(VTooltip): enforce one line txt to make its container width consistent fix(VTooltip): display intrinsic maximum width content Dec 31, 2022
@KaelWD
Copy link
Member

KaelWD commented Jan 12, 2023

@yuwu9145 wdyt about this instead?

diff --git a/packages/vuetify/src/components/VOverlay/locationStrategies.ts b/packages/vuetify/src/components/VOverlay/locationStrategies.ts
index a130cee65..9fd584f4c 100644
--- a/packages/vuetify/src/components/VOverlay/locationStrategies.ts
+++ b/packages/vuetify/src/components/VOverlay/locationStrategies.ts
@@ -407,13 +407,9 @@ function connectedLocationStrategy (data: LocationStrategyData, props: StrategyP
       props.maxHeight,
     ],
     () => updateLocation(),
-    { immediate: !activatorFixed }
   )
 
-  if (activatorFixed) nextTick(() => updateLocation())
-  requestAnimationFrame(() => {
-    if (contentStyles.value.maxHeight) updateLocation()
-  })
+  nextTick(() => updateLocation())
 
   return { updateLocation }
 }

I don't remember exactly why I had immediate: !activatorFixed, but the way it is currently has updateLocation being called twice, the first time while the content still has display: none. This also allows #16042's nextTick to be removed.

@yuwu9145
Copy link
Member Author

yuwu9145 commented Jan 12, 2023

@yuwu9145 wdyt about this instead?

diff --git a/packages/vuetify/src/components/VOverlay/locationStrategies.ts b/packages/vuetify/src/components/VOverlay/locationStrategies.ts
index a130cee65..9fd584f4c 100644
--- a/packages/vuetify/src/components/VOverlay/locationStrategies.ts
+++ b/packages/vuetify/src/components/VOverlay/locationStrategies.ts
@@ -407,13 +407,9 @@ function connectedLocationStrategy (data: LocationStrategyData, props: StrategyP
       props.maxHeight,
     ],
     () => updateLocation(),
-    { immediate: !activatorFixed }
   )
 
-  if (activatorFixed) nextTick(() => updateLocation())
-  requestAnimationFrame(() => {
-    if (contentStyles.value.maxHeight) updateLocation()
-  })
+  nextTick(() => updateLocation())
 
   return { updateLocation }
 }

I don't remember exactly why I had immediate: !activatorFixed, but the way it is currently has updateLocation being called twice, the first time while the content still has display: none. This also allows #16042's nextTick to be removed.

removing nextTick will respect the fix for #16042, but would it break anything when locationStrategy is NOT connected ?

@yuwu9145 yuwu9145 marked this pull request as ready for review January 12, 2023 12:38
scope?.stop()
updateLocation.value = undefined

if (!(IN_BROWSER && data.isActive.value && props.locationStrategy)) return

scope = effectScope()
if (!(props.locationStrategy === 'connected')) { await nextTick() }
Copy link
Member Author

@yuwu9145 yuwu9145 Jan 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this break anything when locationStrategy is NOT connected ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it could technically break any custom locationStrategy, that's probably very uncommon though and I think it should always be handled by the strategy itself instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree. watchEffect should not have any nextTick from logical perspective

@johnleider johnleider added T: bug Functionality that does not work as intended/expected C: VTooltip VTooltip labels Jan 17, 2023
@johnleider johnleider added this to the v3.1.x milestone Jan 17, 2023
KaelWD added a commit that referenced this pull request Jan 24, 2023
@github-actions github-actions bot closed this Jan 24, 2023
@KaelWD
Copy link
Member

KaelWD commented Jan 24, 2023

This did end up breaking menus, added a fix and TODO to look at later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: VTooltip VTooltip T: bug Functionality that does not work as intended/expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants