Skip to content

Commit

Permalink
PATCH: feat(components): add autoclear prop to search-autocomplete (#224
Browse files Browse the repository at this point in the history
)

* feat(components): add autoclear prop to search-autocomplete

* fix(components): set search-autocomplete autoclear prop default to true

Co-authored-by: NicolasRichel <nicolas@bimdata.io>
  • Loading branch information
NicolasRichel and NicolasRichel committed Jul 28, 2022
1 parent d4f0c38 commit 5e1dc40
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ export default {
type: String,
default: "",
},
autoclear: {
type: Boolean,
default: true,
},
},
data() {
return {
Expand Down Expand Up @@ -155,22 +159,28 @@ export default {
},
onElementClick(result) {
this.$emit("item-click", result);
this.search = "";
this.isOpen = false;
if (this.autoclear) {
this.search = "";
}
},
onAllResultatsBtnClick() {
this.$emit("all-results-click", {
results: this.results,
search: this.search,
});
this.search = "";
this.isOpen = false;
if (this.autoclear) {
this.search = "";
}
},
onEnter() {
this.$emit("enter", this.results[this.current].id);
this.search = "";
this.isOpen = false;
this.current = -1;
if (this.autoclear) {
this.search = "";
}
},
onArrowUp() {
if (this.current >= 1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.bimdata-search-autocomplete {
width: 350px;
position: relative;
display: inline-block;
width: 350px;

&__input {
position: relative;
.bimdata-search-icon {
Expand Down
62 changes: 36 additions & 26 deletions src/web/views/Components/SearchAutocomplete/SearchAutocomplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,41 @@

<ComponentCode :componentTitle="$route.name" language="javascript">
<template #module>
<BIMDataSearchAutocomplete
placeholder="Search"
:items="apps"
@item-click="onItemClick"
@all-results-click="onAllResultsClick"
:loading="isLoading"
class="m-t-24"
>
<template #logoPlaceholder>
<span>I lost my LOGO :'(</span>
</template>
</BIMDataSearchAutocomplete>
<div>
<BIMDataSearchAutocomplete
class="m-t-24"
placeholder="Search"
:items="apps"
:loading="isLoading"
:autoclear="isAutoclear"
@item-click="selectedApp = $event"
@all-results-click="onAllResultsClick"
>
<template #logoPlaceholder>
<span>I lost my LOGO :'(</span>
</template>
</BIMDataSearchAutocomplete>
<BIMDataButton
style="display: inline-flex; margin-left: 12px"
fill
radius
@click="selectedApp = null"
>
Reset
</BIMDataButton>
</div>
<div class="m-t-24">
{{ selectedApp ? JSON.stringify(selectedApp) : "" }}
</div>
</template>

<template #parameters>
<div class="m-t-12">
<BIMDataCheckbox text="Loading" v-model="isLoading" />
</div>
<div class="m-t-12">
<BIMDataCheckbox text="Autoclear" v-model="isAutoclear" />
</div>
</template>

<template #import>
Expand All @@ -36,8 +53,9 @@
<pre>
&lt;BIMDataSearchAutocomplete
placeholder="Search"
{{ isLoadingChecked() }}
:items="apps"
{{ isLoading ? ':loading="true"' : "" }}
{{ isAutoclear ? ':autoclear="true"' : "" }}
@item-click="onItemClick"
@all-results-click="onAllResultsClick"
/&gt;
Expand Down Expand Up @@ -68,6 +86,7 @@ import slotsData from "./slots-data.js";
import ComponentCode from "../../Elements/ComponentCode/ComponentCode.vue";
import BIMDataButton from "../../../../BIMDataComponents/BIMDataButton/BIMDataButton.vue";
import BIMDataCheckbox from "../../../../BIMDataComponents/BIMDataCheckbox/BIMDataCheckbox.vue";
import BIMDataSearchAutocomplete from "../../../../BIMDataComponents/BIMDataSearchAutocomplete/BIMDataSearchAutocomplete.vue";
import BIMDataText from "../../../../BIMDataComponents/BIMDataText/BIMDataText.vue";
Expand All @@ -76,16 +95,19 @@ import BIMDataTable from "../../../../BIMDataComponents/BIMDataTable/BIMDataTabl
export default {
components: {
ComponentCode,
BIMDataButton,
BIMDataCheckbox,
BIMDataText,
BIMDataSearchAutocomplete,
BIMDataText,
BIMDataTable,
},
data: function () {
return {
propsData,
slotsData,
isLoading: false,
isAutoclear: true,
selectedApp: null,
apps: [
{
title: "App 01",
Expand All @@ -110,21 +132,9 @@ export default {
};
},
methods: {
onItemClick($event) {
console.log($event);
},
onAllResultsClick($event) {
console.log($event);
},
isLoadingChecked() {
if (this.isLoading) {
return ":loading='true'";
}
},
},
};
</script>

<style lang="scss" scoped>
// @import "./_YourFileStyle.scss";
</style>
6 changes: 6 additions & 0 deletions src/web/views/Components/SearchAutocomplete/props-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ export default [
"false",
"",
],
[
"autoclear",
"Boolean",
"true",
"If true (default), automatically clear search text when an item is selected",
],
];

0 comments on commit 5e1dc40

Please sign in to comment.