Skip to content

Commit

Permalink
feat(AutoComplete): add listener to autocomplete component (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukicenturi authored Sep 12, 2023
1 parent 5979076 commit 9bcb91e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/components/forms/auto-complete/AutoComplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ const updateOpen = (open: boolean) => {
});
}
};
const attrs = useAttrs();
</script>

<template>
Expand All @@ -198,6 +200,7 @@ const updateOpen = (open: boolean) => {
<TextField
v-model="query"
:as="AutoCompleteSelection"
v-bind="attrs"
:color="color"
:data="modelValue"
:dense="dense"
Expand Down
9 changes: 9 additions & 0 deletions src/components/forms/text-field/TextField.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ describe('Forms/TextField', () => {
expect(wrapper.find('input').attributes('disabled')).toBeUndefined();
});

it('passes readonly props', async () => {
const wrapper = createWrapper();
expect(wrapper.find('input').attributes('readonly')).toBeUndefined();
await wrapper.setProps({ readonly: true });
expect(wrapper.find('input').attributes('readonly')).toBeDefined();
await wrapper.setProps({ readonly: false });
expect(wrapper.find('input').attributes('readonly')).toBeUndefined();
});

it('passes color props', async () => {
const wrapper = createWrapper();
expect(wrapper.find('div[class*=wrapper]').classes()).toMatch(/_grey_/);
Expand Down
11 changes: 11 additions & 0 deletions src/components/forms/text-field/TextField.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const meta: Meta<Props> = {
table: { category: 'State' },
},
disabled: { control: 'boolean', table: { category: 'State' } },
readonly: { control: 'boolean', table: { category: 'State' } },
color: {
control: 'select',
options: ['grey', ...contextColors],
Expand Down Expand Up @@ -105,6 +106,16 @@ export const Disabled: Story = {
},
};

export const Readonly: Story = {
args: {
label: 'Label',
placeholder: 'Placeholder',
variant: 'outlined',
readonly: true,
modelValue: 'Readonly text',
},
};

export const WithErrorMessage: Story = {
args: {
label: 'Label',
Expand Down
3 changes: 3 additions & 0 deletions src/components/forms/text-field/TextField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Props {
hideDetails?: boolean;
prependIcon?: RuiIcons;
appendIcon?: RuiIcons;
readonly?: boolean;
}
defineOptions({
Expand All @@ -38,6 +39,7 @@ const props = withDefaults(defineProps<Props>(), {
hideDetails: false,
prependIcon: undefined,
appendIcon: undefined,
readonly: false,
});
const emit = defineEmits<{
Expand Down Expand Up @@ -120,6 +122,7 @@ const slots = useSlots();
:disabled="disabled"
:dense="dense"
:variant="variant"
:readonly="readonly"
:wrapper-width="width"
v-bind="objectOmit(attrs, ['class'])"
@input="input($event)"
Expand Down

0 comments on commit 9bcb91e

Please sign in to comment.