diff --git a/assets/haditha/font-icons/close-circle.svg b/assets/haditha/font-icons/close-circle.svg
new file mode 100644
index 0000000..a92e4d6
--- /dev/null
+++ b/assets/haditha/font-icons/close-circle.svg
@@ -0,0 +1,5 @@
+
diff --git a/components/haditha/AutoComplation.vue b/components/haditha/AutoComplation.vue
index c184877..f43c75f 100644
--- a/components/haditha/AutoComplation.vue
+++ b/components/haditha/AutoComplation.vue
@@ -57,6 +57,7 @@ const search_type = ref("normal");
const type_key = ref("hadith");
const typeModelValue = ref("normal");
const typeModelValueFa = ref("");
+const showclearButton = ref(false);
// If you want to share state across multiple components,
// you can use the same key in useState. Nuxt will ensure
@@ -168,17 +169,27 @@ const clearSimilar = () => {
// const onUpdateModel = (newVal: boolean | InputMenuItem | any) => {
// console.info("onUpdateModel", newVal);
// };
+const searchButtonIcon = computed(() => {
+ return showclearButton.value ? "i-lucide-x" : "i-haditha-search";
+});
+
+const handleSearchClearButton = ()=>{
+ showclearButton.value = true;
+ sendQuery();
+}
const onKeyDown = () => {
- clearTimeout(typingTimer.value);
-};
-const onKeyUp = () => {
- clearTimeout(typingTimer.value);
- typingTimer.value = setTimeout(() => {
- if (props.autoRedirection) sendQuery();
- }, doneTypingInterval.value);
+ showclearButton.value = false;
+ // clearTimeout(typingTimer.value);
};
+// const onKeyUp = () => {
+// clearTimeout(typingTimer.value);
+// typingTimer.value = setTimeout(() => {
+// if (props.autoRedirection) sendQuery();
+// }, doneTypingInterval.value);
+// };
+
const setType = (type: string) => {
search_type.value = type;
sendQuery();
@@ -225,11 +236,6 @@ const sendQuery = async (payload = {}) => {
.postRequest(url, payload)
.then((res) => {
// pass res and search query to the parent.
- emit("response-ready", {
- res: res,
- searchQuery: searchTerm.value,
- disableAutoRedirect: true,
- });
loading.value = false;
// check if search term is not empty
@@ -238,6 +244,32 @@ const sendQuery = async (payload = {}) => {
// close the history dropdown menu
open.value = false;
+
+
+ // show clear button
+ if (showclearButton.value) {
+ searchTerm.value = "";
+
+ emit("response-ready", {
+ res: {
+ hits:{
+ total:0,
+ hits:[]
+ }
+ },
+ searchQuery: searchTerm.value,
+ disableAutoRedirect: true,
+ });
+ } else {
+ emit("response-ready", {
+ res: res,
+ searchQuery: searchTerm.value,
+ disableAutoRedirect: true,
+ });
+ }
+
+ showclearButton.value = !showclearButton.value;
+
// store search phrase
useStorage("searchPhrase", searchTerm.value);
})
@@ -405,7 +437,6 @@ onMounted(() => {
@blur="open = false"
@change="sendQuery"
@keydown="onKeyDown"
- @keyup="onKeyUp"
@keydown.enter="sendQuery"
>
@@ -414,8 +445,9 @@ onMounted(() => {