1- import type { ComponentPublicInstance } from 'vue'
1+ import type { ComponentPublicInstance , PropType } from 'vue'
22import {
33 defineComponent ,
44 getCurrentInstance ,
5+ nextTick ,
56 onMounted ,
67 onUnmounted ,
78 ref ,
@@ -29,6 +30,7 @@ const horizontalClassName = bem.modifier('horizontal').toString()
2930
3031export default defineComponent ( {
3132 props : {
33+ parent : Object as PropType < HTMLElement > ,
3234 indicators : Array < Indicator > ,
3335 size : {
3436 type : Number ,
@@ -52,16 +54,31 @@ export default defineComponent({
5254 let elements : HTMLElement [ ]
5355
5456 // eslint-disable-next-line sonarjs/cognitive-complexity
55- onMounted ( ( ) => {
57+ onMounted ( async ( ) => {
5658 if ( children . length <= 1 ) {
5759 return
5860 }
5961
60- container =
62+ const hackingContainer =
6163 children [ 0 ] . el ?. parentElement ??
64+ // prettier-ignore
6265 // @ts -expect-error
63- ( ( getCurrentInstance ( ) ! . parent ! . ctx as ComponentPublicInstance )
64- . $el as HTMLElement ) // type-coverage:ignore-line -- we can't control
66+ // type-coverage:ignore-next-line -- we can't control
67+ ( ( getCurrentInstance ( ) ?. parent . ctx as ComponentPublicInstance | undefined ) ?. $el as
68+ | HTMLElement
69+ | undefined )
70+
71+ if ( hackingContainer ) {
72+ container = hackingContainer
73+ } else {
74+ await nextTick ( )
75+ if ( ! props . parent ) {
76+ throw new Error (
77+ 'No `parent` provided nor hacking container can be auto injected, please provide `parent` correctly' ,
78+ )
79+ }
80+ container = props . parent
81+ }
6582
6683 // eslint-disable-next-line unicorn/prefer-spread
6784 elements = ( Array . from ( container . children ) as HTMLElement [ ] ) . filter (
0 commit comments