Skip to content

Commit

Permalink
Allow passthrough attrs on UrlInput (#2329)
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei authored Jan 23, 2025
1 parent 3f787e2 commit 93dc50a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/components/common/UrlInput.vue
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -32,7 +32,6 @@ import { checkUrlReachable } from '@/utils/networkUtil'
const props = defineProps<{
modelValue: string
placeholder?: string
}>()
const emit = defineEmits<{
Expand Down Expand Up @@ -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>
32 changes: 32 additions & 0 deletions src/components/common/__tests__/UrlInput.test.ts
Original file line number Diff line number Diff line change
@@ -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('')
})
})

0 comments on commit 93dc50a

Please sign in to comment.