Skip to content

Commit 97a2455

Browse files
committed
fix(CDropdown): resolve placement and refs typescript errors
1 parent d4964fa commit 97a2455

File tree

1 file changed

+5
-28
lines changed

1 file changed

+5
-28
lines changed

src/components/dropdown/CDropdown.ts

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import {
88
reactive,
99
toRefs,
1010
watch,
11+
PropType,
1112
} from 'vue'
12-
import { createPopper } from '@popperjs/core'
13+
import { createPopper, Placement } from '@popperjs/core'
1314

1415
const CDropdown = defineComponent({
1516
name: 'CDropdown',
@@ -92,29 +93,9 @@ const CDropdown = defineComponent({
9293
* @default 'bottom-start'
9394
*/
9495
placement: {
95-
type: String,
96+
type: String as PropType<Placement>,
9697
default: 'bottom-start',
9798
required: false,
98-
validator: (value: string) => {
99-
// The value must match one of these strings
100-
return [
101-
'auto',
102-
'auto-start',
103-
'auto-end',
104-
'top-end',
105-
'top',
106-
'top-start',
107-
'bottom-end',
108-
'bottom',
109-
'bottom-start',
110-
'right-start',
111-
'right',
112-
'right-end',
113-
'left-start',
114-
'left',
115-
'left-end',
116-
].includes(value)
117-
},
11899
},
119100
/**
120101
* If you want to disable dynamic positioning set this property to `true`.
@@ -154,11 +135,10 @@ const CDropdown = defineComponent({
154135
},
155136
},
156137
setup(props, { slots }) {
157-
const dropdownRef = ref(null)
158-
const dropdownMenuRef = ref(null)
138+
const dropdownRef = ref()
139+
const dropdownMenuRef = ref()
159140
const placement = ref(props.placement)
160141
const popper = ref()
161-
// const visible = ref()
162142

163143
const config = reactive({
164144
alignment: props.alignment,
@@ -196,7 +176,6 @@ const CDropdown = defineComponent({
196176
}
197177

198178
if (dropdownRef.value) {
199-
// @ts-expect-error TODO: find solution
200179
popper.value = createPopper(dropdownRef.value, dropdownMenuRef.value, {
201180
placement: placement.value,
202181
})
@@ -233,13 +212,11 @@ const CDropdown = defineComponent({
233212
}
234213

235214
const handleKeyup = (event: Event) => {
236-
// @ts-expect-error TODO: find solution
237215
if (dropdownRef.value && !dropdownRef.value.contains(event.target as HTMLElement)) {
238216
hideMenu()
239217
}
240218
}
241219
const handleClickOutside = (event: Event) => {
242-
// @ts-expect-error TODO: find solution
243220
if (dropdownRef.value && !dropdownRef.value.contains(event.target as HTMLElement)) {
244221
hideMenu()
245222
}

0 commit comments

Comments
 (0)