Skip to content

Commit

Permalink
add update:modelValue
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Lazarev committed Sep 19, 2023
1 parent 11c7804 commit 3a77417
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/components/ec-text-filter/ec-text-filter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ describe('EcTextFilter', () => {
expect((wrapper.findByDataTest('ec-input-field__input').element as HTMLInputElement).value).toBe('');
await wrapper.findByDataTest('ec-input-field__input').setValue('some text');
expect(wrapper.findComponent(EcTextFilter).emitted()[TextFilterEvent.CHANGE]?.[0]).toEqual(['some text']);
expect(wrapper.findComponent(EcTextFilter).emitted()[TextFilterEvent.UPDATE_MODEL_VALUE]?.[0]).toEqual(['some text']);
});

it('should emit the empty value when you click on close icon', async () => {
Expand All @@ -110,6 +111,7 @@ describe('EcTextFilter', () => {

await wrapper.findByDataTest('ec-input-field__icon').trigger('click');
expect(wrapper.findComponent(EcTextFilter).emitted()[TextFilterEvent.CHANGE]?.[0]).toEqual(['']);
expect(wrapper.findComponent(EcTextFilter).emitted()[TextFilterEvent.UPDATE_MODEL_VALUE]?.[0]).toEqual(['']);
});

it('should render with a sensitive class when isSensitive prop is set to true', () => {
Expand Down
10 changes: 8 additions & 2 deletions src/components/ec-text-filter/ec-text-filter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
:left-icon="IconName.SimpleSearch"
:type="InputFieldType.TEXT"
:icon="rightIcon"
@icon-click="emit(TextFilterEvent.CHANGE, '')"
@icon-click="emitModelValue('')"
/>
</div>
</template>
Expand All @@ -32,6 +32,7 @@ interface TextFilterProps {
const props = defineProps<TextFilterProps>();
const emit = defineEmits<{
'update:modelValue': [value: TextFilterEvents[TextFilterEvent.UPDATE_MODEL_VALUE]],
'change': [value: TextFilterEvents[TextFilterEvent.CHANGE]],
}>();
Expand All @@ -40,9 +41,14 @@ const inputModel = computed<TextFilterProps['modelValue']>({
return props.modelValue;
},
set(value) {
emit(TextFilterEvent.CHANGE, value as unknown as TextFilterEvents[TextFilterEvent.CHANGE]);
emitModelValue(value);
},
});
function emitModelValue(value: TextFilterProps['modelValue']) {
emit(TextFilterEvent.UPDATE_MODEL_VALUE, value);
emit(TextFilterEvent.CHANGE, value);
}
const rightIcon = computed(() => (props.modelValue ? IconName.SimpleClose : undefined));
</script>
2 changes: 2 additions & 0 deletions src/components/ec-text-filter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ export interface TextFilterProps {
}

export enum TextFilterEvent {
UPDATE_MODEL_VALUE = 'update:modelValue',
CHANGE = 'change',
}

export interface TextFilterEvents {
[TextFilterEvent.UPDATE_MODEL_VALUE]: InputFieldProps['modelValue']
[TextFilterEvent.CHANGE]: InputFieldProps['modelValue']
}

0 comments on commit 3a77417

Please sign in to comment.