Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/app-vitest-full/components/OptionsApiComputed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
<li data-testid="object-with-get-and-set">
{{ objectWithGetAndSet }}
</li>
<li>
<button
data-testid="hanlde-change-object-with-get-and-set"
@click="hanldeChangeObjectWithGetAndSet"
>
Change
</button>
</li>
</ul>
</template>

Expand Down Expand Up @@ -37,5 +45,10 @@ export default {
},
},
},
methods: {
hanldeChangeObjectWithGetAndSet() {
this.objectWithGetAndSet = `${this.objectWithGetAndSet} (changed)`
},
},
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<script setup lang="ts">
const {
none = false,
show = true,
label = '',
} = defineProps<{
none?: boolean
show?: boolean
label?: string
}>()

const emit = defineEmits<{
blur: []
unmount: []
unmounted: []
}>()

const disabled = ref(false)
const inputRef = useTemplateRef('inputRef')
const modelValue = defineModel<string>({ default: '' })
const counter = computed(() => disabled.value ? '' : `[${modelValue.value.length}/30]`)

function setValue(value: string) {
modelValue.value = value
}

function getValue() {
return modelValue.value
}

onBeforeUnmount(() => emit('unmount'))
onUnmounted(() => emit('unmounted'))

defineExpose({
disabled,
setValue,
getValue,
})
</script>

<template>
<div
v-if="!none"
v-show="show"
data-testid="container"
>
<label
for="input"
:class="$style.label"
data-testid="label"
>
{{ label }}
</label>
<input
id="input"
ref="inputRef"
v-model="modelValue"
:disabled
data-testid="input"
@blur="emit('blur')"
>
<span data-testid="counter">{{ counter }}</span>
<div data-testid="slot">
<slot />
</div>
<SomeComponent data-testid="some-component" />
</div>
</template>

<style module>
.label {
color: red;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<script>
export default defineComponent({
props: {
label: {
type: String,
default: () => '',
},
none: {
type: Boolean,
default: false,
},
show: {
type: Boolean,
default: true,
},
modelValue: {
type: String,
default: () => '',
},
modelModifiers: {
type: Object,
default: () => ({}),
},
},
emits: ['blur', 'update:modelValue', 'unmount', 'unmounted'],
expose: ['disabled', 'getValue', 'setValue'],
data() {
return {
disabled: false,
}
},
computed: {
counter() {
return this.disabled ? '' : `[${this.modelValue.length}/30]`
},
},
beforeUnmount() {
this.$emit('unmount')
},
unmounted() {
this.$emit('unmounted')
},
methods: {
setValue(value) {
this.$emit('update:modelValue', value)
},
getValue() {
return this.modelValue
},
},
})
</script>

<template>
<div
v-if="!none"
v-show="show"
data-testid="container"
>
<label
for="input"
:class="$style.label"
data-testid="label"
>
{{ label }}
</label>
<input
id="input"
ref="inputRef"
:value="modelValue"
:disabled
data-testid="input"
@blur="$emit('blur')"
@input="$emit('update:modelValue', $event.target.value)"
>
<span data-test-id="counter">{{ counter }}</span>
<div data-testid="slot">
<slot />
</div>
<SomeComponent data-testid="some-component" />
</div>
</template>

<style module>
.label {
color: red;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<script>
export default defineComponent({
props: {
label: {
type: String,
default: () => '',
},
none: {
type: Boolean,
default: false,
},
show: {
type: Boolean,
default: true,
},
modelValue: {
type: String,
default: () => '',
},
modelModifiers: {
type: Object,
default: () => ({}),
},
},
emits: ['blur', 'update:modelValue', 'unmount', 'unmounted'],
expose: ['disabled', 'getValue', 'setValue'],
setup(props, { emit }) {
const disabled = ref(false)

function setValue(value) {
emit('update:modelValue', value)
}

return {
disabled,
setValue,
}
},
computed: {
counter() {
return this.disabled ? '' : `[${this.modelValue.length}/30]`
},
},
beforeUnmount() {
this.$emit('unmount')
},
unmounted() {
this.$emit('unmounted')
},
methods: {
getValue() {
return this.modelValue
},
},
})
</script>

<template>
<div
v-if="!none"
v-show="show"
data-testid="container"
>
<label
for="input"
:class="$style.label"
data-testid="label"
>
{{ label }}
</label>
<input
id="input"
ref="inputRef"
:value="modelValue"
:disabled
data-test-id="input"
@blur="$emit('blur')"
@input="$emit('update:modelValue', $event.target.value)"
>
<span data-testid="counter">{{ counter }}</span>
<div data-testid="slot">
<slot />
</div>
<SomeComponent data-testid="some-component" />
</div>
</template>

<style module>
.label {
color: red;
}
</style>
4 changes: 3 additions & 1 deletion examples/app-vitest-full/components/WrapperTests.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ defineExpose({
<button
id="changeModelValue"
@click="modelValue = true"
/>
>
Change model!
</button>
</div>
</template>
Loading
Loading