Skip to content

Commit 3bce086

Browse files
committed
auto-select child elements in table when parent selected
1 parent 2dc7c2a commit 3bce086

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

packages/ui/src/elements/TreeView/NestedSectionsTable/index.scss

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@
158158
}
159159

160160
// When a selected section is followed by another selected section
161-
&__section--selected + &__section--selected &__cell {
161+
&__section--selected + &__section--selected &__cell,
162+
&__section--selected + &__section--selected-descendant &__cell,
163+
&__section--selected-descendant + &__section--selected &__cell,
164+
&__section--selected-descendant + &__section--selected-descendant &__cell {
162165
border-top: none;
163166

164167
&:first-child {
@@ -192,6 +195,30 @@
192195
}
193196
}
194197

198+
&__section--selected:has(+ &__section--selected-descendant),
199+
&__section--selected-descendant:has(+ &__section--selected),
200+
&__section--selected-descendant:has(+ &__section--selected-descendant) {
201+
.nested-sections-table__cell {
202+
&::after {
203+
content: '';
204+
position: absolute;
205+
bottom: -1px;
206+
left: 0;
207+
height: 1px;
208+
right: 0;
209+
background-color: var(--cell-inner-border-color);
210+
z-index: 1;
211+
}
212+
213+
&:first-child {
214+
border-bottom-left-radius: 0;
215+
}
216+
&:nth-last-child(2) {
217+
border-bottom-right-radius: 0;
218+
}
219+
}
220+
}
221+
195222
&__section {
196223
position: relative;
197224
display: table-row-group;
@@ -225,6 +252,16 @@
225252
--cell-inner-border-color: var(--theme-success-200);
226253
}
227254

255+
&__section--selected-descendant {
256+
--cell-bg-color: color-mix(in srgb, var(--theme-success-50) 40%, transparent);
257+
--cell-border-color: var(--theme-success-500);
258+
--cell-inner-border-color: var(--theme-success-200);
259+
}
260+
261+
&__section--selected-descendant.nested-sections-table__section--odd {
262+
--cell-bg-color: color-mix(in srgb, var(--theme-success-50) 40%, transparent);
263+
}
264+
228265
&__section--selected.nested-sections-table__section--dragging {
229266
opacity: 0.4;
230267
}

packages/ui/src/elements/TreeView/NestedSectionsTable/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ export const DivTableSection: React.FC<DivTableSectionProps> = ({
274274
isOdd && `${baseClass}__section--odd`,
275275
targetParentID === rowItem.rowID && `${baseClass}__section--target`,
276276
isRowSelected && `${baseClass}__section--selected`,
277+
hasSelectedAncestor && `${baseClass}__section--selected-descendant`,
277278
]
278279
.filter(Boolean)
279280
.join(' ')}
@@ -295,12 +296,15 @@ export const DivTableSection: React.FC<DivTableSectionProps> = ({
295296
>
296297
<div className={`${baseClass}__row-actions`}>
297298
<CheckboxInput
298-
checked={selectedRowIDs.includes(rowItem.rowID)}
299+
checked={selectedRowIDs.includes(rowItem.rowID) || hasSelectedAncestor}
299300
onToggle={
300301
((event: React.MouseEvent<HTMLElement>) => {
301-
onRowClick({ event, from: 'checkbox', row: rowItem })
302+
if (!hasSelectedAncestor) {
303+
onRowClick({ event, from: 'checkbox', row: rowItem })
304+
}
302305
}) as unknown as (event: React.ChangeEvent) => void
303306
}
307+
readOnly={hasSelectedAncestor}
304308
/>
305309
<DraggableWithClick
306310
disabled={

0 commit comments

Comments
 (0)