Skip to content

Commit bd14df7

Browse files
committed
New option added to highlight always first result automatically
1 parent 457368d commit bd14df7

7 files changed

+71
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
This component follows *Semantic Versioning* (aka SemVer), visit (http://semver.org/) to learn more about it.
44

5+
## Release 3.1.0 (2017-08-27)
6+
### New Features
7+
- Added a new boolean option `highlight-first` to both `paper-autocomplete` and `paper-autocomplete-suggestions` that
8+
when set, it will always highlight the first result each time new suggestions are presented.
9+
510
## Release 3.0.2 (2017-08-23)
611
### Bug Fixes
712
- It is now again possible to add a custom `paper-input` suffix. See the new demo.

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "paper-autocomplete",
3-
"version": "3.0.2",
3+
"version": "3.1.0",
44
"authors": [
55
"S. Francis",
66
"Rodolfo Oviedo <[email protected]>",

demo/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ <h3>Local Data-Source Binding</h3>
102102
</template>
103103
</demo-snippet>
104104

105+
<demo-snippet>
106+
<template>
107+
<paper-autocomplete id="highlightFirst"
108+
class="autocomplete-states"
109+
label="Auto highlight first option"
110+
id="highlight-first-example"
111+
highlight-first>
112+
</paper-autocomplete>
113+
</template>
114+
</demo-snippet>
115+
105116
<h3>Remote Data-Source Binding</h3>
106117
<p>
107118
Mock remote users data binding. Remote data binding delegates the responsibility of filtering the data source

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "paper-autocomplete",
33
"description": "Material Design autocomplete component.",
4-
"version": "3.0.2",
4+
"version": "3.1.0",
55
"author": "S. Francis <[email protected]>",
66
"contributors": [
77
"Rodolfo Oviedo <[email protected]>",

paper-autocomplete-suggestions.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,14 @@
309309
type: Function
310310
},
311311

312+
/**
313+
* If `true`, it will always highlight the first result each time new suggestions are presented.
314+
*/
315+
highlightFirst: {
316+
type: Boolean,
317+
value: false
318+
},
319+
312320
/**
313321
* `_suggestions` Array with the actual suggestions to display
314322
*/
@@ -596,6 +604,10 @@
596604
this._hasItemHighBeenCalculated = true;
597605
}
598606
}
607+
608+
if (this.highlightFirst) {
609+
this._moveHighlighted(DIRECTION.DOWN);
610+
}
599611
}, 100);
600612
},
601613

paper-autocomplete.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@
209209
query-fn="[[queryFn]]"
210210
event-namespace="[[eventNamespace]]"
211211
highlighted-suggestion="{{_highlightedSuggestion}}"
212-
is-open="{{_isSuggestionsOpened}}">
212+
is-open="{{_isSuggestionsOpened}}"
213+
highlight-first="[[highlightFirst]]">
213214

214215
<slot id="templates" name="autocomplete-custom-template"></slot>
215216

@@ -392,6 +393,14 @@
392393
type: Function
393394
},
394395

396+
/**
397+
* If `true`, it will always highlight the first result each time new suggestions are presented.
398+
*/
399+
highlightFirst: {
400+
type: Boolean,
401+
value: false
402+
},
403+
395404
/*************
396405
* PRIVATE
397406
*************/

test/paper-autocomplete_test_local.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,37 @@
332332
expect(isSuffixBtnAdded).to.be.true;
333333
});
334334

335+
describe('autocomplete option', function () {
336+
it('if set to `true`, it should highlight always the first suggestion', function () {
337+
element.setAttribute('highlight-first', '');
338+
339+
var suggestions = element.$.paperAutocompleteSuggestions.$.suggestionsWrapper;
340+
var input = element.$.autocompleteInput;
341+
342+
enterCharacter(input, 'A');
343+
344+
var activeSuggestions = suggestions.querySelectorAll('paper-item.active');
345+
var allSuggestions = suggestions.querySelectorAll('paper-item');
346+
347+
expect(allSuggestions).not.to.be.empty;
348+
expect(activeSuggestions.length).to.equal(1);
349+
expect(activeSuggestions[0]).to.equal(allSuggestions[0]);
350+
});
351+
352+
it('with default value, it should not highlight the first suggestion', function () {
353+
var suggestions = element.$.paperAutocompleteSuggestions.$.suggestionsWrapper;
354+
var input = element.$.autocompleteInput;
355+
356+
enterCharacter(input, 'A');
357+
358+
var activeSuggestions = suggestions.querySelectorAll('paper-item.active');
359+
var allSuggestions = suggestions.querySelectorAll('paper-item');
360+
361+
expect(allSuggestions).not.to.be.empty;
362+
expect(activeSuggestions).to.be.empty;
363+
});
364+
});
365+
335366
a11ySuite('basic', ['badAriaAttributeValue', 'nonExistentRelatedElement']);
336367

337368
// HELPERS

0 commit comments

Comments
 (0)