BVSelect-VanillaJS - BVSelect - Vanilla Javascript Fully Customizable SelectBox

Overview

BVSelect - Vanilla JS


Replaces native select elements with fully customizable dropdowns.

Demo:

https://bmsvieira.github.io/BVSelect-VanillaJS/

Features:

  • 🔧 Fully Customizable
  • 💪 No Dependencies, built with VanillaJS
  • 🌎 Tested in All Modern Browsers
  • 😎 Images & FontIcons
  • ⌨️ Mobile Optimization & Normal Usage
  • 🔎 Built-in Searchbox
  • 🖥 Prevented Viewport Overflow

Installation:

1 - Include JavaScript Source.

<script src="path/to/bvselect.js"></script>

2 - Include Styles.

<link rel="stylesheet" href="path/to/bvselect.css">

4 - Set HTML.

<select id="selectbox">
  <option data-separator="true"> Select Option </option>
  <option value="1"> Option 1 </option>
  <option value="2"> Option 2 </option>
  <option value="3" disabled> Option 3 </option>
  <option value="4"> Option 4 </option>
</select>

3 - Initilize.

document.addEventListener("DOMContentLoaded", function() {
      var demo1 = new BVSelect({
        selector: "#selectbox",
        width: "100%",
        searchbox: true,
        offset: true,
        placeholder: "Select Option",
        search_placeholder: "Search...",
        search_autofocus: true,
        breakpoint: 450
      });
});

Polyfill:

BVSelect uses ES6 which isn't supported in all browsers yet (especially older browsers). Some features will need to be polyfilled to be available. Use the following sources instead:

// Polyfill Source
<script src="https://polyfill.io/v3/polyfill.min.js?features=document.querySelector%2Cdocument%2CArray.prototype.forEach%2CNodeList.prototype.forEach%2CElement.prototype.closest%2CArray.from%2Ces5"></script>

// BVSelect Polyfilled Version
<script src="path/to/bvselect.polyfill.js"></script>

Methods:

Destroy: Removes dropdown, unbinds all its events and brings back the original Select.

demo1.Destroy();

Update: Updates current dropdown based on changes to the original selectbox.

demo1.Update();

Get ID: Returns the ID that was generated to build dropdown, so you can add custom classes.

demo1.GetID();

Set Option: Set new selected option.

Name Value Description
type byIndex or byValue Parameter
value string Value to search
demo1.SetOption({
  type: "byIndex",
  value: "1"
});

Change: Changes dropdown's settings

Name Value Description
placeholder string Modify dropdown's placeholder
search_placeholder string Modify input's placelholder
options object Replaces all options in the original selectbox
demo1.Change({
  placeholder: "New Placeholder",
  search_placeholder: "New Searchbox's Placeholder",
  options : {
          0: {
              inner_text: 'Metallica',
              value: "met",
              disabled: false,
              separator: false,
              img: "https://img.icons8.com/color/2x/usa.png",
              icon: "fa fa-hashtag"
          },
          1: {
              inner_text: 'Megadeth',
              value: "meg",
              disabled: false,
              separator: false,
              img: false,
              icon: "fa fa-tshirt"
          },
          2: {
              inner_text: 'Slayer',
              value: "sla",
              disabled: false,
              separator: false,
              img: false,
              icon: "fa fa-hashtag"
          }  
    }
});

// Update Dropdown based on changes to the original selectbox
demo1.Update();

Append Option: Add new options to existing selectbox

Name Value Description
position afterbegin or beforeend Add new options at beginning or ending of the dropdown
options object Options to add to original selectbox
demo1.AppendOption({
    position: "beforeend",
    options : {
            0: {
                inner_text: 'Metallica',
                value: "met",
                disabled: false,
                separator: false,
                img: "https://img.icons8.com/color/2x/usa.png",
                icon: "fa fa-hashtag"
            },
            1: {
                inner_text: 'Megadeth',
                value: "meg",
                disabled: false,
                separator: false,
                img: false,
                icon: "fa fa-tshirt"
            }
      }
  });

// Update Dropdown based on changes to the original selectbox
demo1.Update();

Settings:

Name Value Default Description
selector ID --- Specify ID of the element
width px or % 100% Specify the width of the main element
searchbox boolean false Add a search box to the list
offset boolean true Fixes Viewport Offset
placeholder string Select Option Modify dropdown's placeholder
search_placeholder string Search... Modify input's placelholder
search_autofocus boolean false Automatically focus on search input if enabled
breakpoint integer 600 Defines the responsive breakpoint (in px)
document.addEventListener("DOMContentLoaded", function() {
      var demo1 = new BVSelect({
        selector: "#selectbox",
        searchbox: true,
        offset: true
      });
});

Attributes:

Name Value Description
data-separator boolean Highlights an option
data-img Image Source Adds an Image to option
data-icon fa fa-hashtag Adds an FontIcon to option, can be used any provider as long it is identical. Images will be prioritized over icons.
disabled (native) disabled Disables an option

To add FontIcons, you must include it's own sources

<select id="selectbox">
    <option value="##" data-separator="true" selected>Select Option</option>
    <option data-img="path/to/img.png" value="--">Cristiano Ronaldo</option>
    <option data-icon="fa fa-hashtag" value="--" >Lionel Messi </option>
    <option data-img="path/to/img.png" value="--" disabled>Neymar Jr. (Disabled)</option>
    <option data-img="path/to/img.png" value="--">Ronaldinho</option>
    <option data-img="path/to/img.png" value="--">Luis Figo</option>
</select>

All CSS styles are fully customizable in order to match your style

Appearance

This was built to fit any style and to be 100% fully customizable, so you are able to change everything in the css file.

Comments
  • Automatic focus into search field after opening

    Automatic focus into search field after opening

    Additional to #1: If the dropdown is opened using mouse click and the search field has been enabled, it the keyboard focus should be set into the search field immediately?

    enhancement 
    opened by mmokross 1
  • It is without accessibility.

    It is without accessibility.

    Some things that are important to add: 1 - Aria attributes 2 - Keyboard navigation 3 - Mobile close button (X)

    I really like these libraries to create customized fields, but we have to take great care not to forget accessibility.

    enhancement 
    opened by Hai-San 0
  • Dynamicly creation option elements breaks when value contain spaces

    Dynamicly creation option elements breaks when value contain spaces

    When option elements are created dynamicly, the values need to be encapsulated. Right now, this is not the case, resulting in broken html when values contain spaces.

    To fix this, change:

                    document.getElementById(this.selector).insertAdjacentHTML('beforeend',
                        "<option "+change_img+" "+change_icon+" "+change_separator+" "+change_disabled+" value="+properties.options[i].value+" >"+properties.options[i].inner_text+"</option>");
    

    To:

                    document.getElementById(this.selector).insertAdjacentHTML('beforeend',
                        "<option "+change_img+" "+change_icon+" "+change_separator+" "+change_disabled+" value=\""+properties.options[i].value+"\" >"+properties.options[i].inner_text+"</option>");
    
    opened by AforDesign 0
  • Suggestion - Setting for custom output elements

    Suggestion - Setting for custom output elements

    First of all, thank you for this awesome class.

    I have a request / suggestion for a future enhancement: It would be nice to be able to overrule the html output via the settings.

    For example: I stumbled upon a performance issue when dealing with a list of 1500 items including image previews. Allthough the image are only a few kb, i t's quite a performance hit. Therefor I needed to lazy-load them. To be able to do that I had to modify the source code.

     // Check for Attachment
     if (optionImg) {
        var has_attachment = "<img data-src=" + optionImg + " class='lazyload'>";
    } 
    

    No big deal ofcourse, but it would be super nice if such alteration could be added to the settings object.

    opened by AforDesign 2
  • Uncaught ReferenceError: BVSelect is not defined

    Uncaught ReferenceError: BVSelect is not defined

    I have loaded the BVSelect JS and CSS files into my Javascript ES6 file and created a #selectbox element.

    When I try to use new BVSelect() it fails with:

    Uncaught ReferenceError: BVSelect is not defined

    The browser shows that the .js and .css files are loaded succesfully and my code intellisense does pick up the BVSelect class.

    Here's my javascript:

        $(`
        <select id="selectbox">
          <option data-separator="true"> Select Option </option>
          <option value="1"> Option 1 </option>
          <option value="2"> Option 2 </option>
          <option value="3" disabled> Option 3 </option>
          <option value="4"> Option 4 </option>
        </select>`).appendTo(this.$contentDiv);
    
        var demo = new BVSelect('#selectbox'); 
    
    opened by TestO2015 0
  • Show images for selected item

    Show images for selected item

    An image can be added to each menu entry, but this does not get displayed for the selected item in the top selection.

    Can this be added as the selected item displayed at the top should reflect the line item content for better presentation.

    Please see the example below.

    Thanks

    image

    enhancement 
    opened by MohsenAlyafei 1
  • no keyboard navigation

    no keyboard navigation

    Was looking into this to see if I should recommend it to a friend. Being a11y friendly is always a big deal. I noticed that I cannot use this with keyboard navigation. I cannot open a selectbox with a keyboard trigger and I cannot tab to select boxes.

    I get this is your open source project and not making any demands, just saying that accessibility is an important aspect of choosing a select control with actual legal implications in the US (for the site that uses it). You might consider either prioritizing these features or clearly stating the limitation at the top of the readme

    enhancement 
    opened by togakangaroo 2
Releases(bvselectv1.4)
Owner
Bruno Vieira
“Make it work, make it right, make it fast.” – Kent Beck
Bruno Vieira
Pure JavaScript (VanillaJS) dropdown menu, with multiple select and searching support

JS Select Pure JavaScript (VanillaJS) dropdown menu, with multiple select and searching support How to use To use the select plugins, two main file mu

Luigi Verolla 4 Mar 17, 2022
This is an VanillaJS SPA example with function based rendering.

Function-Based-Rendering This is an VanillaJS SPA example with function based rendering. Here's how to create Views by function composition and how to

강호형 3 Oct 16, 2021
VanillaJS implementation of an animated rising / falling number.

number-rollup Demo https://marknorrapscm.github.io/number-rollup/ Features Smooth rising / falling number animations with easing options VanillaJS Zer

null 14 Jul 27, 2021
A fully configurable & customizable Remix PWA stack.

Remix RockSpec Stack Learn more about Remix Stacks. npx create-remix --template ShafSpecs/rockspec-stack What's in the stack Fly app deployment with

Abdur-Rahman 54 Dec 18, 2022
LogTure - A minimal designed, fully customizable, and extensible modern personal blogging framework, built with Nextjs.

LogTure - A minimal designed, fully customizable, and extensible modern personal blogging framework, built with Nextjs.

Sam Zhang 14 Aug 26, 2022
Fully controllable vanilla-js material design ripple effect generator.

Fully controllable vanilla-js material design ripple effect generator. This can be used with any JavaScript framework and/or any CSS framework. Demo I

71 Dec 16, 2022
This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js

This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js. But in most cases, I would recommend you to use something like Express in a production project for productivity purposes.

Eduardo Dantas 7 Jul 19, 2022
A lightweight, fully-featured, modular, typescript-compatible javascript library for Paymongo.

paymongo.js A lightweight, fully-featured, modular, typescript-compatible javascript library for PayMongo. Installation npm install paymongo.js # or y

Prince Carlo Juguilon 15 Nov 23, 2022
A fully type-safe and lightweight internationalization library for all your TypeScript and JavaScript projects.

?? typesafe-i18n A fully type-safe and lightweight internationalization library for all your TypeScript and JavaScript projects. Advantages ?? lightwe

Hofer Ivan 1.3k Jan 4, 2023
This is a simple javascript file that gives you control over the browser cursor, alowing for fully animated cursors using CSS's cursor functionality.

animatedWebCursors.js This is a simple javascript file that gives you control over the browser cursor, alowing for fully animated cursors using CSS's

alienmelon 32 Dec 25, 2022
🔧 Alternative to 'eval' in JavaScript that is customizable and safer!

?? better-eval An alternative to eval() in JavaScript that is customizable and safer! The eval function sucks, and there lacks alternatives that provi

Bharadwaj Duggaraju 32 Sep 14, 2022
A lightweight, modern and customizable JavaScript slider library.

NSlider NSlider is a lightweight (< 10 KB), modern and customizable JavaScript slider library. CDN Development https://cdn.jsdelivr.net/gh/fatihege/ns

Fatih 6 Jan 20, 2022
This simple library allows you to create awesome responsive and highly customizable popups importing just one JavaScript file.

Creativa - Popup This is a simple library that allows you to create awesome popups importing just one JavaScript file. Getting started You can import

Eduardo Mollo 5 Mar 29, 2022
A beautiful, responsive, highly customizable and accessible replacement for JavaScript's popup boxes. Zero dependencies.Alerts ,dialogs

AsgarAlert (v1) for JS Install <script defer src="/asgar-alert.js"></script> Examples The most basic message: asgar("Hello world!"); A message signali

Asgar Aliyev 5 Dec 20, 2022
The JavaScript library let’s you transform native tooltip’s into customizable overlays.

iTooltip The JavaScript library let’s you transform native tooltip’s into customizable overlays. Use: <script src="/path/to/iTooltip.js"></script> <sc

null 2 Dec 17, 2021
Navigation-Menu-Javascript - A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked.

Navigation-Menu-Javascript A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked. Desktop view Mobile v

Ellis 2 Feb 16, 2021
MenuSlider-Javascript - How to create a menu slider with vanilla javascript

MenuSlider-Javascript How to create a menu slider with vanilla javascript Instal

Tarokh Mohammadi 1 Feb 8, 2022
Leader Board is a simple project based on JavaScript programing language. The purpose of this project is to work with APIs and ASYNC & AWAIT methods. I have used vanilla JavaScript with web pack to implement this project

Leader Board - JavaScript Project Table of contents Overview The challenge Screenshot Links Project Setup commands My process Built with What I learne

Mahdi Rezaei 7 Oct 21, 2022
Fully dockered starter kit for Elm with Hasura

elm-hasura-dockered This repo contains a Elm-Hasura starter kit for rapid+typesafe web application development on open source foundations. Elm is grea

Cies Breijs 41 Dec 9, 2022