JSFiddle - React, Tailwind, and code Playground

by liquidmetalrob

HTML

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

<div class="dropdown">
<button onclick="dropDownMenu()" class="dropbtn">Change Date 
Filter</button>
  <div id="myDropdown" class="dropdown-content">
    <a href="#" onclick="return switchDateOptions();">Date Picker</a>
    <a href="#" onclick="return switchDateOptions();">Date Slider</a>
  </div>
</div>

CSS

.dropbtn {
    background-color: #3498DB;
    color: white;
    padding: 13px;
    font-size: 13px;
    border: none;
    position: absolute;
    right: -490px;
    top: 8px;
    background-color: #0076B1;
    border-radius: 25%;
    cursor: pointer;
    transition: 0.3s;
}

.dropbtn:hover, .dropbtn:focus {
    background-color: #2980B9;
}

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: white;
    min-width: 160px;
    overflow: auto;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
    right: -490px;
    top: 52px;
}

.dropdown-content a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
}

.dropdown a:hover {background-color: #ddd}

.show {display:block;}

JavaScript

function dropDownMenu() {
document.getElementById("myDropdown").classList.toggle("show");
}

// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
  if (!event.target.matches('.dropbtn')) {

var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
  var openDropdown = dropdowns[i];
  if (openDropdown.classList.contains('show')) {
    openDropdown.classList.remove('show');
  }
 }
 }
 }