6
6
import Component from '@glimmer/component' ;
7
7
import { assert } from '@ember/debug' ;
8
8
import { HdsTableScopeValues } from './types.ts' ;
9
- import type { HdsTableScope } from './types.ts' ;
9
+ import type { HdsTableScope , HdsTableThSortOrder } from './types.ts' ;
10
10
import type { HdsFormCheckboxBaseSignature } from '../form/checkbox/base' ;
11
+ import { action } from '@ember/object' ;
12
+ import { tracked } from '@glimmer/tracking' ;
11
13
12
14
export interface BaseHdsTableTrArgs {
13
15
Args : {
16
+ sortOrder ?: HdsTableThSortOrder ;
17
+ onClickSort ?: ( sortBy ?: string ) => void ;
18
+ // NEW ABOVE
14
19
isSelectable ?: boolean ;
15
20
isSelected ?: false ;
16
21
selectionAriaLabelSuffix ?: string ;
@@ -44,12 +49,24 @@ export interface SelectableHdsTableTrArgs extends BaseHdsTableTrArgs {
44
49
// Union type to combine both possible states
45
50
export type HdsTableTrArgs = BaseHdsTableTrArgs | SelectableHdsTableTrArgs ;
46
51
52
+ function getRowContainerElement (
53
+ element : HTMLTableRowElement
54
+ ) : HTMLElement | null {
55
+ let parent = element . parentElement ;
56
+
57
+ while ( parent && parent . tagName !== 'TABLE' ) {
58
+ if ( [ 'TBODY' , 'THEAD' ] . includes ( parent . tagName ) ) {
59
+ return parent ;
60
+ }
61
+
62
+ parent = parent . parentElement ;
63
+ }
64
+
65
+ return parent ;
66
+ }
47
67
export default class HdsTableTr extends Component < HdsTableTrArgs > {
48
- /**
49
- * @param selectionKey
50
- * @type {string }
51
- * @default undefined
52
- */
68
+ @tracked isHeaderRow = false ;
69
+
53
70
get selectionKey ( ) : string | undefined {
54
71
if ( this . args . isSelectable && this . args . selectionScope === 'row' ) {
55
72
assert (
@@ -60,4 +77,11 @@ export default class HdsTableTr extends Component<HdsTableTrArgs> {
60
77
}
61
78
return undefined ;
62
79
}
80
+
81
+ @action
82
+ didInsert ( element : HdsTableTrArgs [ 'Element' ] ) {
83
+ const rowContainer = getRowContainerElement ( element ) ;
84
+
85
+ this . isHeaderRow = rowContainer ?. tagName === 'THEAD' ;
86
+ }
63
87
}
0 commit comments