You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
we would want our users to be able to start typing in the input, and the dropdown would open and the user would continue to type in the search field (the previous keystrokes being reported in the search field).
It's the behaviour we had with a previous combobox component
Currently we have implemented this behaviour in a wrapper component as following (this is not the whole code of our wrapper component, only the related part) :
virtualSelect.addEventListener('keypress',this.onKeyPress)onKeyPress: function(e){varcharTyped=String.fromCharCode(e.which)/* we restrict event to letters, numbers and some usuals caracters, in order to avoid to open dropdown on tab key for example */if(/[a-zA-Z\d -()]/i.test(charTyped)){constisDropdownVisible=this.getIsDropdownVisible()if(!isDropdownVisible){virtualSelect.open()constsearchInput=this.getSearchInputElement()if(searchInput){searchInput.value=charTyped}}}},/** * Check if the dropdown is open, by checking visibility* There's no magic bullet in js to know if a element is visible, but rergarding virtualselect implementation* we can confidently rely on opacity*/getIsDropdownVisible: function(){constdropdownContainerElement=this.getDropdownContainerElement()constcomputedStyle=dropdownContainerElement&&window.getComputedStyle(dropdownContainerElement)returndropdownContainerElement&&!dropdownContainerElement.hidden&&computedStyle.opacity!=="0"},getDropdownContainerElement: function(){returndocument.querySelector('#__'+this.id+' .vscomp-dropbox-container')},getSearchInputElement: function(){/* search input is not a child of select in the domthus we have to get its id to be able to select itTo do that, we get the id of another element, with class vscomp-ele-wrapperFrom this element, we guess the id of search input elementExcerpt of html code : <div id="vscomp-ele-wrapper-4485" class="vscomp-ele-wrapper vscomp-wrapper has-search-input popup-position-center has-value focused" tabindex="0" role="combobox" aria-haspopup="listbox" aria-controls="vscomp-dropbox-container-4485" aria-expanded="true" aria-label="Options list" data-tabindex-value="0" data-tabindex-counter="1" aria-activedescendant=""> in this case search input will have l'id "vscomp-search-input-4485" */constwrapperElement=document.querySelector('#__'+this.id+` .vscomp-ele-wrapper`)if(!wrapperElement){console.error(`getDropdownContainerElement : impossible de trouver le wrapper element`)}constidParts=wrapperElement.id.split('-')constid=idParts[idParts.length-1]returndocument.querySelector(`#vscomp-search-input-${id}`)},
It works fine, but as you can see, it's cumbersome and if the implementation of virtual-select change, it will break.
For this reason, I think it would be better to implement a built-in behaviour.
The text was updated successfully, but these errors were encountered:
I start typing the letter "J" in the field named "Période début" and thanks to our implementation, the dropdown opens automatically and "J" is reported in the field search, and then I keep on typing :
01.09.2023_13.43.15_REC.mp4
abenhamdine
changed the title
open dropdown when the user start typing in input
open dropdown when the user starts typing in input
Sep 1, 2023
Hi,
we would want our users to be able to start typing in the input, and the dropdown would open and the user would continue to type in the search field (the previous keystrokes being reported in the search field).
It's the behaviour we had with a previous combobox component
Currently we have implemented this behaviour in a wrapper component as following (this is not the whole code of our wrapper component, only the related part) :
It works fine, but as you can see, it's cumbersome and if the implementation of virtual-select change, it will break.
For this reason, I think it would be better to implement a built-in behaviour.
The text was updated successfully, but these errors were encountered: