Fixed #1362 - Added autoHighlight property to AutoComplete (#1429)

* Adding autoHighlight to first element in autocomplete

* Adding autoHighlight to first element in autocomplete

* Adding autoHighlight to first element in autocomplete

* Adding autoHighlight to first element in autocomplete

* Added autoHighlight to first element in autocomplete

* Added autoHighlight to first element in autocomplete: set default to false
pull/1544/head
Mouad Taoussi 2021-09-15 07:33:20 +01:00 committed by GitHub
parent 357b26178b
commit d9d871efb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 2 deletions

View File

@ -10,6 +10,7 @@ interface AutoCompleteProps {
scrollHeight?: string; scrollHeight?: string;
dropdown?: boolean; dropdown?: boolean;
dropdownMode?: string; dropdownMode?: string;
autoHighlight?: boolean;
multiple?: boolean; multiple?: boolean;
minLength?: number; minLength?: number;
delay?: number; delay?: number;

View File

@ -86,6 +86,10 @@ export default {
type: String, type: String,
default: 'blank' default: 'blank'
}, },
autoHighlight: {
type: Boolean,
default: false
},
multiple: { multiple: {
type: Boolean, type: Boolean,
default: false default: false
@ -321,6 +325,10 @@ export default {
}, },
showOverlay() { showOverlay() {
this.overlayVisible = true; this.overlayVisible = true;
setTimeout(()=>{
this.autoHighlightFirstItem()
},200)
}, },
hideOverlay() { hideOverlay() {
this.overlayVisible = false; this.overlayVisible = false;
@ -345,7 +353,6 @@ export default {
query: query query: query
}); });
}, },
onInputClicked(event) { onInputClicked(event) {
if(this.completeOnFocus) { if(this.completeOnFocus) {
this.search(event, '', 'click'); this.search(event, '', 'click');
@ -384,10 +391,16 @@ export default {
onBlur() { onBlur() {
this.focused = false; this.focused = false;
}, },
autoHighlightFirstItem() {
if (this.autoHighlight && this.suggestions && this.suggestions.length) {
const itemToHighlight = this.overlay.firstElementChild.firstElementChild
DomHandler.addClass(itemToHighlight, 'p-highlight')
}
},
onKeyDown(event) { onKeyDown(event) {
if (this.overlayVisible) { if (this.overlayVisible) {
let highlightItem = DomHandler.findSingle(this.overlay, 'li.p-highlight'); let highlightItem = DomHandler.findSingle(this.overlay, 'li.p-highlight');
switch(event.which) { switch(event.which) {
//down //down
case 40: case 40:

View File

@ -187,6 +187,12 @@ export default {
<td>blank</td> <td>blank</td>
<td>Specifies the behavior dropdown button. Default "blank" mode sends an empty string and "current" mode sends the input value.</td> <td>Specifies the behavior dropdown button. Default "blank" mode sends an empty string and "current" mode sends the input value.</td>
</tr> </tr>
<tr>
<td>autoHighlight</td>
<td>boolean</td>
<td>false</td>
<td>Highlights automatically the first item of the dropdown to be selected.</td>
</tr>
<tr> <tr>
<td>multiple</td> <td>multiple</td>
<td>boolean</td> <td>boolean</td>