Skip to content

Commit

Permalink
Fixes #495 - Adds input clear button
Browse files Browse the repository at this point in the history
- Adds search input manager for handling input clear button—little (x).
- Disables autocomplete because field highlight color can’t be
overridden.
- Removes unused data-list attributes.
- Adds tests for clearing the input fields.
  • Loading branch information
anselmbradford committed Jul 29, 2014
1 parent ffbcaa4 commit 6c23d00
Show file tree
Hide file tree
Showing 12 changed files with 626 additions and 22 deletions.
52 changes: 52 additions & 0 deletions app/assets/javascripts/search/input-manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Handles functionality of search inputs, such as how the inputs are cleared.
define(
function () {
'use strict';

function init() {

var inputs = document.querySelectorAll('.clearable');

for (var i = 0, len = inputs.length; i < len; i++) {
_initCloseButton(inputs[i])
}
}

function _initCloseButton(inputContainer) {

// Retrieve first and only input element.
var input = inputContainer.getElementsByTagName('input')[0];
var buttonClose = document.createElement('button');
buttonClose.className = 'button-close';
if (input.value === '')
buttonClose.className += ' hide';
inputContainer.appendChild(buttonClose);

//var buttonClose = input.querySelector('.close');
buttonClose.addEventListener('click', function (evt) {
evt.preventDefault();
input.value = '';
buttonClose.classList.add('hide');
input.focus();
})

input.addEventListener('keyup', function (evt) {
_checkCloseButtonVisibility(input, buttonClose);
})

input.addEventListener('change', function (evt) {
_checkCloseButtonVisibility(input, buttonClose);
})
}

function _checkCloseButtonVisibility(input, buttonClose) {
if (input.value === '')
buttonClose.classList.add('hide');
else
buttonClose.classList.remove('hide');
}

return {
init:init
};
});
10 changes: 7 additions & 3 deletions app/assets/javascripts/search/search-init.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// manages search initialization
require(['search/search-filter-manager'],
function (filter) {
// Manages search initialization.
require([
'search/search-filter-manager',
'search/input-manager'
],
function (filter, input) {
'use strict';

filter.init();
input.init();
});
5 changes: 3 additions & 2 deletions app/assets/stylesheets/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,17 @@
// Turns off proprietary default webkit styling of search input fields.
@mixin reset-input-webkit()
{
// Turns off iOS input rounding.
input[type=search]::-webkit-search-cancel-button,
input[type=search]::-webkit-search-decoration,
input[type=search]::-webkit-search-results-button,
input[type=search]::-webkit-search-results-decoration {
-webkit-appearance:none;
-webkit-appearance: none;
}
input[type=search] {
-webkit-appearance: none;
border-radius: 0;
-webkit-box-sizing:content-box;
-webkit-box-sizing: content-box;
}
}

Expand Down
51 changes: 47 additions & 4 deletions app/assets/stylesheets/components/_input-search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
height: 45px;
padding: 3px;
padding-left: 45px;
padding-right: 6px;
padding-right: 25px;
width: 100%;
vertical-align: bottom;

Expand All @@ -38,7 +38,7 @@
color: $white;
}

> button
> .button-icon
{
cursor: pointer;
background: none;
Expand Down Expand Up @@ -107,7 +107,7 @@
color: $black;
}

> button
> .button-icon
{
position: absolute;
top: 0;
Expand Down Expand Up @@ -181,7 +181,7 @@

> .filter-input-group
{
> button
> .button-icon
{
font-size: $font_size_110;
position: absolute;
Expand Down Expand Up @@ -268,3 +268,46 @@
}
}
}

// Clearable input fields have a (x) that can be clicked for clearing the
// field's content.
.clearable
{
position: relative;

&:hover
{
.button-close {
color: rgba($black, .4);
}
}

.button-close
{
position: absolute;
right: 0px;
top: 50%;
margin-top: -15px;

color: $greyscale_midtone; // IE Fallback
color: rgba($black, .1);
font-size: $font_size_110;

border-collapse: collapse;
border: none;
outline: none;
background: transparent;
}

.button-close:after,
.button-close::after
{
content: "×";
}

.button-close:hover
{
color: $black;
cursor: pointer;
}
}
6 changes: 3 additions & 3 deletions app/views/component/search/_agency.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
= field_set_tag nil, id: 'org-name-options', class: 'input-search-filter' do
= label_tag 'org_name', t('labels.agency_search')
= content_tag :div, '', class: 'filter-input-group' do
= button_tag(type: 'submit', name: nil) do
= content_tag :div, '', class: 'filter-input-group clearable' do
= button_tag(type: 'submit', name: nil, class: 'button-icon') do
= content_tag :i, '', class: 'fa fa-institution'
= search_field_tag :org_name, params[:org_name], placeholder: t('placeholders.agency_search'), list: 'search-agency'
= search_field_tag :org_name, params[:org_name], autocomplete: 'off', placeholder: t('placeholders.agency_search')
10 changes: 5 additions & 5 deletions app/views/component/search/_aside.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
%section#search-box
= form_tag('/organizations', method: :get, id: 'search-form') do
%section#keyword-search-box
%div.input-search-small
= button_tag(type: 'submit', name: nil, id: 'find-btn', title: 'Search') do
%div.input-search-small.clearable
= button_tag(type: 'submit', name: nil, id: 'find-btn', class: 'button-icon', title: 'Search') do
%i{ class: 'fa fa-search' }
= search_field_tag :keyword, params[:keyword], placeholder: t('placeholders.results_page_keyword_search'), list: 'search-keywords'
= search_field_tag :keyword, params[:keyword], autocomplete: 'off', placeholder: t('placeholders.results_page_keyword_search')

%section#search-options
= render 'component/search/location'
= render 'component/search/agency'

%ul#search-controls
%li
= button_tag(type:'submit', name: nil, class: 'update-btn button-small') do
= button_tag(type:'submit', name: nil, class: 'button-small update-btn') do
%i{ class: 'fa fa-refresh' }
= t('buttons.update_search_results')
%li
= button_tag(type: 'reset', name: nil, id: 'reset-btn', class: 'reset-btn button-small') do
= button_tag(type: 'reset', name: nil, id: 'reset-btn', class: 'button-small reset-btn') do
%i{ class: 'fa fa-times-circle' }
= t('buttons.clear_search_fields')
4 changes: 2 additions & 2 deletions app/views/component/search/_box.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
%section#keyword-search-box>
= label_tag 'keyword', t('labels.homepage_search')
%div.input-search-big
= search_field_tag :keyword, params[:keyword], placeholder: t('placeholders.homepage_keyword_search'), list: 'search-keywords'
= search_field_tag :keyword, params[:keyword], autocomplete: 'off', placeholder: t('placeholders.homepage_keyword_search')

= button_tag(type: 'submit', name: nil, id: 'find-btn', title: 'Search') do
= button_tag(type: 'submit', name: nil, id: 'find-btn', class: 'button-icon', title: 'Search') do
%i{ class: 'fa fa-search' }
%span
= t('buttons.homepage_search')
Expand Down
6 changes: 3 additions & 3 deletions app/views/component/search/_location.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
= field_set_tag nil, id: 'location-options', class: 'input-search-filter input-search-filter-option' do
= label_tag 'location', t('labels.address_search')
= content_tag :div, '', class: 'filter-input-group' do
= button_tag(type: 'submit', name: nil) do
= content_tag :div, '', class: 'filter-input-group clearable' do
= button_tag(type: 'submit', name: nil, class: 'button-icon') do
= content_tag :i, '', class: 'fa fa-map-marker'
= search_field_tag :location, params[:location], placeholder: t('placeholders.address_search'), list: 'search-location'
= search_field_tag :location, params[:location], autocomplete: 'off', placeholder: t('placeholders.address_search')
= render 'component/search/geolocate', context_class: 'input-search-filter-option'

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6c23d00

Please sign in to comment.