-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdropdownMenu.js
More file actions
28 lines (26 loc) · 828 Bytes
/
Copy pathdropdownMenu.js
File metadata and controls
28 lines (26 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
export const dropdownMenu = (selection, props) => {
const {
options,
onOptionClicked,
selectedOption,
dropdownClass
} = props;
let select = selection.selectAll('select').data([null]);
select = select.enter().append('select')
.merge(select)
.attr("class", () => {
if (dropdownClass)
return dropdownClass;
return "";
})
.on('change', function() {
onOptionClicked(this.value);
});
const option = select.selectAll('option').data(options);
option.enter().append('option')
.merge(option)
.attr('value', d => d)
.property('selected', d => d === selectedOption)
.text(d => d);
option.exit().remove();
}