Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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: false,
},
},
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: false,
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",
"false",
"If true, automatically clear search text when an item is selected",
],
];