Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Add cancel-button and -handler to search component #2328

Merged
merged 4 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions changelog/unreleased/enhancement-search-cancel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: "Chancel"-button and -handler in OcSearchBar

We've added to possibility to have a "cancel"-button and -handler in the `OcSearchBar` component.

https://github.com/owncloud/web/issues/7617
https://github.com/owncloud/owncloud-design-system/pull/2328
50 changes: 49 additions & 1 deletion src/components/atoms/OcSearchBar/OcSearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@keydown.enter="onSearch"
/>
<oc-button
v-if="query.length > 0"
v-if="query.length"
:aria-label="$gettext('Clear search query')"
class="oc-search-clear oc-position-small oc-position-center-right oc-mt-rm"
appearance="raw"
Expand All @@ -46,6 +46,15 @@
{{ buttonLabel }}
</oc-button>
</div>
<oc-button
v-if="showCancelButton"
:variation="cancelButtonVariation"
class="oc-ml-m"
appearance="raw"
@click="onCancel"
>
<span v-text="$gettext('Cancel')" />
</oc-button>
</oc-grid>
</template>

Expand Down Expand Up @@ -175,6 +184,33 @@ export default {
required: false,
default: "",
},
/**
* Show a "cancel" button next to the search bar.
*/
showCancelButton: {
type: Boolean,
required: false,
default: false,
},
/**
* Variation of the cancel button
*/
cancelButtonVariation: {
type: String,
required: false,
default: "primary",
validator: value => {
return value.match(/(passive|primary|danger|success|warning|inverse)/)
},
},
/**
* Handler function for when the cancel button is clicked.
*/
cancelHandler: {
type: Function,
required: false,
default: () => {},
},
},
data: () => ({
query: "",
Expand Down Expand Up @@ -237,6 +273,12 @@ export default {
*/
this.$emit("clear")
},
onCancel() {
this.query = ""
this.onType("")
this.onSearch()
this.cancelHandler()
},
},
}
</script>
Expand Down Expand Up @@ -346,6 +388,12 @@ export default {
<oc-search-bar :isFilter="true" label="Search files" placeholder="Filter Files ..." :type-ahead="true" @search="onFilter" button="Filter" icon="" />
<div v-if="filterQuery" class="oc-m">Filter query: {{ filterQuery }}</div>
</section>
<section>
<h3 class="oc-heading-divider">
Search with cancel button
</h3>
<oc-search-bar label="Search files" placeholder="Enter search term" :type-ahead="true" :show-cancel-button="true" />
</section>
</div>
</template>
<script>
Expand Down