The MultiLevelSelect kit renders a multi leveled select dropdown based on data from the user. treeData
is a required prop that is expected to contain the data in the form of an array of objects. See code snippet for an example data array.
For the React version of the kit, the onSelect
prop returns an array of objects. This array contains all checked items irrespective of whether it is a parent, child or grandchild. Open the console on this example and check and uncheck checkboxes to see this is action!
For the Rails version of the kit, there is no onselect. The form submits as a array of strings, following the typical rails pattern of utilizing hidden inputs. The strings are the values of the selected items' ids. For example, ["103", "106", "107"].
<% treeData = [{ label: "Power Home Remodeling", value: "Power Home Remodeling", id: "100", expanded: true, children: [ { label: "People", value: "People", id: "101", expanded: true, children: [ { label: "Talent Acquisition", value: "Talent Acquisition", id: "102", }, { label: "Business Affairs", value: "Business Affairs", id: "103", children: [ { label: "Initiatives", value: "Initiatives", id: "104", }, { label: "Learning & Development", value: "Learning & Development", id: "105", }, ], }, { label: "People Experience", value: "People Experience", id: "106", }, ], }, { label: "Contact Center", value: "Contact Center", id: "107", children: [ { label: "Appointment Management", value: "Appointment Management", id: "108", }, { label: "Customer Service", value: "Customer Service", id: "109", }, { label: "Energy", value: "Energy", id: "110", }, ], }, ], }] %> <%= pb_rails("multi_level_select", props: { id: "multi-level-select-default-rails", name: "my_array", tree_data: treeData }) %>
Optionally enable the single
variant to replace checkboxes with radios so the input accepts and returns only a single selection.
<% treeData = [ { label: "HQ", value: "HQ", id: "hq", }, { label: "Philadelphia", value: "Philadelphia", id: "phl", children: [ { label: "Marketing & Sales PHL", value: "Marketing & Sales PHL", id: "marketingPHL", }, { label: "Installation Office PHL", value: "Installation Office PHL", id: "installationPHL", }, { label: "Warehouse PHL", value: "Warehouse PHL", id: "warehousePHL", }, ] }, { label: "New Jersey", value: "New Jersey", id: "nj", children: [ { label: "New Jersey", value: "New Jersey", id: "nj1", children: [ { label: "Marketing & Sales NJ", value: "Marketing & Sales NJ", id: "marketingNJ", }, { label: "Installation Office NJ", value: "Installation Office NJ", id: "installationNJ", }, { label: "Warehouse NJ", value: "Warehouse NJ", id: "warehouseNJ", }, ], }, { label: "Princeton", value: "Princeton", id: "princeton", children: [ { label: "Marketing & Sales Princeton", value: "Marketing & Sales Princeton", id: "marketingPR", }, { label: "Installation Office Princeton", value: "Installation Office Princeton", id: "installationPR", }, { label: "Warehouse Princeton", value: "Warehouse Princeton", id: "warehousePR", }, ] }, ] }, { label: "Maryland", value: "Maryland", id: "MD", children: [ { label: "Marketing & Sales MD", value: "Marketing & Sales MD", id: "marketingMD", }, { label: "Installation Office MD", value: "Installation Office MD", id: "installationMD", }, { label: "Warehouse MD", value: "Warehouse MD", id: "warehouseMD", }, ] }, { label: "Connecticut", value: "Connecticut", id: "CT", children: [ { label: "Marketing & Sales CT", value: "Marketing & Sales CT", id: "marketingCT", }, { label: "Installation Office CT", value: "Installation Office CT", id: "installationCT", }, { label: "Warehouse CT", value: "Warehouse CT", id: "warehouseCT", }, ] }, ]; %> <%= pb_rails("multi_level_select", props: { id: "multi-level-select-single-rails", name: "my_single_select_array", tree_data: treeData, input_name: "Power", variant: "single" }) %>
Dynamically control your selectable options by passing hideRadio: true
to any node within your tree data to omit that node's radio selector. In this example we've hidden all radios except ultimate children (nodes without descendants).
<% treeData = [ { label: "HQ", value: "HQ", id: "hq1", }, { label: "Philadelphia", value: "Philadelphia", id: "phl1", hideRadio: true, children: [ { label: "Marketing & Sales PHL", value: "Marketing & Sales PHL", id: "marketingPHL1", }, { label: "Installation Office PHL", value: "Installation Office PHL", id: "installationPHL1", }, { label: "Warehouse PHL", value: "Warehouse PHL", id: "warehousePHL1", }, ] }, { label: "New Jersey", value: "New Jersey", id: "nj2", hideRadio: true, children: [ { label: "New Jersey", value: "New Jersey", id: "nj3", hideRadio: true, children: [ { label: "Marketing & Sales NJ", value: "Marketing & Sales NJ", id: "marketingNJ1", }, { label: "Installation Office NJ", value: "Installation Office NJ", id: "installationNJ1", }, { label: "Warehouse NJ", value: "Warehouse NJ", id: "warehouseNJ1", }, ], }, { label: "Princeton", value: "Princeton", id: "princeton1", hideRadio: true, children: [ { label: "Marketing & Sales Princeton", value: "Marketing & Sales Princeton", id: "marketingPR1", }, { label: "Installation Office Princeton", value: "Installation Office Princeton", id: "installationPR1", }, { label: "Warehouse Princeton", value: "Warehouse Princeton", id: "warehousePR1", }, ] }, ] }, { label: "Maryland", value: "Maryland", id: "MD1", hideRadio: true, children: [ { label: "Marketing & Sales MD", value: "Marketing & Sales MD", id: "marketingMD1", }, { label: "Installation Office MD", value: "Installation Office MD", id: "installationMD1", }, { label: "Warehouse MD", value: "Warehouse MD", id: "warehouseMD1", }, ] }, { label: "Connecticut", value: "Connecticut", id: "CT1", hideRadio: true, children: [ { label: "Marketing & Sales CT", value: "Marketing & Sales CT", id: "marketingCT1", }, { label: "Installation Office CT", value: "Installation Office CT", id: "installationCT1", }, { label: "Warehouse CT", value: "Warehouse CT", id: "warehouseCT1", }, ] }, ]; %> <%= pb_rails("multi_level_select", props: { id: "multi-level-select-single-children-only-rails", name: "my_single_children_only_select_array", tree_data: treeData, input_name: "PowerChildren", variant: "single" }) %>
The returnAllSelected
or return_all_selected
prop can be used when users want data on all checked nodes from the dropdown, irrespective of whether it is a parent or child node.
NOTE: This variant also does not automatically uncheck the parent when any of the child nodes are unchecked. returnAllSelected
is set to false by default.
NOTE: For larger trees that may return many pill selections, you can optionally set input_display: "none"
(for Rails) or inputDisplay = "none"
(for React) to hide all pills within the input.
<% treeData = [{ label: "Power Home Remodeling", value: "Power Home Remodeling", id: "100", expanded: true, children: [ { label: "People", value: "People", id: "101", children: [ { label: "Talent Acquisition", value: "Talent Acquisition", id: "102", }, { label: "Business Affairs", value: "Business Affairs", id: "103", children: [ { label: "Initiatives", value: "Initiatives", id: "104", }, { label: "Learning & Development", value: "Learning & Development", id: "105", }, ], }, { label: "People Experience", value: "People Experience", id: "106", }, ], }, { label: "Contact Center", value: "Contact Center", id: "107", children: [ { label: "Appointment Management", value: "Appointment Management", id: "108", }, { label: "Customer Service", value: "Customer Service", id: "109", }, { label: "Energy", value: "Energy", id: "110", }, ], }, ], }] %> <%= pb_rails("multi_level_select", props: { id: "multi-level-select-return-all-selected-rails", name: "my_data_array", tree_data: treeData, return_all_selected: true }) %>
selected_ids
is an optional prop that accepts an array of ids that, if present, will mark the corresponding nodes on the treeData as checked on page load.
Items that include checked:true
on the treeData itself will also be selected on page load, even without being passed to selectedIds
.
When an item is marked as checked on page load by any means, the dropdown will expand to show the checked items for easier accessibility.
<% treeData = [{ label: "Power Home Remodeling", value: "Power Home Remodeling", id: "100", expanded: true, children: [ { label: "People", value: "People", id: "101", children: [ { label: "Talent Acquisition", value: "Talent Acquisition", id: "102", }, { label: "Business Affairs", value: "Business Affairs", id: "103", children: [ { label: "Initiatives", value: "Initiatives", id: "104", }, { label: "Learning & Development", value: "Learning & Development", id: "105", }, ], }, { label: "People Experience", value: "People Experience", id: "106", }, ], }, { label: "Contact Center", value: "Contact Center", id: "107", children: [ { label: "Appointment Management", value: "Appointment Management", id: "108", }, { label: "Customer Service", value: "Customer Service", id: "109", }, { label: "Energy", value: "Energy", id: "110", }, ], }, ], }] %> <%= pb_rails("multi_level_select", props: { id: "multi-level-select-seelcted_ids", name: "my_data_array_selected", return_all_selected: true, selected_ids:["110","102"], tree_data: treeData, }) %>
<%= pb_form_with(scope: :example, url: "", method: :get) do |form| %> <% treeData = [{ label: "Power Home Remodeling", value: "Power Home Remodeling", id: "powerhome1", expanded: true, children: [ { label: "People", value: "People", id: "people1", children: [ { label: "Talent Acquisition", value: "Talent Acquisition", id: "talent1", }, { label: "Business Affairs", value: "Business Affairs", id: "business1", children: [ { label: "Initiatives", value: "Initiatives", id: "initiative1", }, { label: "Learning & Development", value: "Learning & Development", id: "development1", }, ], }, { label: "People Experience", value: "People Experience", id: "experience1", }, ], }, { label: "Contact Center", value: "Contact Center", id: "contact1", children: [ { label: "Appointment Management", value: "Appointment Management", id: "appointment1", }, { label: "Customer Service", value: "Customer Service", id: "customer1", }, { label: "Energy", value: "Energy", id: "energy1", }, ], }, ], }] %> <%= form.multi_level_select :example, props: {id: "with-form-multi-level-select", tree_data: treeData, return_all_selected: true, margin_bottom: "sm" } %> <%= form.actions do |action| %> <%= action.button props: { type: "submit", text: "Submit", variant: "primary", margin_top: "lg" } %> <% end %> <% end %>
Change the form pill color by passing the optional pill_color
prop. Product, Data, and Status colors are available options. Check them out here in the Form Pill colors example.
<% treeData = [{ label: "Power Home Remodeling", value: "Power Home Remodeling", id: "100", expanded: true, children: [ { label: "People", value: "People", id: "101", expanded: true, children: [ { label: "Talent Acquisition", value: "Talent Acquisition", id: "102", }, { label: "Business Affairs", value: "Business Affairs", id: "103", children: [ { label: "Initiatives", value: "Initiatives", id: "104", }, { label: "Learning & Development", value: "Learning & Development", id: "105", }, ], }, { label: "People Experience", value: "People Experience", id: "106", }, ], }, { label: "Contact Center", value: "Contact Center", id: "107", children: [ { label: "Appointment Management", value: "Appointment Management", id: "108", }, { label: "Customer Service", value: "Customer Service", id: "109", }, { label: "Energy", value: "Energy", id: "110", }, ], }, ], }] %> <%= pb_rails("multi_level_select", props: { id: "multi-level-select-default-rails", name: "my_array", tree_data: treeData, pill_color: "neutral" }) %>
In order to clear the multilevelselect selection using an external trigger (like a reset button), the clearMultiLevelSelect
function can be used. See the code snippet below to see this in action. The function is scoped by id so an id MUST be used on the multilevelselect kit and passed to the function as shown for it to work.
<% treeData = [{ label: "Power Home Remodeling", value: "Power Home Remodeling", id: "100", expanded: true, children: [ { label: "People", value: "People", id: "101", expanded: true, children: [ { label: "Talent Acquisition", value: "Talent Acquisition", id: "102", }, { label: "Business Affairs", value: "Business Affairs", id: "103", children: [ { label: "Initiatives", value: "Initiatives", id: "104", }, { label: "Learning & Development", value: "Learning & Development", id: "105", }, ], }, { label: "People Experience", value: "People Experience", id: "106", }, ], }, { label: "Contact Center", value: "Contact Center", id: "107", children: [ { label: "Appointment Management", value: "Appointment Management", id: "108", }, { label: "Customer Service", value: "Customer Service", id: "109", }, { label: "Energy", value: "Energy", id: "110", }, ], }, ], }] %> <%= pb_rails("multi_level_select", props: { id: "multi-level-select-reset-example", name: "my_array", tree_data: treeData, return_all_selected: true }) %> <%= pb_rails("button", props: { text: "Reset", margin_top: "lg", id:"multilevelselect-reset-button" }) %> <script> window.addEventListener('DOMContentLoaded', () => { const exampleResetButton = document.querySelector("#multilevelselect-reset-button"); exampleResetButton.addEventListener("click", () => { clearMultiLevelSelectById('multi-level-select-reset-example'); }); function clearMultiLevelSelectById(id) { const clearFunction = window[`clearMultiLevelSelect_${id}`]; if (clearFunction) { clearFunction(); } else { console.warn(`No clear function found for MultiLevelSelect with id: ${id}`); } } }) </script>
Props | Type | Values |
---|---|---|
max_width |
array
|
0%
xs
sm
md
lg
xl
xxl
0
none
100%
|
min_width |
array
|
0%
xs
sm
md
lg
xl
xxl
0
none
100%
|
width |
array
|
0%
xs
sm
md
lg
xl
xxl
0
none
100%
|
z_index |
array
|
1
2
3
4
5
6
7
8
9
10
|
number_spacing |
array
|
tabular
|
shadow |
array
|
none
deep
deeper
deepest
|
line_height |
array
|
tightest
tighter
tight
normal
loose
looser
loosest
|
display |
array
|
block
inline_block
inline
flex
inline_flex
none
|
cursor |
array
|
auto
default
none
contextMenu
help
pointer
progress
wait
cell
crosshair
text
verticalText
alias
copy
move
noDrop
notAllowed
grab
grabbing
eResize
nResize
neResize
nwResize
sResize
seResize
swResize
wResize
ewResize
nsResize
neswResize
nwseResize
colResize
rowResize
allScroll
zoomIn
zoomOut
|
flex_direction |
array
|
row
column
rowReverse
columnReverse
|
flex_wrap |
array
|
wrap
nowrap
wrapReverse
|
justify_content |
array
|
start
end
center
spaceBetween
spaceAround
spaceEvenly
|
justify_self |
array
|
auto
start
end
center
stretch
|
align_items |
array
|
flexStart
flexEnd
start
end
center
baseline
stretch
|
align_content |
array
|
start
end
center
spaceBetween
spaceAround
spaceEvenly
|
align_self |
array
|
auto
start
end
center
stretch
baseline
|
flex |
array
|
auto
initial
0
1
2
3
4
5
6
7
8
9
10
11
12
none
|
flex_grow |
array
|
1
0
|
flex_shrink |
array
|
1
0
|
order |
array
|
1
2
3
4
5
6
7
8
9
10
11
12
|
position |
array
|
relative
absolute
fixed
sticky
|
hover |
array
|
|
border_radius |
array
|
none
xs
sm
md
lg
xl
rounded
|
text_align |
array
|
start
end
left
right
center
justify
justify-all
match-parent
|
overflow |
array
|
visible
hidden
scroll
auto
|
truncate |
array
|
1
2
3
4
5
|
left |
array
|
0
xxs
xs
sm
md
lg
xl
auto
initial
inherit
|
top |
array
|
0
xxs
xs
sm
md
lg
xl
auto
initial
inherit
|
right |
array
|
0
xxs
xs
sm
md
lg
xl
auto
initial
inherit
|
bottom |
array
|
0
xxs
xs
sm
md
lg
xl
auto
initial
inherit
|
vertical_align |
array
|
baseline
super
top
middle
bottom
sub
text-top
text-bottom
|
height |
array
|
auto
xs
sm
md
lg
xl
xxl
xxxl
|
min_height |
array
|
auto
xs
sm
md
lg
xl
xxl
xxxl
|
max_height |
array
|
auto
xs
sm
md
lg
xl
xxl
xxxl
|
overflow_x |
array
|
visible
hidden
scroll
auto
|
overflow_y |
array
|
visible
hidden
scroll
auto
|
margin |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_bottom |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_left |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_right |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_top |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_x |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_y |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_bottom |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_left |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_right |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_top |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_x |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_y |
array
|
none
xxs
xs
sm
md
lg
xl
|
classname |
string
|
|
dark |
boolean
|
|
group_hover |
boolean
|
|
data |
hashprop
|
|
aria |
hashprop
|
|
html_options |
hashprop
|
|
children |
proc
|
|
style |
hashprop
|
Props | Type | Values | Default |
---|---|---|---|
id |
string
|
||
name |
string
|
||
tree_data |
array
|
||
return_all_selected |
boolean
|
false
|
|
selected_ids |
array
|
||
input_display |
enum
|
pills
none
|
pills
|
input_name |
string
|
||
variant |
enum
|
multi
single
|
multi
|
pill_color |
enum
|
primary
neutral
success
warning
error
info
data_1
data_2
data_3
data_4
data_5
data_6
data_7
data_8
windows
siding
roofing
doors
gutters
solar
insulation
accessories
|
primary
|