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

Commit

Permalink
Sage Search followup (#539)
Browse files Browse the repository at this point in the history
* Sage Search followup

* removed click functionality
  • Loading branch information
QuintonJason authored Nov 13, 2020
1 parent ccce0f5 commit 055bf03
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
23 changes: 6 additions & 17 deletions lib/sage-frontend/javascript/system/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ Sage.search = (function() {
// ==================================================

function init(el) {
const elButton = el.querySelector(SELECTOR_SEARCH_BUTTON);
const elInput = el.querySelector(SELECTOR_SEARCH_INPUT);

el.addEventListener('keydown', searchOnInputHandler);
elButton.addEventListener('click', searchClearClickHandler);
// check the input for a value on load
hasValue(elInput) ? addVisibleButtonState(el) : removeVisibleButtonState(el);
el.addEventListener('keyup', searchOnInputHandler);
}

function unbind(el) {
const elButton = el.querySelector(SELECTOR_SEARCH_BUTTON);

el.removeEventListener('keydown', searchOnInputHandler);
elButton.removeEventListener('click', searchClearClickHandler);
el.removeEventListener('keyup', searchOnInputHandler);
}

function searchOnInputHandler(evt) {
Expand All @@ -34,18 +32,9 @@ Sage.search = (function() {
hasValue(elInput) ? addVisibleButtonState(elParent) : removeVisibleButtonState(elParent);
}

function searchClearClickHandler(evt) {
const elParent = evt.currentTarget.closest(`[${SELECTOR_SEARCH}]`);
const elInput = elParent.querySelector(SELECTOR_SEARCH_INPUT);

elParent.classList.remove(CLASS_VISIBLE);
elInput.value = ""; /* reset the search field */
elInput.blur(); /* force refresh with blur event */
}

// check if the search value has text or not
function hasValue(el) {
return el.value.length >= 0
return el.value.length > 0
}

function addVisibleButtonState(elParent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form
<div
role="search"
class=" sage-search
<%= "sage-search--contained" if component.contained %>
Expand Down Expand Up @@ -27,4 +27,4 @@
}
} %>

</form>
</div>

0 comments on commit 055bf03

Please sign in to comment.