css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="wrapper">
  <input class="input" type="text" placeholder="Type a color..." data-list="Black,White,Red,Yellow,Green,Pink,Blue,Orange,Grey,Purple,Turquoise,Crimson" />
  <span class="arrow-up"></span>
  <ul class="list"></ul>
</div>
            
          
!
            
              html {
  box-sizing: border-box;
}

*,
*:before,
*:after {
  box-sizing: inherit;
  padding: 0;
  margin: 0;
  list-style: none;
}

body {
  background: #fff;
  font-family:helvetica;
}

h2 {
  text-align: center;
  color: #444;
  margin-top: 20px;
}

.wrapper {
  width: 220px;
  padding: 10px;
  margin: 50px auto;
  position: relative;
}

.input {
  width: 200px;
  height: 38px;
  padding: 5px 10px;
  font-size: 16px;
  color: #555;
  border: 1px solid #b1b1b1;
  border-radius: 5px;
  outline: none;
  position: relative;
  transition: all 0.25s linear;
}

.input:focus {
  border: 1px solid #777;
}

.list {
  position: absolute;
  width: 200px;
  top: 50px;
  max-height: 250px;
  overflow-x: scroll;
  background: rgba(33, 33, 33, .7);
  color: #fff;
  border-radius: 5px;
  overflow-x: hidden;
  visibility: hidden;
  opacity: 0;
  transition: all 0.25s linear;
  transform: translateY(10px);
}

.list li {
  padding: 6px 10px;
  cursor: pointer;
  font-size: 15px;
}

.list li:hover {
  background: rgba(33, 33, 33, 0.3);
}

.arrow-up {
  width: 0px;
  height: 0px;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-bottom: 10px solid rgba(33, 33, 33, .7);
  position: absolute;
  top: 40px;
  left: 20px;
  visibility: hidden;
  opacity: 0;
  transition: all 0.25s linear;
  transform: translateY(10px);
}

.show {
  visibility: visible;
  opacity: 1;
  transform: translateY(0px);
}

.hide {
  visibility: hidden;
  opacity: 0;
  transform: translateY(5px);
  //transition-duration: 0.15s;
  transition:none;
}

.selecting {
  background: rgba(33, 33, 33, 0.3);
}
            
          
!
            
              var input = document.querySelector(".input");
var list = document.querySelector(".list");
var arrow = document.querySelector(".arrow-up");
var data_list = input.getAttribute("data-list");
var selecting = -1;
var list_li;

// Make data list array
data_list = data_list.split(",");

var typing_arr = [];

input.addEventListener("keyup", function(e) {
  list.innerHTML = '';
  var typing = data_list;

  // Filter data-list array 
  typing = typing.filter(function(item) {
    return item.toLowerCase().search(e.target.value.toLowerCase()) != -1;
  });

  // If value empty hide list and arrow
  if (e.target.value === "" || typing.length === 0) {
    list.classList.add("hide");
    list.classList.remove("show");

    arrow.classList.add("hide");
    arrow.classList.remove("show");
  } else {
    list.classList.remove("hide");
    list.classList.add("show");
    
    arrow.classList.remove("hide");
    arrow.classList.add("show");
  }

  typing_arr = typing;

  // Show filtered data-list
  typing_arr.map(function(list_item) {
    var li = document.createElement("li");
    list.appendChild(li);
    li.innerHTML = list_item;

    // Close list when click on li and make clicked li input value
    li.addEventListener("click", function(e) {
      input.value = e.target.textContent;
      list.classList.add("hide");
      arrow.classList.add("hide");
    });

    // Close list when click enter and make selecting li input value
    if (e.which == 13 || e.keyCode == 13) {
      if (selecting > -1) {
        input.value = list_li[selecting].textContent;
        list.classList.add("hide");
        arrow.classList.add("hide");
      }
    }

  });

  // Down and up buttons
  if (e.which == 40 || e.keyCode == 40) {
    selecting++;

    list_li = list.querySelectorAll("li")
    if (selecting + 1 > list_li.length) {
      selecting = 0;
    }

    list_li[selecting].classList.add("selecting");

    // When input value change, make selecting -1
    input.addEventListener("input", function(e) {
      selecting = -1;
    });

  } else if (e.which == 38 || e.keyCode == 38) {
    selecting--;

    list_li = list.querySelectorAll("li")
    if (selecting < 0) {
      selecting = list_li.length - 1;
    }

    list_li[selecting].classList.add("selecting");
  }

  // Keep selecting class when press a button
  list_li = list.querySelectorAll("li")
  list_li[selecting].classList.add("selecting");

});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console