Skip to content

Commit

Permalink
Usability improvements for search widget
Browse files Browse the repository at this point in the history
  • Loading branch information
tswfi committed Dec 20, 2023
1 parent 6fe6641 commit c08fd4c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions modules/ps_searchbar/ps_searchbar.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
<div id="search_widget" class="search-widgets js-search-widget" data-search-controller-url="{$search_controller_url}">
<form method="get" action="{$search_controller_url}">
<input type="hidden" name="controller" value="search">
<i class="material-icons search" aria-hidden="true">search</i>
<input class="js-search-input" type="text" name="s" value="{$search_string}" placeholder="{l s='Search our catalog' d='Shop.Theme.Catalog'}" aria-label="{l s='Search' d='Shop.Theme.Catalog'}">
<i class="material-icons search js-search-icon" aria-hidden="true">search</i>
<input class="js-search-input" type="search" name="s" value="{$search_string}" placeholder="{l s='Search our catalog' d='Shop.Theme.Catalog'}" aria-label="{l s='Search' d='Shop.Theme.Catalog'}">
<i class="material-icons clear" aria-hidden="true">clear</i>
</form>

Expand Down
1 change: 1 addition & 0 deletions src/js/constants/selectors-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const searchBar = {
searchResults: '.js-search-results',
searchTemplate: '.js-search-template',
searchInput: '.js-search-input',
searchIcon: '.js-search-icon',
};

export const checkout = {
Expand Down
15 changes: 15 additions & 0 deletions src/js/modules/ps_searchbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,23 @@ const initSearchbar = () => {
const searchResults = document.querySelector<HTMLElement>(SearchBarMap.searchResults);
const searchTemplate = document.querySelector<HTMLTemplateElement>(SearchBarMap.searchTemplate);
const searchInput = document.querySelector<HTMLInputElement>(SearchBarMap.searchInput);
const searchIcon = document.querySelector<HTMLElement>(SearchBarMap.searchIcon);
const searchUrl = searchWidget?.dataset.searchControllerUrl;

// focus on the input field when clicking on the widget area
// helps to have a larger "area" for touch devices
searchWidget?.addEventListener('click', () => {
searchInput?.focus();
});

// if input has text then submit search when clicking on the icon
// usability for people without "enter" key
searchIcon?.addEventListener('click', () => {
if(searchInput?.value) {

Check failure on line 31 in src/js/modules/ps_searchbar.ts

View workflow job for this annotation

GitHub Actions / ESLint

Expected space(s) after "if"
searchInput?.form?.submit();
}
});

searchCanvas?.addEventListener('hidden.bs.offcanvas', () => {
if (searchDropdown) {
searchDropdown.innerHTML = '';
Expand Down
1 change: 1 addition & 0 deletions types/selectors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ declare type searchBar = {
searchResults: string,
searchTemplate: string,
searchInput: string,
searchIcon: string,
};

declare type checkout = {
Expand Down

0 comments on commit c08fd4c

Please sign in to comment.