1. Import the Treeselect’s JavaScript and Stylesheet.
<link rel="stylesheet" href="./dist/treeselect-js.css" />
import Treeselect from '../dist/treeselect-js.mjs.js';
2. Create an empty DIV container to hold the Multi-Select dropdown box.
<div class="example" /> </div>
3. Define your nested options as follows:
const options = [
{
name: 'JavaScript',
value: 'JavaScript',
htmlAttr: {},
isGroupSelectable: true,
disabled: false,
children: [
{
name: 'React',
value: 'React',
children: [
{
name: 'React.js',
value: 'React.js',
children: []
},
{
name: 'React Native',
value: 'React Native',
children: []
}
]
},
{
name: 'Vue',
value: 'Vue',
children: []
}
]
},
{
name: 'HTML',
value: 'html',
children: [
{
name: 'HTML5',
value: 'HTML5',
children: []
},
{
name: 'XML',
value: 'XML',
children: []
}
]
}
] 4. Initialize the Treeselect and populate the Multi-Select dropdown box with the data you just created.
const treeselect = new Treeselect({
parentHtmlContainer: document.querySelector('.example'),
options: options,
}) 5. Available options to customize the Treeselect.
const treeselect = new Treeselect({
// parent container element
parentHtmlContainer: HTMLElement,
// an array of option values
value: [],
// define your options here
options: [],
// keep the tree select always open
alwaysOpen: true,
// open all options to this level
openLevel: 0,
// append the Treeselect to the body
appendToBody: false,
// shows selected options as tags
showTags: true,
// text to show if you use 'showTags'
tagsCountText: '{count} {tagsCountText}',
// shows remove icon
clearable: true,
// is searchable?
searchable: true,
// placeholder text
placeholder: 'Search...',
// text to display when no results found
emptyText: 'No results found...',
// converts multi-select to the single value select
isSingleSelect: false,
// returns groups if they selected instead of separate ids
isGroupedValue: false,
// All nodes in treeselect work as an independent entity.
// Check/uncheck action ignore children/parent updates workflow.
// Disabled nodes ignore children/parent workflow as well.
isIndependentNodes: false,
// It is impossible to select groups. You can select only leaves.
disabledBranchNode: false,
// mproves list rendering performance by using visibility-based optimizations and IntersectionObserver.
// Useful for efficiently rendering large lists.
isBoostedRendering: false,
// auto, top, bottom
direction: 'auto',
// all groups which have checked values will be expanded on the init.
expandSelected: false,
// The list saves the last scroll position before close. If you open the list your scroll will be on the previous position.
// If you set the value to false - the scroll will have position 0 and the first item will be focused every time.
saveScrollPosition: true,
// A class name for list.
listClassName: '',
// shows count of children near the group's name.
showCount: false,
// group options
grouped: true,
// element that appends to the end of the dropdown list
listSlotHtmlComponent: null,
// is dropdown list disabled?
disabled: false,
// add the list as a static DOM element
// this prop will be ignored if you use appendToBody.
staticList: false,
// id attribute for the accessibility.
id: '',
// { arrowUp, arrowDown, arrowRight, attention, clear, cross, check, partialCheck }
// object contains all svg icons
iconElements: {},
srcElement: null,
// callback and functions
inputCallback: (value) => void (undefined),
openCallback: (value) => void (undefined),
closeCallback: (value) => void (undefined),
nameChangeCallback: (value) => void (undefined),
searchCallback: (value) => void (undefined),
openCloseGroupCallback: (groupId: ValueOptionType, isClosed: boolean) => void (undefined)
mount: () => void,
updateValue: (newValue: ValueOptionType[]) => void,
destroy: () => void,
focus: () => void,
toggleOpenClose: () => void,
}) 6. Events.
treeselect.srcElement.addEventListener('input', (e) => {
// ...
})
treeselect.srcElement.addEventListener('open', (e) => {
// ...
})
treeselect.srcElement.addEventListener('close', (e) => {
// ...
})
treeselect.srcElement.addEventListener('name-change', (e) => {
// ...
})
treeselect.srcElement.addEventListener('search', (e) => {
// ...
})
treeselect.srcElement.addEventListener('open-close-group', (e) => {
// ...
}) 7. API methods.
// update options treeselect.updateValue(Array[String]); // remount and update settings treeselect.mount(); // toggle between open & close treeselect.toggleOpenClose(); // set focus on treeselect input without open/close state changes. treeselect.focus(); // destroy the instance treeselect.destroy();
v0.13.1 (04/12/2025)
v0.13.0 (03/06/2025)
v0.12.3 (03/06/2025)
v0.12.2 (03/04/2025)
v0.12.1 (02/22/2025)
v0.12.0 (01/13/2025)
v0.11.0 (06/17/2024)
v0.10.0 (11/19/2023)
v0.9.3 (09/24/2023)
v0.9.1 (07/11/2023)
v0.9.0 (06/06/2023)
v0.8.6 (04/19/2023)
v0.8.5 (04/18/2023)
v0.8.4 (04/16/2023)
v0.8.2 (04/16/2023)
v0.8.1 (04/14/2023)
v0.8.0 (04/12/2023)
v0.7.0 (03/27/2023)
v0.6.0 (03/20/2023)
v0.5.8 (01/30/2023)
v0.5.7 (12/16/2022)
v0.5.6 (11/03/2022)
v0.5.5 (11/01/2022)
v0.5.4 (11/01/2022)
v0.5.3 (10/15/2022)
v0.5.2 (10/04/2022)
v0.5.1 (10/03/2022)
v0.5.0 (09/30/2022)
v0.4.3 (09/08/2022)
v0.4.2 (09/06/2022)
v0.4.1 (09/05/2022)
v0.4.0 (09/05/2022)
v0.3.6 (08/24/2022)
v0.3.3 (07/29/2022)
v0.3.2 (07/28/2022)
v0.3.1 (07/23/2022)
v0.2.9 (07/07/2022)
v0.2.8 (07/02/2022)
v0.2.7 (06/30/2022)
v0.2.6 (06/29/2022)
The post Multi-Select Box With Tree Structured Data Dropdown List – Treeselect appeared first on CSS Script.
Just days ago, a game came out whose unlikely premise has already drawn a good…
The LPGA Tour will bring the 2026 Mizuho Americas Open to Mountain Ridge Country Club…
Broadway Hot & Honey Chicken throws open its doors Saturday, March 21, at 11 a.m.…
New Jersey bans tint on windshields and front windows. Cars, SUVs, and vans must keep…
Swetha and Top.Domains hit the longevity jackpot. Swetha just posted on X that she sold…
Eric Lyon posted an interesting poll over at Namepros. Sellers thinking about how their buyers…
This website uses cookies.