Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usability improvements for search widget #572

Merged
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
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) {
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
Loading