Skip to content
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sysvale/cuida",
"version": "3.158.3",
"version": "3.158.4",
"description": "A design system built by Sysvale, using storybook and Vue components",
"repository": {
"type": "git",
Expand Down
7 changes: 1 addition & 6 deletions src/components/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ function filterOptions(value) {
return;
}

if (props.searchable && props.addable) {
if (props.searchable) {
searchString.value = value;
}

Expand Down Expand Up @@ -601,11 +601,6 @@ function hide() {
localValue.value = null;
}

if (!searchString.value && !shouldClearSelection) {
localValue.value = localOptions.value.some(item => item[props.optionsField]?.toLowerCase() === get(localValue.value, props.optionsField)?.toLowerCase())
? localValue.value
: {};
}

nextTick(() => {
localOptions.value = pristineOptions.value;
Expand Down
62 changes: 60 additions & 2 deletions src/tests/Select.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, test, expect } from 'vitest';
import { mount } from '@vue/test-utils';
import Select from '../components/Select.vue';
import { describe, expect, test } from 'vitest';
import CdsBaseInput from '../components/BaseInput.vue';
import Select from '../components/Select.vue';

describe('Select', () => {
test('renders correctly', () => {
Expand Down Expand Up @@ -180,4 +180,62 @@ describe('Select', () => {
await wrapper.find('input').trigger('blur');
expect(wrapper.vm.active).toBe(false);
});

test('does not emit update:modelValue when focused and blurred without changes (when modelValue is empty)', async () => {
const wrapper = mount(Select, {
props: {
label: 'label',
id: 'select-input',
options: [{ value: 'Option 1' }, { value: 'Option 2' }],
modelValue: undefined,
},
});

await wrapper.find('input').trigger('focus');
await wrapper.find('input').trigger('blur');

expect(wrapper.emitted('update:modelValue')).toBeUndefined();
});

test('does not reset modelValue when blurred with active filtered search (searchable: true)', async () => {
const wrapper = mount(Select, {
props: {
label: 'label',
id: 'select-input',
options: [{ value: 'Option 1' }, { value: 'Option 2' }],
searchable: true,
modelValue: { value: 'Option 1' },
},
});

await wrapper.find('input').trigger('focus');
await wrapper.find('input').setValue('Option 2');
await wrapper.findComponent(CdsBaseInput).trigger('input');

await wrapper.find('input').trigger('blur');

expect(wrapper.emitted('update:modelValue')).toBeUndefined();
expect(wrapper.vm.localValue).toEqual({ value: 'Option 1' });
});

test('set modelValue to null when blurred with active filtered search that does not find any items (searchable: true)', async () => {
const wrapper = mount(Select, {
props: {
label: 'label',
id: 'select-input',
options: [{ value: 'Option 1' }, { value: 'Option 2' }],
searchable: true,
modelValue: { value: 'Option 1' },
},
});

await wrapper.find('input').trigger('focus');
await wrapper.find('input').setValue('Not an option');
await wrapper.findComponent(CdsBaseInput).trigger('input');

await wrapper.find('input').trigger('blur');

expect(wrapper.emitted('update:modelValue')).toStrictEqual([[ null ]]);
expect(wrapper.vm.localValue).toBeNull();
});
});
Comment thread
jvictordev1 marked this conversation as resolved.
Loading