Skip to content

Commit 1a78166

Browse files
committed
Add indeterminate state support for checkboxes in tree view
1 parent 9924cf9 commit 1a78166

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/treeviewRenderService.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const renderService: ITreeViewRenderService = {
3131
checkbox.id = `cb-${node.nodeId}`;
3232
checkbox.type = 'checkbox';
3333
checkbox.checked = node.checked;
34+
checkbox.indeterminate = node.numVisibleEntities > 0 && !node.checked;
3435
checkbox.style.pointerEvents = 'all';
3536
if (checkHandler) checkbox.addEventListener('change', checkHandler);
3637
wrapperDiv.appendChild(checkbox);
@@ -124,12 +125,18 @@ const renderService: ITreeViewRenderService = {
124125
isChecked: (element: HTMLInputElement) => {
125126
return element.checked;
126127
},
127-
setCheckbox: (nodeId, checked) => {
128+
setCheckbox: (nodeId, checked, indeterminate = false) => {
128129
const checkbox = document.getElementById(`cb-${nodeId}`) as HTMLInputElement;
129130
if (checkbox) {
130131
if (checked !== checkbox.checked) {
131132
checkbox.checked = checked;
132133
}
134+
if (indeterminate !== checkbox.indeterminate) {
135+
checkbox.indeterminate = indeterminate;
136+
if (indeterminate) {
137+
checkbox.checked = false;
138+
}
139+
}
133140
}
134141
},
135142
setXRayed: () => {

0 commit comments

Comments
 (0)