Skip to content

Commit b0533fd

Browse files
committed
fix(tooltip): tooltip not working properly on HTML elements
closes #140
1 parent 37769b6 commit b0533fd

File tree

7 files changed

+43
-21
lines changed

7 files changed

+43
-21
lines changed

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ module.exports = {
5555
'/^(click):[a-z]+[a-zA-Z]+$/',
5656
],
5757
}],
58+
'vue/component-name-in-template-casing': ['error', 'PascalCase', {
59+
registeredComponentsOnly: false,
60+
ignores: [],
61+
}],
5862

5963
// Vue
6064
'vue/require-default-prop': 'off',

packages/anu-vue/src/components/alert/AAlert.vue

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script lang="ts" setup>
2-
import { AIcon } from '@/components';
3-
import { useLayer, useProps as useLayerProps } from '@/composables/useLayer';
4-
import { configurable as configurableProp } from '@/composables/useProps';
5-
import type { ExtractPropTypes } from 'vue';
2+
import type { ExtractPropTypes } from 'vue'
3+
import { AIcon } from '@/components'
4+
import { useLayer, useProps as useLayerProps } from '@/composables/useLayer'
5+
import { configurable as configurableProp } from '@/composables/useProps'
66
77
const props = defineProps({
88
@@ -83,14 +83,15 @@ const handleAppendIconClick = () => {
8383
}
8484
8585
const appendIconBindings = computed(() => {
86-
if (props.dismissible)
86+
if (props.dismissible) {
8787
return {
8888
icon: appendIcon,
89-
ariaLabel: 'close'
89+
ariaLabel: 'close',
9090
}
91+
}
9192
9293
return {
93-
class: appendIcon
94+
class: appendIcon,
9495
}
9596
})
9697
</script>
@@ -109,14 +110,17 @@ const appendIconBindings = computed(() => {
109110
<div v-if="props.icon">
110111
<i :class="props.icon" />
111112
</div>
112-
<div class="flex-grow">
113+
<div
114+
class="flex-grow"
115+
data-no-reference
116+
>
113117
<slot />
114118
</div>
115119
<div>
116120
<slot name="append">
117121
<Component
118-
v-if="appendIcon"
119122
:is="props.dismissible ? AIcon : 'i'"
123+
v-if="appendIcon"
120124
class="align-text-top"
121125
v-bind="appendIconBindings"
122126
@click="handleAppendIconClick"

packages/anu-vue/src/components/btn/ABtn.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const { styles, classes } = getLayerClasses(
4646
/>
4747
<div
4848
class="a-btn-content"
49+
data-no-reference
4950
:class="[props.loading && 'opacity-0']"
5051
>
5152
<i

packages/anu-vue/src/components/switch/ASwitch.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ const dotPosition = computed(() => {
6565
>
6666

6767
<!-- 👉 Label -->
68-
<div class="a-switch-label">
68+
<div
69+
class="a-switch-label"
70+
data-no-reference
71+
>
6972
<slot>{{ props.label }}</slot>
7073
</div>
7174

packages/anu-vue/src/components/tooltip/ATooltip.vue

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script lang="ts" setup>
2-
import type { Middleware } from '@floating-ui/vue';
2+
import type { Middleware } from '@floating-ui/vue'
33
44
// import { arrow } from '@floating-ui/vue'
5-
import { AFloating } from '@/components/floating';
6-
import { useParent } from '@/composables';
7-
import { flip, offset, shift } from '@floating-ui/vue';
8-
import { tooltipProps } from './props';
5+
import { flip, offset, shift } from '@floating-ui/vue'
6+
import { tooltipProps } from './props'
7+
import { AFloating } from '@/components/floating'
8+
import { useParent } from '@/composables'
99
1010
const props = defineProps(tooltipProps)
1111
@@ -44,9 +44,11 @@ const floatingMiddleware = [
4444
:middleware="() => floatingMiddleware"
4545
>
4646
<div class="a-tooltip">
47-
<slot>
48-
<span class="a-tooltip-text">{{ props.text }}</span>
49-
</slot>
47+
<span class="a-tooltip-text">
48+
<slot>
49+
{{ props.text }}
50+
</slot>
51+
</span>
5052
<!-- <div
5153
ref="arrowEl"
5254
class="a-tooltip-arrow absolute"

packages/anu-vue/src/composables/useParent.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
export function useParent (){
1+
export function useParent() {
22
const parentEl = ref()
3+
34
onMounted(() => {
45
const vm = getCurrentInstance()
5-
if (vm?.proxy?.$parent)
6-
parentEl.value = unrefElement(vm?.proxy?.$parent)
6+
let parent: ParentNode | null = vm?.proxy?.$el.parentNode
7+
8+
// TODO: Fix types
9+
// @ts-expect-error hasAttribute doesn't exist on parentNode type
10+
while (parent && parent.hasAttribute('data-no-reference'))
11+
parent = parent.parentNode
12+
13+
parentEl.value = parent
714
})
815

916
return parentEl

packages/anu-vue/volar.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ declare module 'vue' {
1212
ADialog: typeof import('anu-vue')['ADialog']
1313
ADrawer: typeof import('anu-vue')['ADrawer']
1414
AFloating: typeof import('anu-vue')['AFloating']
15+
AIcon: typeof import('anu-vue')['AIcon']
1516
AInput: typeof import('anu-vue')['AInput']
1617
AList: typeof import('anu-vue')['AList']
1718
AListItem: typeof import('anu-vue')['AListItem']

0 commit comments

Comments
 (0)