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 3 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
79 changes: 56 additions & 23 deletions src/components/atoms/OcSearchBar/OcSearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,44 @@
class="oc-search"
:class="{ 'oc-search-small': small }"
>
<div class="oc-width-expand oc-position-relative">
<span v-if="icon" class="oc-search-icon" @click="focusSearchInput">
<oc-icon v-show="!loading" :name="icon" fill-type="line" />
<oc-spinner
v-show="loading"
:size="spinnerSize"
:aria-label="loadingAccessibleLabelValue"
<div class="oc-width-expand">
<div class="oc-width-1-1 oc-position-relative">
<span v-if="icon" class="oc-search-icon" @click="focusSearchInput">
<oc-icon v-show="!loading" :name="icon" fill-type="line" />
<oc-spinner
v-show="loading"
:size="spinnerSize"
:aria-label="loadingAccessibleLabelValue"
/>
</span>
<input
ref="searchInput"
:class="inputClass"
:aria-label="label"
:value="searchQuery"
:disabled="loading"
:placeholder="placeholder"
@input="onType($event.target.value)"
@keydown.enter="onSearch"
/>
</span>
<input
ref="searchInput"
:class="inputClass"
:aria-label="label"
:value="searchQuery"
:disabled="loading"
:placeholder="placeholder"
@input="onType($event.target.value)"
@keydown.enter="onSearch"
/>
<oc-button
v-if="query.length > 0"
JammingBen marked this conversation as resolved.
Show resolved Hide resolved
:aria-label="$gettext('Clear search query')"
class="oc-search-clear oc-position-small oc-position-center-right oc-mt-rm"
appearance="raw"
@click="onClear"
>
<oc-icon name="close" size="small" variation="passive" />
</oc-button>
</div>
<oc-button
v-if="query.length > 0"
:aria-label="$gettext('Clear search query')"
class="oc-search-clear oc-position-small oc-position-center-right oc-mt-rm"
v-if="showCancelButton"
variation="inverse"
class="oc-ml-m"
appearance="raw"
@click="onClear"
@click="onCancel"
>
<oc-icon name="close" size="small" variation="passive" />
<span v-text="$gettext('Cancel')" />
</oc-button>
</div>
<div class="oc-search-button-wrapper" :class="{ 'oc-invisible-sr': buttonHidden }">
Expand Down Expand Up @@ -175,6 +186,22 @@ export default {
required: false,
default: "",
},
/**
* Show a "cancel" button next to the search bar.
*/
showCancelButton: {
type: Boolean,
required: false,
default: false,
},
/**
* Handler function for when the cancel button is clicked.
*/
cancelHandler: {
type: Function,
required: false,
default: () => {},
},
},
data: () => ({
query: "",
Expand Down Expand Up @@ -237,6 +264,12 @@ export default {
*/
this.$emit("clear")
},
onCancel() {
this.query = ""
this.onType("")
this.onSearch()
this.cancelHandler()
},
},
}
</script>
Expand Down