Skip to content

Commit

Permalink
feat(autocomplete): clearable autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
gravitano committed May 11, 2022
1 parent aa26812 commit bdfecb9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/autocomplete/src/Autocomplete.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ const Template = (args) => ({

export const Default = Template.bind({});
Default.args = {};

export const Clearable = Template.bind({});
Clearable.args = {
clearable: true,
};
18 changes: 12 additions & 6 deletions packages/autocomplete/src/Autocomplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Props = {
clearable?: boolean;
notFoundText?: string;
noDataText?: string;
clearable?: boolean;
};
const props = withDefaults(defineProps<Props>(), {
Expand All @@ -45,6 +46,7 @@ const props = withDefaults(defineProps<Props>(), {
items: () => [],
noDataText: 'No data.',
notFoundText: 'Nothing found.',
clearable: false,
});
const emit = defineEmits(['update:modelValue', 'update:query']);
Expand All @@ -66,9 +68,10 @@ watch(selected, (val) => {
watch(query, (val) => {
emit('update:query', val);
if (val === '') {
selected.value = '';
}
// if (val === '') {
// console.log({val});
// selected.value = '';
// }
});
const filteredItems = computed(() =>
Expand Down Expand Up @@ -131,21 +134,24 @@ const clear = () => {
/>
<div class="absolute inset-y-0 right-0 flex items-center pr-4">
<button
v-if="clearable"
v-if="clearable && selected"
type="button"
class="
mr-1
text-gray-400
hover:text-gray-700
hover:bg-gray-200
hover:bg-gray-100
rounded-full
p-1
transition
duration-300
"
@click="clear"
>
<XIcon class="w-6 h-6" aria-hidden="true" />
<XIcon
class="w-6 h-6 fill-current text-gray-500"
aria-hidden="true"
/>
</button>
<ComboboxButton>
<ChevronDownIcon
Expand Down
1 change: 1 addition & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = {
'./packages/toast/src/*.{vue,js,ts,jsx,tsx}',
'./packages/tooltip/src/*.{vue,js,ts,jsx,tsx}',
'./packages/utils/*.{vue,js,ts,jsx,tsx}',
'./packages/autocomplete/src/*.{vue,js,ts,jsx,tsx}',
],
presets: [require('./packages/tailwind-config/preset')],
};

0 comments on commit bdfecb9

Please sign in to comment.