Skip to content

Commit

Permalink
fixes #1054 - underlying Tagify shoud not get focused when selecting …
Browse files Browse the repository at this point in the history
…a suggestion from a Tagify sugegstion dropdown which is rendered over it.

Also added a feature which slowing hiding the selected sugegstion istead of all-at-once
  • Loading branch information
Yair Even Or authored and Yair Even Or committed Jul 28, 2022
1 parent 0dbbfc9 commit b2aa6a7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/parts/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export default {

/**
* fill data into the suggestions list
* (mainly used to update the list when removing tags, so they will be re-added to the list. not efficient)
* (mainly used to update the list when removing tags while the suggestions dropdown is visible, so they will be re-added to the list. not efficient)
*/
refilter( value ){
value = value || this.state.dropdown.query || ''
Expand All @@ -231,7 +231,7 @@ export default {
this.dropdown.fill()

if( !this.suggestedListItems.length )
this.dropdown.hide()
setTimeout(this.dropdown.hide.bind(this)) // a timeout is sadly needed so a possible underlying Tagify won't get focused when selecting a suggestion

this.trigger("dropdown:updated", this.DOM.dropdown)
},
Expand Down Expand Up @@ -549,8 +549,17 @@ export default {
if( closeOnSelect ){
setTimeout(this.dropdown.hide.bind(this))
}
else
this.dropdown.refilter()

// hide selected suggestion
elm.addEventListener('transitionend', () => {
if( this.dropdown.filterListItems(this.state.dropdown.query || '') <= 1)
this.dropdown.hide()
}, {once: true})

elm.classList.add(this.settings.classNames.dropdownItemHidden)

// else
// this.dropdown.refilter()
},

// adds all the suggested items, including the ones which are not currently rendered,
Expand Down Expand Up @@ -584,9 +593,6 @@ export default {
var _s = this.settings,
_sd = _s.dropdown,
options = options || {},
value = (_s.mode == 'select' && this.value.length && this.value[0][_s.tagTextProp] == value
? '' // do not filter if the tag, which is already selecetd in "select" mode, is the same as the typed text
: value),
list = [],
exactMatchesList = [],
whitelist = _s.whitelist,
Expand All @@ -599,6 +605,10 @@ export default {
niddle,
i = 0;

value = (_s.mode == 'select' && this.value.length && this.value[0][_s.tagTextProp] == value
? '' // do not filter if the tag, which is already selecetd in "select" mode, is the same as the typed text
: value);

if( !value || !searchKeys.length ){
list = _s.duplicates
? whitelist
Expand Down
10 changes: 10 additions & 0 deletions src/tagify.scss
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,19 @@
background: var(--tagify-dd-color-primary);
color: white;
}

&:active{
filter: brightness(105%);
}

&--hidden{
padding-top: 0;
padding-bottom: 0;
margin: 0 1px;
font-size: 0;
pointer-events: none;
transition: .2s;
}
}
}
}

0 comments on commit b2aa6a7

Please sign in to comment.