Allow passthrough attrs on UrlInput (#2329)

This commit is contained in:
Chenlei Hu
2025-01-23 14:29:38 -05:00
committed by GitHub
parent 3f787e2dbf
commit 93dc50a95a
2 changed files with 38 additions and 2 deletions

View File

@@ -1,9 +1,9 @@
<template>
<IconField class="w-full">
<InputText
v-bind="$attrs"
:model-value="modelValue"
class="w-full"
:placeholder="placeholder"
:invalid="validationState === UrlValidationState.INVALID"
@update:model-value="handleInput"
@blur="validateUrl"
@@ -32,7 +32,6 @@ import { checkUrlReachable } from '@/utils/networkUtil'
const props = defineProps<{
modelValue: string
placeholder?: string
}>()
const emit = defineEmits<{
@@ -80,4 +79,9 @@ const validateUrl = async () => {
validationState.value = UrlValidationState.INVALID
}
}
// Add inheritAttrs option to prevent attrs from being applied to root element
defineOptions({
inheritAttrs: false
})
</script>

View File

@@ -0,0 +1,32 @@
import { mount } from '@vue/test-utils'
import PrimeVue from 'primevue/config'
import IconField from 'primevue/iconfield'
import InputIcon from 'primevue/inputicon'
import InputText from 'primevue/inputtext'
import { beforeEach, describe, expect, it } from 'vitest'
import { createApp } from 'vue'
import UrlInput from '../UrlInput.vue'
describe('UrlInput', () => {
beforeEach(() => {
const app = createApp({})
app.use(PrimeVue)
})
it('passes through additional attributes to input element', () => {
const wrapper = mount(UrlInput, {
global: {
plugins: [PrimeVue],
components: { IconField, InputIcon, InputText }
},
props: {
modelValue: '',
placeholder: 'Enter URL',
disabled: true
}
})
expect(wrapper.find('input').attributes('disabled')).toBe('')
})
})