Skip to content

Commit e45597c

Browse files
authored
fix: add strategy to tooltip and use it in sticky elems (#1330)
1 parent f345226 commit e45597c

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

app/components/Package/MetricsBadges.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const typesHref = computed(() => {
5757
<ul class="flex items-center gap-1.5 list-none m-0 p-0">
5858
<!-- TypeScript types badge -->
5959
<li v-if="!props.isBinary" class="contents">
60-
<TooltipApp :text="typesTooltip">
60+
<TooltipApp :text="typesTooltip" strategy="fixed">
6161
<LinkBase
6262
v-if="typesHref"
6363
variant="button-secondary"
@@ -88,6 +88,7 @@ const typesHref = computed(() => {
8888
<li class="contents">
8989
<TooltipApp
9090
:text="isLoading ? '' : hasEsm ? $t('package.metrics.esm') : $t('package.metrics.no_esm')"
91+
strategy="fixed"
9192
>
9293
<TagStatic
9394
tabindex="0"
@@ -107,7 +108,7 @@ const typesHref = computed(() => {
107108

108109
<!-- CJS badge -->
109110
<li v-if="isLoading || hasCjs" class="contents">
110-
<TooltipApp :text="isLoading ? '' : $t('package.metrics.cjs')">
111+
<TooltipApp :text="isLoading ? '' : $t('package.metrics.cjs')" strategy="fixed">
111112
<TagStatic
112113
tabindex="0"
113114
:variant="isLoading ? 'ghost' : 'default'"

app/components/Tooltip/Base.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import type { HTMLAttributes } from 'vue'
3-
import type { Placement } from '@floating-ui/vue'
3+
import type { Placement, Strategy } from '@floating-ui/vue'
44
import { autoUpdate, flip, offset, shift, useFloating } from '@floating-ui/vue'
55
66
const props = withDefaults(
@@ -17,9 +17,12 @@ const props = withDefaults(
1717
tooltipAttr?: HTMLAttributes
1818
/** Teleport target for the tooltip content (defaults to 'body') */
1919
to?: string | HTMLElement
20+
/** Strategy for the tooltip - prefer fixed for sticky containers (defaults to 'absolute') */
21+
strategy?: Strategy
2022
}>(),
2123
{
2224
to: 'body',
25+
strategy: 'absolute',
2326
},
2427
)
2528
@@ -31,6 +34,7 @@ const placement = computed<Placement>(() => props.position || 'bottom')
3134
const { floatingStyles } = useFloating(triggerRef, tooltipRef, {
3235
placement,
3336
whileElementsMounted: autoUpdate,
37+
strategy: props.strategy,
3438
middleware: [offset(4), flip(), shift({ padding: 8 })],
3539
})
3640
</script>

app/pages/package/[[org]]/[name].vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ onKeyStroke(
623623
: $t('package.verified_provenance')
624624
"
625625
position="bottom"
626+
strategy="fixed"
626627
>
627628
<LinkBase
628629
variant="button-secondary"
@@ -696,6 +697,7 @@ onKeyStroke(
696697
"
697698
position="bottom"
698699
class="items-center"
700+
strategy="fixed"
699701
>
700702
<ButtonBase
701703
@click="likeAction"

0 commit comments

Comments
 (0)