Skip to content

Commit ceddc98

Browse files
authored
fix(checkbox): HTMLElement is not defined in Nuxt 3 (#483)
* fix: 'No projects matched the filters' for Nuxt playground" * fix: checkbox 'HTMLElement is not defined' in nuxt * fix: another issue when restarting dev server
1 parent 79911d8 commit ceddc98

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

packages/components/checkbox/src/checkbox.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { computed, defineComponent, h, mergeProps, reactive, ref, toRefs, useModel, watchEffect } from 'vue'
1+
import { computed, defineComponent, h, mergeProps, onMounted, reactive, ref, toRefs, useModel, watchEffect } from 'vue'
22
import { reactiveOmit, useComposedRefs, useControllable, useForwardRef, useListeners } from '@oku-ui/use-composable'
33
import { composeEventHandlers } from '@oku-ui/utils'
44
import { Primitive } from '@oku-ui/primitive'
@@ -40,7 +40,13 @@ const Checkbox = defineComponent({
4040
const composedRefs = useComposedRefs(forwardedRef, buttonRef)
4141
const hasConsumerStoppedPropagationRef = ref(false)
4242
// We set this to true by default so that events bubble to forms without JS (SSR)
43-
const isFormControl = computed(() => buttonRef.value instanceof HTMLElement ? Boolean(buttonRef.value.closest('form')) : false)
43+
const isFormControl = ref<boolean>(false)
44+
onMounted(() => {
45+
isFormControl.value = buttonRef.value
46+
? typeof buttonRef.value.closest === 'function'
47+
&& Boolean(buttonRef.value.closest('form'))
48+
: true
49+
})
4450

4551
const modelValue = useModel(props, 'modelValue')
4652
const proxyChecked = computed({

packages/components/checkbox/src/props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export const bubbleInputProps = {
135135
required: true,
136136
},
137137
control: {
138-
type: [HTMLElement, null] as PropType<BubbleInputProps['control']>,
138+
type: Object as PropType<BubbleInputProps['control']>,
139139
default: null,
140140
required: true,
141141
},

playground/nuxt3/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "nuxt3-playground",
2+
"name": "nuxt3",
33
"type": "module",
44
"private": true,
55
"scripts": {

0 commit comments

Comments
 (0)