JavaScript Dropdown

The LemonadeJS Dropdown is a lightweight, high-performance JavaScript plugin with a reactive design. It offers various configurable options and integrates seamlessly with popular front-end frameworks like Vue, React, and Angular. The main key features include:

  • Autocomplete: Enables quick and efficient search functionality, allowing users to find options rapidly.
  • Grouping: Allows categorization of options into groups for organized and intuitive navigation.
  • Smart Loading: Optimizes performance by intelligently managing the DOM, ensuring exceptional responsiveness and efficiency, especially with large datasets.
  • Framework Compatibility: Its framework-neutral design guarantees easy integration across various technologies, ensuring a uniform platform experience.

Standalone Dropdown Component

Use LemonadeJS Dropdown directly in your Vue, React, or Angular applications for:

  • Form selectors and autocomplete inputs
  • Multi-select interfaces
  • Country/language pickers
  • Tag selectors and filters

Data Grid Dropdown Editor

For spreadsheet applications with advanced dropdown column editors, Jspreadsheet Pro uses LemonadeJS Dropdown as the underlying component:

  • Conditional Dropdowns: Options change based on other cell values
  • Dynamic Ranges: Link dropdowns to cell ranges (e.g., Sheet1!A1:A4)
  • Remote Search: Autocomplete from backend APIs with JWT support
  • Advanced Validation: Professional spreadsheet dropdown features

Explore Jspreadsheet Pro Dropdown Editor

Lightweight Alternative - Jsuites Dropdown

For simpler use cases without framework dependencies, Jsuites Dropdown offers:

  • Lightweight vanilla JavaScript
  • No build tools required
  • Simple API
  • Used by Jspreadsheet CE (community edition)

Explore Jsuites Dropdown

Open Source Spreadsheets - Jspreadsheet CE

For open-source spreadsheet projects, Jspreadsheet CE provides basic dropdown editors:

  • Community edition spreadsheet
  • Uses Jsuites Dropdown
  • MIT license

Explore Jspreadsheet CE


When to Use Each

ComponentBest ForFrameworkLicense
LemonadeJS DropdownStandalone forms, high-performance appsVue, React, AngularMIT
Jspreadsheet ProProfessional spreadsheets with advanced dropdown editorsAnyCommercial
Jsuites DropdownSimple forms, legacy projects, lightweight needsVanilla JSMIT
Jspreadsheet CEOpen source spreadsheets, basic dropdown editorsAnyMIT

Documentation

Installation

npm install @lemonadejs/dropdown

Settings

AttributeDescription
data: Item[]An array of options to be displayed. Each item should follow the structure defined in the ‘Item Details’ section.
multiple?: BooleanIf provided, enables the multiple selection mode, allowing users to select more than one option simultaneously.
autocomplete?: BooleanIf provided, enables the autocomplete feature, displaying an input field that allows users to filter and quickly find options in the Dropdown.
value?: StringRepresents the current value or selected option in the Dropdown.
type?: StringSpecifies the type of display the Dropdown will use. It can be “searchbar” for a search bar interface, “picker” for a selection picker, or “default” for the default dropdown appearance.
insert?: BooleanEnables the insert feature, allowing users to add a new option directly by typing the title text and clicking on the plus symbol.
format?: NumberData format type, usually in the form of { id: name } or { value: text }
width?: NumberSpecifies the width of the dropdown
placeholder?: StringPlaceholder text to guide users in the dropdown
url?: StringSpecifies the URL for fetching the data. Do not declare the data attribute for the url to function properly.
disabled?: BooleanDisabled the dropdown

Item Details

AttributeDescription
value?: Number|StringRepresents the identifier or unique value associated with the option.
group?: StringIndicates the group to which the option belongs, allowing for segregation and organization.
text?: StringDisplays the label or text associated with the option.
image?: StringSpecifies the image URL to be displayed alongside the option.
synonym?: String | String[]Words with the same meaning to help the search.
keywords?: String | String[]Keywords for easier item identification
disabled?: BooleanIndicates whether the item is currently disabled
color?: StringSpecifies the color associated with the item

Events

EventTrigger
onclose?: () => voidInvoked when the dropdown modal is closed.
onbeforeinsert?: (instance, Item) => voidInvoked before an item is added to the options through the insert feature.
oninsert?: (instance, Item) => voidInvoked after an item is added to the options through the insert feature.
onchange?: (instance, Item) => voidInvoked when the value changes.
onload?: (instance, Item) => voidInvoked when appended to the DOM.
onsearch?: (instance, Item) => voidInvoked when searching for an item.
onbeforesearch?: (instance, Item) => voidInvoked before initiating a search.
onopen?: (instance) => voidInvoked when the dropdown is opened.

Performance

Create a dropdown with 100000 items from a JSON list.

live
<html>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@lemonadejs/dropdown/dist/style.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@lemonadejs/modal/dist/style.min.css" />
<script src="https://cdn.jsdelivr.net/npm/lemonadejs/dist/lemonade.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@lemonadejs/dropdown/dist/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@lemonadejs/modal/dist/index.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/build/build/faker.min.js"></script>

<div id='root'></div>

<script>
let root = document.getElementById('root');
let data = [];

for (let i = 0; i < 100000; i++) {
    data.push({
        value: i,
        text: faker.commerce.productName()
    });
}

// Initial time before creating the table
let s = Date.now();

Dropdown(root, {
    data: data,
    value: 1,
    width: 260,
    autocomplete: true,
    onload: function() {
        let e = Date.now();
        let p = document.createElement('p');
        p.textContent = 'The dropown was created in: ' + (e - s) + 'ms';
        root.appendChild(p)
    },
});
</script>
</html>

Grouping and Multiple Selection

The dropdown supports categorizing options into lists, enhancing navigation and organization. It also allows multiple selections, enabling users to choose several options simultaneously for greater flexibility.

live
<html>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@lemonadejs/dropdown/dist/style.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@lemonadejs/modal/dist/style.min.css" />
<script src="https://cdn.jsdelivr.net/npm/lemonadejs/dist/lemonade.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@lemonadejs/dropdown/dist/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@lemonadejs/modal/dist/index.min.js"></script>

<div id='root'></div>

<script>
let root = document.getElementById('root');

Dropdown(root, {
    data: [
        { "text": "Red", "value": 1, "group": "Warm" },
        { "text": "Blue", "value": 2, "group": "Cool" },
        { "text": "Green", "value": 3, "group": "Cool" },
        { "text": "Yellow", "value": 4, "group": "Warm" },
        { "text": "Purple", "value": 5, "group": "Cool" },
        { "text": "Gray", "value": 6, "group": "Cool" }
    ],
    value: 1,
    width: 260,
    multiple: true,
});
</script>
</html>

Autocomplete and Inserting New Options

The dropdown includes an autocomplete feature for fast, type-based option searches. Its DOM management system ensures efficient performance with large datasets. Users can also directly insert new options, offering enhanced flexibility and convenience.

live
<html>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@lemonadejs/dropdown/dist/style.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@lemonadejs/modal/dist/style.min.css" />
<script src="https://cdn.jsdelivr.net/npm/lemonadejs/dist/lemonade.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@lemonadejs/dropdown/dist/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@lemonadejs/modal/dist/index.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/build/build/faker.min.js"></script>

<div id='root'></div>

<script>
let root = document.getElementById('root');

let d = [];
for (let i = 0; i < 1000; i++) {
    d.push({
        value: i,
        text: faker.commerce.productName(),
    });
}

Dropdown(root, {
    data: d,
    value: 1,
    width: 260,
    autocomplete: true,
    insert: true,
});
</script>
</html>

Codesandbox working examples

Here is more examples on codesandbox.