File tree 5 files changed +26
-3
lines changed
packages/components/src/components/hds/advanced-table
showcase/tests/integration/components/hds/advanced-table
5 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,16 @@ import { focusable, tabbable } from 'tabbable';
8
8
import type { HdsAdvancedTableTdSignature } from './td' ;
9
9
import type { HdsAdvancedTableThSignature } from './th' ;
10
10
11
+ export const onFocusTrapDeactivate = ( cell : HTMLDivElement ) => {
12
+ const cellTabbableChildren = tabbable ( cell ) ;
13
+
14
+ for ( const child of cellTabbableChildren ) {
15
+ child . setAttribute ( 'tabindex' , '-1' )
16
+ }
17
+
18
+ cell . setAttribute ( 'tabindex' , '0' )
19
+ }
20
+
11
21
export const didInsertGridCell = (
12
22
cell :
13
23
| HdsAdvancedTableThSignature [ 'Element' ]
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import { focusable, type FocusableElement } from 'tabbable';
11
11
12
12
import type { HdsAdvancedTableHorizontalAlignment } from './types.ts' ;
13
13
import { HdsAdvancedTableHorizontalAlignmentValues } from './types.ts' ;
14
- import { didInsertGridCell , handleGridCellKeyPress } from './helpers.ts' ;
14
+ import { didInsertGridCell , handleGridCellKeyPress , onFocusTrapDeactivate } from './helpers.ts' ;
15
15
16
16
export const ALIGNMENTS : string [ ] = Object . values (
17
17
HdsAdvancedTableHorizontalAlignmentValues
@@ -77,6 +77,7 @@ export default class HdsAdvancedTableTd extends Component<HdsAdvancedTableTdSign
77
77
78
78
@action onFocusTrapDeactivate ( ) : void {
79
79
this . _shouldTrapFocus = false ;
80
+ onFocusTrapDeactivate ( this . _element )
80
81
}
81
82
82
83
@action enableFocusTrap ( ) : void {
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ import type {
21
21
HdsAdvancedTableThSortOrderLabels ,
22
22
} from './types.ts' ;
23
23
import type { HdsAdvancedTableThButtonSortSignature } from './th-button-sort' ;
24
- import { didInsertGridCell , handleGridCellKeyPress } from './helpers.ts' ;
24
+ import { didInsertGridCell , handleGridCellKeyPress , onFocusTrapDeactivate } from './helpers.ts' ;
25
25
26
26
export const ALIGNMENTS : string [ ] = Object . values (
27
27
HdsAdvancedTableHorizontalAlignmentValues
@@ -92,6 +92,7 @@ export default class HdsAdvancedTableThSort extends Component<HdsAdvancedTableTh
92
92
93
93
@action onFocusTrapDeactivate ( ) : void {
94
94
this . _shouldTrapFocus = false ;
95
+ onFocusTrapDeactivate ( this . _element )
95
96
}
96
97
97
98
@action enableFocusTrap ( ) : void {
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ import type {
15
15
HdsAdvancedTableScope ,
16
16
} from './types.ts' ;
17
17
import { HdsAdvancedTableHorizontalAlignmentValues } from './types.ts' ;
18
- import { didInsertGridCell , handleGridCellKeyPress } from './helpers.ts' ;
18
+ import { didInsertGridCell , handleGridCellKeyPress , onFocusTrapDeactivate } from './helpers.ts' ;
19
19
20
20
export const ALIGNMENTS : string [ ] = Object . values (
21
21
HdsAdvancedTableHorizontalAlignmentValues
@@ -104,6 +104,8 @@ export default class HdsAdvancedTableTh extends Component<HdsAdvancedTableThSign
104
104
105
105
@action onFocusTrapDeactivate ( ) : void {
106
106
this . _shouldTrapFocus = false ;
107
+ onFocusTrapDeactivate ( this . _element )
108
+
107
109
}
108
110
109
111
@action enableFocusTrap ( ) : void {
Original file line number Diff line number Diff line change @@ -331,6 +331,15 @@ module(
331
331
// cells should not be focusable anymore
332
332
assert . dom ( '.hds-advanced-table__th[tabindex="0"]' ) . doesNotExist ( ) ;
333
333
assert . dom ( '.hds-advanced-table__td[tabindex="0"]' ) . doesNotExist ( ) ;
334
+
335
+ await triggerKeyEvent ( firstCellSortButton , 'keydown' , 'Escape' ) ;
336
+ assert . dom ( firstCell ) . hasAttribute ( 'tabindex' , '0' ) ;
337
+ assert . dom ( firstCellSortButton ) . hasAttribute ( 'tabindex' , '-1' ) ;
338
+
339
+ // content within cells should not be focusable anymore
340
+ assert
341
+ . dom ( '[data-advanced-table-child-focusable=""][tabindex="0"]' )
342
+ . doesNotExist ( ) ;
334
343
} ) ;
335
344
336
345
test ( 'it should trap focus inside a cell when not in navigation mode' , async function ( assert ) {
You can’t perform that action at this time.
0 commit comments