TarekRaafat / autoComplete.js

Simple autocomplete pure vanilla Javascript library.
https://tarekraafat.github.io/autoComplete.js
Apache License 2.0
3.96k stars 240 forks source link

Autocomplete list open upwards when at the edge of the page #158

Closed cedbesafilm closed 3 years ago

cedbesafilm commented 3 years ago

Is your feature request related to a problem? Please describe. Now the autocomplete open downwards in evey situation, on mobile the user can not notice the list open

Thoroughly Describe the solution you'd like if the autocomplete is open at the lower limit of the page the list should open upwards

Please provide a few use cases for this feature

  1. on mobile the user can not notice the list open

Please Describe alternatives you've considered For now i'm studing a custom method when list renders

Additional context current behavior image

image

expected behavior This is and example take from a Select image

cedbesafilm commented 3 years ago

MY WORKAROUND

Pieces of code taken from ChoicesJS

Javascript

I use rendered event because in resultsList the property bottom is always 0 (maybe is not injected in the DOM already?)

      i.addEventListener("rendered", function() {
        var shouldFlip = false;
        var el = document.getElementById("autoComplete_list");
        var dropdownPos = el.getBoundingClientRect().bottom

        shouldFlip = !window.matchMedia("(min-height: " + (dropdownPos + 1) + "px)").matches;

        if (shouldFlip) {
          el.classList.add("is-flipped");
        }
      }, false);

CSS

#autoComplete_list.is-flipped {
  top: auto;
  bottom: 100%;
  margin-bottom: 0rem;
}

VISUAL

On lower edge image

mits87 commented 3 years ago

Also I have the same problem. Would be good if the plugin will support that out of the box

edj56 commented 3 years ago

Hello :) Yes, it would be great to have this feature, please take a look

amiregelz commented 2 years ago

@TarekRaafat Is there a way to always open the dropdown upwards? trying to figure out what CSS to apply