All files / lib/table table.component.ts

91.94% Statements 1244/1353
87.64% Branches 234/267
88.75% Functions 71/80
91.94% Lines 1244/1353

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 13541x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x           1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 455x 455x 1x 1x           1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2684x 2684x 2684x 2684x 2684x 2684x 2684x 2684x 2684x 2684x 2684x 2684x 2684x 2684x 2684x 27511x 27511x 3063x 24448x 24448x 27511x 2684x 2684x 27511x 27511x 2684x 2684x 6905x 6905x 6905x 6905x 6905x 6905x 6905x 6905x 6905x 6905x 2684x 2684x 2684x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 951x 951x 951x 951x 951x 951x 951x 10954x 10954x 777x 10177x 10177x 10954x 951x 951x 10191x 10191x 951x 951x 5511x 5511x 5511x 5511x 5511x 5511x 5511x 5511x 951x 951x 951x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x 1x 65x 65x 1x 1x 1x 1590x 1590x 1590x 11x 11x 1590x 1590x 1590x 1590x 1590x 1590x 1590x 1590x 1x 1x 1x 1x 1x 1x 49403x 49403x 49403x 1x 1x 155x 155x 155x 6x 16x 6x 155x 155x 1x 1x 1x 3144x 4x 3140x 3140x 1542x 1598x   1598x 1598x 3144x 3144x 1x 1x 1x 1x 1x 1x       1x 1x       1x 1x 15215x 80x 21x 59x 59x 15135x 15135x 7300x 7835x 7835x 15215x 15215x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 130x 130x 130x 130x 1x 1x 3x 3x 3x 3x 3x 3x 3x         3x 3x 3x 3x     3x 3x 1x 1x 1x 27511x 27511x 27511x 27511x 27511x 27511x 1x 1x 1x 10954x 10954x 10954x 10954x 10954x 6257x 10954x 10954x 1x 1x 1x 44x 44x 44x 44x 44x 44x 44x 1x 1x 1x 1x 32029x 32029x 32029x 32029x 32029x 29550x 32029x 32029x 32029x 1x 1x 1x 15146x 15146x 1x 1x 1x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 130x 109x 109x 109x 109x 130x 130x 130x 130x 130x 130x 130x 130x 130x 126x 130x 130x 130x 130x 130x 130x 130x 1x 1x 1x 1590x 18x 1572x 130x 130x 130x 130x 1590x 1590x 1590x 1x 1x 1x                                 1x 1x 1x 207x 161x 207x 207x 68x 207x 207x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 2x 2x 2x 2x 1x 1x 1x 3x 3x         3x 3x 3x 1x 1x 1x 27913x 565x 27348x 27348x 27913x 1x 1x 1x 22x 22x 1x 1x 1x 5099x 5099x 1x 1x 1590x 1590x 1590x 1590x 1572x   1572x 1590x 1590x 1590x 1590x 1590x 10954x 10954x 10954x 10954x         10954x 2331x 8623x 2385x 6238x 3903x 2335x 2335x 1590x 1590x 1590x 1590x 1x 1x 99x 11x 11x 88x 88x 88x 99x 1x 1x 324x 36x   36x 36x 36x 288x 288x 36x 36x 252x 252x 252x 324x 1x 1x 7950x 7950x 7950x 1x 1x 1x 1x 1x 3x 3x 1x 1x 38465x   38465x   38465x 38465x 38465x 38465x 1x 1x 14x 14x 14x 14x 36x 36x 36x 11x 14x 14x 14x 14x 1x 1x 38465x 38465x 38465x 38465x 38465x 1x 1x 38465x 38465x   38465x 38465x 38465x 38465x 1x 1x 126349x   126349x 126349x 126349x 1x 1x 38465x   38465x 38465x 38465x 1x 1x 126349x   126349x 126349x 126349x 1x 1x 38465x   38465x 38465x 38465x 1x 1x               1x 1x             1x 1x 1x 109x 109x 109x 17x 17x 17x 17x 61x 13x 13x 13x 13x 73x 32x 32x 32x 32x 75x 12x 12x 12x 12x 77x 1x 1x 1x 1x 1x 1x 1x 1x 1x 109x 109x 1x 1x 6234x   6234x 6234x 6234x 1x 1x 142x 142x 12x 142x 142x 142x 135x 200x 200x 200x 135x 135x 135x 135x 135x 135x 135x 7x 142x 142x 1x 1x 342x 335x 335x 335x 7x 7x 7x 342x 342x 1x 1x 3x 3x 3x 3x         3x 3x 3x   3x 3x 3x         3x 3x 3x 3x 1x 1x 1x       1x 1x 198x 3x 3x 195x 195x 198x 198x 1x 1x 1x 158x 158x 1x 1x 1x 288x 288x 288x 1x 1x 1x 32x 32x 32x 32x 32x 32x   32x 32x 32x 28x 32x 32x 32x 1x 1x 1x 12x 12x 12x 12x 8x 12x 12x 12x 1x 1x 1x 17x 17x 17x 11x 11x 11x 11x 17x 17x 17x 17x 1x 1x 1x 13x 13x 13x 13x 13x 13x   13x 13x 11x 11x 11x 11x 13x 13x 13x 13x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 126x 126x 126x 1111x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 70x 70x 70x 126x 2x 2x 2x   2x 2x       2x 2x 126x 126x 126x 126x 1x 1x 1x 126x 126x 126x 70x 70x 70x 126x 126x 126x 124x 124x 124x 124x 124x 124x 124x 124x 124x 124x 124x 124x 124x 124x 124x 126x 1x 1x 1x 1x 1x 1x 1x 1x 1x 62x 62x 62x 62x 62x 32x 32x 32x 32x 32x 32x 8x 8x 8x 8x 8x 8x 8x 8x 8x 32x 24x 24x 18x 18x 18x 6x 6x 3x 3x 3x 24x 24x 24x 24x 24x   24x 24x 24x 32x 32x 30x 30x 30x 30x 30x 30x 30x 30x 30x 16x 14x 14x 30x 30x 30x 30x 30x 30x 30x 30x 62x 1x 1x 1x 1x 1x 1x 1x 32x 32x 32x 32x 32x 32x 32x 32x 32x 12x 12x 12x 12x 26x 2x 2x 2x 2x 2x 2x 2x 2x   2x 2x 26x 26x 32x 1x 1x 1x 1x 1x 1x 1x 12x 12x 12x 12x 12x 12x 12x 10x 12x 12x 12x 12x 12x                               12x 1x 1x 1x 126x 126x 126x 126x 126x 68x 68x 68x 68x 58x 58x 58x 56x 58x 58x 58x 58x 126x 126x 1x 1x 1x 161x 161x 4x 4x 4x 4x 157x 157x 67x   67x 67x 90x 4x 4x 86x 86x 86x 161x 161x 1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
import {
  AfterViewChecked,
  AfterViewInit,
  Component,
  ContentChildren,
  Directive,
  ElementRef,
  EventEmitter,
  HostBinding,
  Input,
  NgZone,
  OnChanges,
  OnDestroy,
  Output,
  QueryList,
  SimpleChanges,
  TemplateRef,
  ViewChild,
  ViewChildren,
  inject,
} from '@angular/core';
 
import {
  getKeyboardFocusableElements,
  observeSize,
  relativeTo,
  subscribeOutsideZone,
  subscribeWindow,
  waitForRender,
} from '../utils/internal-utils';
import {
  Callback,
  FocusableElementOwner,
  Item,
  ItemGroup,
  StructuredControlState,
} from '../utils/util.types';
import { isItem, itemTrack } from '../utils/utilities';
 
import {
  AriaLiveReadDisposer,
  AriaLiveReaderComponent,
} from '../internal/aria-live-reader/aria-live-reader.component';
import { TextHighlightService } from '../internal/text-highlight/text-highlight.component';
 
import { ButtonContentDisplay } from '../button/button.component';
import {
  TableCellContext,
  TableColumn,
  TableHeaderCellContext,
} from './table.common';
 
export * from './table.common';
 
@Directive({
  selector: 'ng-template[td-template-for]', // eslint-disable-line @angular-eslint/directive-selector -- old occurence, change requires API breakage
  standalone: false,
})
export class TableTdTemplateDirective<T> {
  @Input('td-template-for')
  public templateFor!: string;
  constructor(public readonly template: TemplateRef<TableCellContext<T>>) {}
 
  static ngTemplateContextGuard<T>(
    dir: TableTdTemplateDirective<T>,
    ctx: unknown,
  ): ctx is TableCellContext<T> {
    return true;
  }
}
 
interface TmpCell<T> {
  column: TableColumn<T>;
  item?: T;
  label: string;
  rowIndex: number;
  colIndex: number;
}
 
@Directive({
  //eslint-disable-next-line @angular-eslint/directive-selector -- old occurence, change requires API breakage (not critical due to ng-template, just preferreable for consistency)
  selector: 'ng-template[th-template-for]',
  standalone: false,
})
export class TableThTemplateDirective<T> {
  @Input('th-template-for')
  public templateFor!: string;
  constructor(
    public readonly template: TemplateRef<TableHeaderCellContext<T>>,
  ) {}
 
  static ngTemplateContextGuard<T>(
    dir: TableThTemplateDirective<T>,
    ctx: unknown,
  ): ctx is TableHeaderCellContext<T> {
    return true;
  }
}
 
@Directive({
  selector: '[data-gc-int-td]',
  exportAs: 'tdCtx',
  standalone: false,
})
export class TableCellDirective<T> implements TableCellContext<T> {
  @Input('col')
  public col!: TableColumn<T>;
 
  @Input('row')
  public row!: T;
 
  @Input('colIdx')
  public colIdx!: number;
 
  @Input('rowIdx')
  public rowIdx!: number;
 
  @Input('stickyOffset')
  @HostBinding('style.--gc-table-sticky-offset.px')
  public stickyOffset = 0;
 
  @HostBinding('style.text-align')
  get alignment(): string {
    if (this.col.alignment == 'right-decimal') {
      return 'right';
    }
    return this.col.alignment;
  }
 
  public get $implicit(): TableCellContext<T> {
    return this;
  }
 
  public get cell(): TmpCell<T> {
    const label = this.col.label ? this.col.label(this.row) : 'null';
    return {
      column: this.col,
      item: this.row,
      rowIndex: this.rowIdx,
      colIndex: this.colIdx,
 
      label,
    };
  }
 
  public readonly el: ElementRef<HTMLElement> = inject<ElementRef<HTMLElement>>(
    ElementRef<HTMLElement>,
  );
}
 
@Directive({
  selector: 'th[data-gc-table-int-th]',
  exportAs: 'thCtx',
  standalone: false,
})
export class TableHeaderDirective<T> implements TableHeaderCellContext<T> {
  @Input('col')
  public col!: TableColumn<T>;
  @Input('colIdx')
  public colIdx!: number;
  @Input('stickyOffset')
  @HostBinding('style.--gc-table-sticky-offset.px')
  public stickyOffset = 0;
 
  @HostBinding('style.text-align')
  get alignment(): string {
    if (this.col.alignment === 'right-decimal') {
      return 'right';
    }
    return this.col.alignment;
  }
 
  public get $implicit(): TableHeaderCellContext<T> {
    return this;
  }
 
  public get cell(): TmpCell<T> {
    return {
      column: this.col,
      item: undefined,
      rowIndex: 0,
      colIndex: this.colIdx,
      label: this.col.title,
    };
  }
 
  public readonly el: ElementRef<HTMLElement> = inject<ElementRef<HTMLElement>>(
    ElementRef<HTMLElement>,
  );
}
 
/** A group of table items. */
export interface TableItemGroup<T> extends ItemGroup<T> {
  /**
   * Override the total number of entries within the group, if not set the current number of items is used.
   * Count may be different from the number of current items in case of pagination.
   */
  entryCount?: {
    /** Total number of items in this group. */
    totalEntryCount: number;
    /** Index of the first item in the current list within the complete group. */
    offset: number;
  };
}
 
type DisplayState =
  | 'empty' // Show a single cell with text
  | 'loading' // Show a single cell with a loading spinner
  | 'search-empty' // Show a single cell with text, with table-headers
  | 'search-loading' // Show a single cell with a loading spinner, with table-headers
  | 'default'; // Display a table with rows
 
const DEFAULT_COL_MIN_WIDTH = 100;
 
/**
 * A Table component.
 */
@Component({
  selector: 'gc-table',
  templateUrl: './table.component.html',
  styleUrls: ['./table.component.css'],
  providers: [TextHighlightService],
  standalone: false,
})
export class TableComponent<T>
  implements
    FocusableElementOwner,
    AfterViewInit,
    AfterViewChecked,
    OnDestroy,
    OnChanges
{
  /** Title of the table. Visibility depends on the `showLabel` input. */
  @Input()
  public label = '';
 
  /**
   * If `true`, the label will be visible as heading above the table. Otherwise, the information will
   * be visually hidden and only available for accessibility utilities.
   */
  @Input()
  public showLabel = false;
 
  /**
   * Items displayed in the settings menu (menu-button is not visible, when `settingsMenuItems` is undefined or empty)
   */
  @Input()
  public settingsMenuItems?: readonly Item[];
 
  /**
   * Items displayed next to the settings menu
   */
  @Input()
  public functionItems?: readonly Item[];
 
  /** Optional icon provider to use for the function buttons */
  @Input()
  public functionItemIconProvider?: TemplateRef<{ $implicit: Item }>;
 
  /**
   * Event emitted when an item is selected
   */
  @Output()
  public readonly onFunctionItemAction: EventEmitter<Item> =
    new EventEmitter<Item>();
 
  /** The columns of the table */
  @Input()
  public columns: readonly TableColumn<T>[] = [];
 
  /** Pager template slot*/
  @Input()
  public pagerTemplate: TemplateRef<Record<string, never>> | null = null;
 
  /**
   * Override the total number of entries, if not set the current number of items is used.
   * Count may be different from the number of current items in case of pagination.
   */
  @Input()
  public totalEntryCount?: number;
 
  /** If set to `true` the header columns are sticky and will remain visible when the table content scrolls. */
  @Input()
  @HostBinding('class.gc-with-sticky-header')
  public stickyHeaderColumns = false;
 
  /**
   * Set a fixed height on the content area of the table, specified as a number of rows to always reserve space for.
   * Only used when data is present, does not affect the height of empty tables or related states. When the space needed
   * to display the provided data exceeds the fixed height, the table content may scroll.
   * @see stickyHeaderColumns
   */
  @Input()
  public fixedContentHeight?: number;
 
  /** Marks the table as required. The table should contain selectable option when this is used. */
  @Input()
  @HostBinding('class.gc-state-required')
  public required = false;
 
  /** Hint message that appears within the table caption. */
  @Input()
  public hint = '';
 
  /**
   * Error message which is part of the table caption.
   */
  @Input()
  public errorMessage = '';
 
  /** Used to display additional content (in particular extra error messages) in the error section of the table. */
  @Input()
  public errorContentTemplate?: TemplateRef<Record<string, never>>;
 
  /** Used to display a confirmation-banner on top of the table. */
  @Input()
  public confirmationBannerTemplate: TemplateRef<Record<string, never>> | null =
    null;
 
  /**
   * Changes the state of the table.
   * Possible optional states are:
   * - loading: indicates that the table is in a loading state.
   * - search: indicates that the table is in an ongoing search context/state.
   */
  @Input()
  public state: StructuredControlState = {
    loading: false,
    search: false,
  };
 
  @Input()
  public fixedStartColumns = 0;
 
  @Input()
  public fixedEndColumns = 0;
 
  /**
   * Action that is fired when clicked on item in table-settings-menu
   */
  @Output()
  public readonly onSettingsMenuAction: EventEmitter<Item> =
    new EventEmitter<Item>();
 
  /** @ignore */
  @ViewChildren(TableHeaderDirective)
  public thElements?: QueryList<TableHeaderDirective<T>>;
 
  /** @ignore */
  @ViewChildren(TableCellDirective)
  public tdElements?: QueryList<TableCellDirective<T>>;
 
  /** @ignore */
  @ContentChildren(TableThTemplateDirective)
  public thTemplates!: QueryList<TableThTemplateDirective<T>>;
 
  /** @ignore */
  @ContentChildren(TableTdTemplateDirective)
  public tdTemplates!: QueryList<TableTdTemplateDirective<T>>;
 
  /** @ignore */
  @ViewChild('thDefaultTemplate')
  public thDefaultTemplate!: TemplateRef<TableHeaderCellContext<T>>;
 
  /** @ignore */
  @ViewChild('tdDefaultTemplate')
  public tdDefaultTemplate!: TemplateRef<TableCellContext<T>>;
 
  /** @ignore */
  @ViewChild('table')
  public table!: ElementRef<HTMLTableElement>;
 
  /** @ignore */
  @ViewChild('header')
  public header?: ElementRef<HTMLElement>;
 
  /** @ignore */
  @ViewChild('ariaLiveRegion')
  private ariaLiveRegion?: AriaLiveReaderComponent;
 
  /** The text which should be highlighted through the table. */
  @Input()
  public get highlightString(): string | undefined {
    return this.textHighlightService.highlightString;
  }
 
  public set highlightString(val: string | undefined) {
    this.textHighlightService.highlightString = val;
  }
 
  /** @ignore */
  @HostBinding('style.--gc-table-fixed-content-height.px')
  public get _fixedContentHeight(): number | undefined {
    if (
      this.fixedContentHeight === undefined ||
      this.isEmpty() ||
      this.state.loading
    ) {
      return undefined;
    } else {
      const headerHeight = 41;
      const rowHeight = 73;
      return headerHeight + rowHeight * this.fixedContentHeight;
    }
  }
 
  /**
   * The items of the table. If group items are supplied, items of each group are displayed in separate blocks
   * within the table.
   */
  @Input()
  public get items(): readonly T[] | readonly TableItemGroup<T>[] {
    return this._items;
  }
 
  public set items(value: readonly T[] | readonly TableItemGroup<T>[]) {
    this._items = value;
 
    if (this._isTableItemGroup(this._items)) {
      this.allRowsFlattened = this._items.reduce<T[]>((acc, curr) => {
        return [...acc, ...curr.items];
      }, []);
    }
  }
 
  /** @ignore */
  public get _totalEntryCount(): number {
    if (this.state.loading) {
      return 0;
    }
    if (this.totalEntryCount !== undefined) {
      return this.totalEntryCount;
    } else if (this._isTableItemGroup(this.items)) {
      return this.items.reduce((sum, group) => sum + group.items.length, 0);
    } else {
      return this.items.length;
    }
  }
 
  /**
   * Set to true if the data is currently loading.
   * @deprecated - use new *state* input instead.
   */
  @Input()
  public get isLoading(): boolean {
    return this._isLoading;
  }
 
  public set isLoading(value: boolean) {
    this._isLoading = value;
    this.state = { ...this.state, loading: value ? 'default' : false };
  }
 
  protected get displayState(): DisplayState {
    if (this.state.loading) {
      if (this.state.search) {
        return 'search-loading';
      } else {
        return 'loading';
      }
    } else if (this.state.search) {
      return this.isEmpty() ? 'search-empty' : 'default';
    } else {
      return this.isEmpty() ? 'empty' : 'default';
    }
  }
 
  /** @ignore */
  smallActions = false;
 
  /** @ignore */
  _stickyRowHeaders = true;
 
  /** @ignore */
  protected readonly LOADING_TEXT = 'Tabelle wird geladen';
  /** @ignore */
  protected readonly LOADING_SEARCH_TEXT = 'Ergebnisse werden geladen';
  /** @ignore */
  protected functionContentDisplay: ButtonContentDisplay = 'text-only';
 
  /** @ignore */
  private _isLoading = false;
 
  /** @ignore */
  private resizeObserver?: Callback;
 
  /** @ignore */
  private screenResizeObserver?: Callback;
 
  /** @ignore */
  private resizeObserverHeaderCleanup?: Callback;
 
  /** @ignore */
  private headerHeightObserver?: Callback;
 
  /**
   * Helper object for tracking the last focused cell and it's contained elements information.
   * @prop { index } - index of the last focused element within the cell
   * @prop { cell }  - coordinates of the last focused cell
   * @ignore
   * */
  private lastFocusedCell?: {
    index: number;
    cell: { colIdx: number; rowIdx: number };
  };
 
  /** @ignore */
  private _items: readonly T[] | readonly TableItemGroup<T>[] = [];
 
  /** @ignore */
  private allRowsFlattened: readonly T[] = [];
 
  /** @ignore */
  private eventCallbacks: Callback[] = [];
 
  /** @ignore */
  private ariaLiveReadDisposer?: AriaLiveReadDisposer;
 
  constructor(
    private readonly textHighlightService: TextHighlightService,
    private readonly zone: NgZone,
    private readonly el: ElementRef<HTMLElement>,
  ) {}
 
  focusChild(): boolean {
    const firstFocusableChildren = getKeyboardFocusableElements(
      this.el.nativeElement,
    );
 
    const children =
      firstFocusableChildren.length > 0
        ? firstFocusableChildren
        : Array.from(
            this.table.nativeElement.querySelectorAll<HTMLElement>(
              '[tabindex="-1"]:not([disabled]):not([aria-hidden])',
            ),
          );
    if (children.length > 0) {
      children[0].focus();
      return true;
    } else {
      return false;
    }
  }
 
  /** @ignore */
  public findTdTemplate(columnId: string): TemplateRef<TableCellContext<T>> {
    let templ = this.tdDefaultTemplate;
    templ =
      this.tdTemplates.find(template => template.templateFor === columnId)
        ?.template ?? templ;
    return templ;
  }
 
  /** @ignore */
  public findThTemplate(
    columnId: string,
  ): TemplateRef<TableHeaderCellContext<T>> {
    let templ = this.thDefaultTemplate;
    templ =
      this.thTemplates.find(template => template.templateFor === columnId)
        ?.template ?? templ;
    return templ;
  }
 
  /** @ignore */
  public findCell(
    colIndex: number,
    rowIndex: number,
  ): TableCellDirective<T> | undefined {
    return this.tdElements?.find(
      tdEl => tdEl.cell.colIndex == colIndex && tdEl.cell.rowIndex == rowIndex,
    );
  }
 
  // type guard written as class member to allow using it within the template
  /** @ignore */
  public _isTableItemGroup(
    items: readonly T[] | readonly TableItemGroup<T>[],
  ): items is readonly TableItemGroup<T>[] {
    if (items.length === 0) {
      return false;
    } else {
      const item = items[0];
      return isItem(item) && Array.isArray(item.items);
    }
  }
 
  /** @ignore */
  isEmpty(): boolean {
    return this.items.length === 0;
  }
 
  /** @ignore */
  ngAfterViewInit(): void {
    this.resizeObserver = observeSize(
      this.table,
      this.zone,
      this.resizeObserverCallback.bind(this),
    );
    this.screenResizeObserver = subscribeWindow(
      'resize',
      this.windowResizeObserverCallback.bind(this),
    );
    this.thElements?.changes.subscribe(this.updateTh.bind(this));
 
    this.eventCallbacks.push(
      subscribeOutsideZone(
        this.zone,
        this.table.nativeElement,
        'keydown',
        e => {
          if (e.target instanceof HTMLElement) {
            this.onKeyDown(e);
          }
        },
        { capture: true },
      ),
    );
    this.eventCallbacks.push(
      subscribeOutsideZone(
        this.zone,
        this.table.nativeElement,
        'focusin',
        e => {
          void this.onFocusableNodeFocus(e);
        },
      ),
    );
    this.computeFunctionContentDisplay();
 
    this.updateTh();
  }
 
  /** @ignore */
  ngAfterViewChecked(): void {
    if (this.resizeObserverHeaderCleanup && !this.header) {
      this.resizeObserverHeaderCleanup();
    } else if (this.header && !this.resizeObserverHeaderCleanup) {
      this.resizeObserverHeaderCleanup = observeSize(
        this.header,
        this.zone,
        () => this.checkScrolling(),
      );
    }
  }
 
  /** @ignore */
  ngOnDestroy(): void {
    if (this.resizeObserver) {
      this.resizeObserver();
    }
    if (this.resizeObserverHeaderCleanup) {
      this.resizeObserverHeaderCleanup();
    }
    if (this.screenResizeObserver) {
      this.screenResizeObserver();
    }
    if (this.headerHeightObserver) {
      this.headerHeightObserver();
    }

    // clear focus listeners
    this.eventCallbacks.forEach(fc => fc());
  }
 
  /** @ignore */
  ngOnChanges(changes: SimpleChanges): void {
    if ('items' in changes || 'state' in changes) {
      this.updateAriaUpdater();
    }
    if ('functionItemIconProvider' in changes) {
      this.computeFunctionContentDisplay();
    }
  }
 
  /**
   * Focus a cell in an item
   *
   * @param item the item representing the row
   * @param column optional column or index of the column to move the focus to
   * @param defer defer the focus to the next render cycle
   * @param elementIndex optional index of the focusable element inside the cell
   * @returns `true` if the focus could be transferred otherwise `false` - if you passed `defer=true` it is always true
   */
  public focusItem(
    item: T,
    column?: TableColumn<T> | number,
    defer?: boolean,
    elementIndex?: number,
  ): boolean {
    const block = () => {
      const target = this.computeFocusTarget(item, column);
      if (target) {
        return this.focusCell(
          target.rowIdx,
          target.colIdx,
          elementIndex ?? 'first',
        );
      }
      return false;
    };
    if (defer) {
      this.zone.runOutsideAngular(() => {
        setTimeout(block);
      });
      return true;
    }
    return block();
  }
 
  /** @ignore */
  protected getGlobalRowIndex(item: T, index: number) {
    if (this._isTableItemGroup(this.items)) {
      return this.allRowsFlattened.indexOf(item);
    }
    return index;
  }
 
  /** @ignore */
  protected trackByGroup(group: TableItemGroup<T>) {
    return group.key;
  }
 
  /** @ignore */
  protected trackByIndex(index: number, column: TableColumn<T>) {
    return index.toString() + column.id;
  }
 
  protected computeGridStyles() {
    if (!this.isTableHeaderVisible()) {
      return 'grid-template-columns: 1fr';
    }
    const fillColumn =
      this.columns.find(c => c.fillWidth && c.fillWidth > 0) === undefined
        ? (this.columns.find(c => c.rowHeader) ?? this.columns[0])
        : undefined;
 
    return (
      'grid-template-columns: ' +
      this.columns
        .map((c, idx) => {
          const fillWidth = fillColumn === c ? 1 : c.fillWidth;
          const minWidth = c.minWidth;
 
          if (this.isStickyLeft(idx) || this.isStickyRight(idx)) {
            if (minWidth) {
              return `${minWidth.toFixed(0)}px`;
            }
            return DEFAULT_COL_MIN_WIDTH.toString() + 'px';
          } else if (minWidth && fillWidth) {
            return `minmax(${this.minWidthValue(minWidth)}, ${fillWidth.toFixed(0)}fr)`;
          } else if (fillWidth) {
            return `${fillWidth.toFixed(0)}fr`;
          } else if (minWidth) {
            return `minmax(${this.minWidthValue(minWidth)}, auto)`;
          }
          return 'auto';
        })
        .join(' ')
    );
  }
 
  protected computeNoDataColPosition(column: TableColumn<T>, colIdx: number) {
    if (column.rowHeader) {
      // eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- number is known to be an integer
      return `grid-column: 1/${this.columns.length + 1};`;
    }
    // eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- number is known to be an integer
    return `grid-column: ${colIdx + 1};`;
  }
 
  protected computeGroupColPosition(column: TableColumn<T>, colIdx: number) {
    if (column.rowHeader) {
      if (this.fixedStartColumns > 0) {
        return `grid-column: 1/${(this.fixedStartColumns + 1).toFixed(0)};`;
      }
      // eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- number is known to be an integer
      return `grid-column: 1/${this.columns.length + 1}`;
    }
    if (colIdx === 0) {
      // eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- number is known to be an integer
      return `grid-column: ${colIdx + 1}/${this.columns.length + 1};`;
    }
    // eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- number is known to be an integer
    return `grid-column: ${colIdx + 1};`;
  }
 
  protected isTableHeaderVisible() {
    const state = this.displayState;
    return !(state === 'empty' || state === 'loading');
  }
 
  /**
   * @ignore
   */
  protected _itemTrackBy(item: Item): string {
    return itemTrack(item);
  }
 
  protected computeColumnOffset(colIdx: number): number {
    if (this.isStickyLeft(colIdx)) {
      return this.computeLeftOffsetForColumnIndex(colIdx);
    } else if (this.isStickyRight(colIdx)) {
      return this.computeRightOffsetForColumnIndex(colIdx + 1);
    }
 
    return 0;
  }
 
  protected computeGroupItemRowIndex(items: readonly TableItemGroup<T>[]) {
    const map: Map<TableItemGroup<T>, number> = new Map();
    let index = 2;
    for (const group of items) {
      map.set(group, index);
      index += group.items.length + 1;
      // The group is empty we insert an empty item
      if (group.items.length === 0) {
        index += 1;
      }
    }
    return map;
  }
 
  protected computeScrollMarginLeft(colIndex: number) {
    if (this.fixedStartColumns > 0 && !this.isStickyLeft(colIndex)) {
      return this.computeLeftOffsetForColumnIndex(this.fixedStartColumns);
    }
    return undefined;
  }
 
  protected computeScrollMarginRight(colIndex: number) {
    if (this.fixedEndColumns > 0 && !this.isStickyRight(colIndex)) {
      return this.computeRightOffsetForColumnIndex(
        this.columns.length - this.fixedEndColumns,
      );
    }
    return undefined;
  }
 
  protected isStickyLeft(colIndex: number) {
    if (this.fixedStartColumns > 0) {
      return colIndex < this.fixedStartColumns;
    }
    return false;
  }
 
  protected isLastStickyLeft(colIndex: number) {
    if (this.isStickyLeft(colIndex)) {
      return colIndex + 1 === this.fixedStartColumns;
    }
    return false;
  }
 
  protected isStickyRight(colIndex: number) {
    if (this.fixedEndColumns > 0) {
      return colIndex >= this.columns.length - this.fixedEndColumns;
    }
    return false;
  }
 
  protected isFirstStickyRight(colIndex: number) {
    if (this.isStickyRight(colIndex)) {
      return this.columns.length - this.fixedEndColumns == colIndex;
    }
    return false;
  }
 
  private computeLeftOffsetForColumnIndex(colIdx: number) {
    let result = 0;
    for (let i = 0; i < colIdx; i++) {
      result += this.columns[i].minWidth ?? DEFAULT_COL_MIN_WIDTH;
    }

    return result;
  }
 
  private computeRightOffsetForColumnIndex(colIdx: number) {
    let result = 0;
    for (let i = colIdx; i < this.columns.length; i++) {
      result += this.columns[i].minWidth ?? DEFAULT_COL_MIN_WIDTH;
    }
    return result;
  }
 
  /** @ignore */
  private onKeyDown(event: KeyboardEvent): void {
    const key = event.key;
    switch (key) {
      case 'ArrowUp':
        this.handleArrowUp();
        event.preventDefault();
        event.stopPropagation();
        break;
      case 'ArrowDown':
        this.handleArrowDown();
        event.preventDefault();
        event.stopPropagation();
        break;
      case 'ArrowRight':
        this.handleArrowRight();
        event.preventDefault();
        event.stopPropagation();
        break;
      case 'ArrowLeft':
        this.handleArrowLeft();
        event.preventDefault();
        event.stopPropagation();
        break;
      case 'Home':
        this.handleHomeKey();
        event.preventDefault();
        event.stopPropagation();
        break;
      case 'End':
        this.handleEndKey();
        event.preventDefault();
        event.stopPropagation();
        break;
    }
  }
 
  private minWidthValue(value: number) {
    if (value <= 0) {
      return 'min-content';
    }
    return `${value.toFixed(0)}px`;
  }
 
  private updateTh() {
    const first = this.thElements?.first;
    if (this.headerHeightObserver) {
      this.headerHeightObserver();
    }
 
    if (first) {
      const r = new ResizeObserver(() => {
        this.updateHeaderStyle(
          Math.max(first.el.nativeElement.getBoundingClientRect().height, 41),
        );
      });
      r.observe(first.el.nativeElement);
      this.headerHeightObserver = () => r.disconnect();
      this.updateHeaderStyle(
        Math.max(first.el.nativeElement.getBoundingClientRect().height, 41),
      );
    } else {
      this.updateHeaderStyle(undefined);
    }
  }
 
  private updateHeaderStyle(height: number | undefined) {
    if (height) {
      this.table.nativeElement.style.setProperty(
        '--gc-table-header-height',
        `${height.toFixed(0)}px`,
      );
    } else {
      this.table.nativeElement.style.removeProperty('--gc-table-header-height');
    }
  }
 
  private computeFocusTarget(item: T, column?: TableColumn<T> | number) {
    if (column !== undefined) {
      if (typeof column === 'number') {
        return this.tdElements?.find(
          cell => cell.row === item && cell.colIdx === column,
        );
      } else {
        return this.tdElements?.find(
          cell => cell.row === item && cell.col.id === column.id,
        );
      }
    } else {
      const rowHeaderCell = this.tdElements?.find(
        cell => cell.row === item && cell.col.rowHeader === true,
      );
      if (rowHeaderCell) {
        return rowHeaderCell;
      } else {
        return this.tdElements?.find(
          cell => cell.row === item && cell.colIdx === 0,
        );
      }
    }
  }
 
  /** @ignore */
  private windowResizeObserverCallback(): void {
    this._stickyRowHeaders = window.innerHeight >= 400;
    this.computeFunctionContentDisplay();
  }
 
  private computeFunctionContentDisplay() {
    if (this.functionItemIconProvider) {
      this.functionContentDisplay =
        window.innerWidth < 720 ? 'icon-only' : 'text-only';
    } else {
      this.functionContentDisplay = 'text-only';
    }
  }
 
  /** @ignore */
  private resizeObserverCallback(): void {
    this.checkScrolling();
  }
 
  /** @ignore */
  private checkScrolling() {
    const table = this.table.nativeElement.clientWidth;
    this.smallActions = table < 650;
  }
 
  /** @ignore */
  private handleArrowRight(): void {
    if (this.lastFocusedCell) {
      const nextCol = this.lastFocusedCell.cell.colIdx + 1;
      const totalNumberOfCols =
        this.tdElements?.reduce(
          (acc, curr) => (curr.colIdx > acc ? curr.colIdx : acc),
          0,
        ) ?? 0;
 
      const nextElementWithinFocused = this.focusNextElementInCell();
      if (nextCol <= totalNumberOfCols && !nextElementWithinFocused) {
        this.focusCell(this.lastFocusedCell.cell.rowIdx, nextCol, 'first');
      }
    }
  }
 
  /** @ignore */
  private handleArrowLeft(): void {
    if (this.lastFocusedCell) {
      const previousElementWithinFocused = this.focusPreviousElementInCell();
      const nextCol = this.lastFocusedCell.cell.colIdx - 1;
      if (nextCol >= 0 && !previousElementWithinFocused) {
        this.focusCell(this.lastFocusedCell.cell.rowIdx, nextCol, 'last');
      }
    }
  }
 
  /** @ignore */
  private handleArrowUp(): void {
    if (this.lastFocusedCell) {
      const nextRow = this.lastFocusedCell.cell.rowIdx - 1;
      if (nextRow >= -1) {
        this.focusCell(
          nextRow,
          this.lastFocusedCell.cell.colIdx,
          this.lastFocusedCell.index,
        );
      }
    }
  }
 
  /** @ignore */
  private handleArrowDown(): void {
    if (this.lastFocusedCell) {
      const previousRow = this.lastFocusedCell.cell.rowIdx + 1;
      const totalNumberOfRows =
        this.tdElements?.reduce(
          (acc, curr) => (curr.rowIdx > acc ? curr.rowIdx : acc),
          0,
        ) ?? 0;
 
      if (previousRow <= totalNumberOfRows) {
        this.focusCell(
          previousRow,
          this.lastFocusedCell.cell.colIdx,
          this.lastFocusedCell.index,
        );
      }
    }
  }
 
  /** @ignore */
  private handleEndKey(): void {
    const lastCell = this.tdElements?.last;
 
    if (lastCell) {
      this.focusCell(lastCell.rowIdx, lastCell.colIdx, 'last');
    }
  }
 
  /** @ignore */
  private handleHomeKey(): void {
    const firstCell = this.tdElements?.first;
 
    if (firstCell) {
      this.focusCell(0, 0, 'first');
    }
  }
 
  /** @ignore */
  private async onFocusableNodeFocus(event: FocusEvent): Promise<void> {
    const findTD = (el: HTMLElement): HTMLElement | null => {
      let current = el as HTMLElement | null;
      while (current) {
        if (current.tagName == 'TD') {
          break;
        }
        current = current.parentElement;
      }
      return current;
    };
 
    this.updateLastFocusedCell();
 
    const target = event.target as HTMLElement;
    const tr = findTD(target);
 
    if (tr) {
      // Firefox does not scroll the focus element intoView if more than
      // 50% is visible already
      tr.scrollIntoView({ block: 'nearest', inline: 'nearest' });
      if (this.stickyHeaderColumns) {
        await waitForRender();
        const relative = relativeTo(tr, this.table.nativeElement);
        const stickyHeaderHeight = this._isTableItemGroup(this.items)
          ? 41 * 2
          : 41;
        if (relative < stickyHeaderHeight) {
          this.table.nativeElement.scrollBy({
            top: relative - stickyHeaderHeight,
          });
        }
      }
    }
 
    this.scrollToActiveCell();
  }
 
  /** @ignore */
  private updateLastFocusedCell() {
    const focusedCell =
      this.thElements?.find(i =>
        i.el.nativeElement.contains(document.activeElement),
      ) ??
      this.tdElements?.find(i =>
        i.el.nativeElement.contains(document.activeElement),
      );
 
    if (focusedCell) {
      const cell: { rowIdx: number; colIdx: number } = {
        colIdx: focusedCell.colIdx,
        rowIdx:
          focusedCell instanceof TableCellDirective ? focusedCell.rowIdx : -1,
      };
 
      const focusableChildren = getKeyboardFocusableElements(
        focusedCell.el.nativeElement,
      );
 
      const index = focusableChildren.indexOf(
        document.activeElement as HTMLElement,
      );
      this.lastFocusedCell = { index, cell };
    }
  }
 
  /**
   * Focuses the cell within the table that corresponds to the passed row and column parameters.
   * @param rowIdx index of the row to be focused
   * @param colIdx index of the column to be focused
   * @returns true if the cell exists otherwise returns false
   * @ignore
   */
  private focusCell(
    rowIdx: number,
    colIdx: number,
    indexInCellToFocus: number | 'first' | 'last',
  ): boolean {
    if (rowIdx >= 0) {
      const cell = this.findCell(colIdx, rowIdx);
      if (cell) {
        const focusableElements = getKeyboardFocusableElements(
          cell.el.nativeElement,
        );
        if (focusableElements.length === 0) {
          const programmticallyFocusable = Array.from(
            cell.el.nativeElement.querySelectorAll<HTMLElement>(
              '*[tabindex="-1"]:not([disabled]):not([aria-hidden])',
            ),
          );
          if (programmticallyFocusable.length > 0) {
            programmticallyFocusable[0].focus();
            return true;
          }
        } else {
          let targetIndex;
          if (typeof indexInCellToFocus === 'number') {
            targetIndex = Math.max(
              0,
              Math.min(indexInCellToFocus, focusableElements.length - 1),
            );
          } else if (indexInCellToFocus === 'first') {
            targetIndex = 0;
          } else {
            targetIndex = focusableElements.length - 1;
          }
 
          focusableElements[
            targetIndex < focusableElements.length
              ? targetIndex
              : focusableElements.length - 1
          ].focus();
          return true;
        }
      }
    } else {
      const headerElement = this.thElements?.find(
        item => item.colIdx === colIdx,
      );
      if (headerElement) {
        const focusableElements = getKeyboardFocusableElements(
          headerElement.el.nativeElement,
        );
        const focusTarget =
          focusableElements.length > 0
            ? focusableElements[0]
            : headerElement.el.nativeElement.querySelector<HTMLElement>(
                '*[tabindex="-1"]',
              );
        if (focusTarget) {
          focusTarget.focus();
        }
      }
    }
 
    return false;
  }
 
  /**
   * Focuses the next focusable element within the currently focused cell that contains focusable elements.
   * @returns true if a next element exists within the current cell otherwise returns false
   * @ignore
   */
  private focusNextElementInCell(): boolean {
    if (!this.lastFocusedCell) {
      return false;
    }
 
    if (this.lastFocusedCell.index === -1) {
      return false;
    }
 
    const cell = this.findCell(
      this.lastFocusedCell.cell.colIdx,
      this.lastFocusedCell.cell.rowIdx,
    );
 
    if (cell) {
      const focusableChildren = getKeyboardFocusableElements(
        cell.el.nativeElement,
      );
 
      const nextIdx = this.lastFocusedCell.index + 1;
 
      if (nextIdx < focusableChildren.length) {
        focusableChildren[nextIdx].focus();
        return true;
      }
    }
 
    return false;
  }
 
  /**
   * Focuses the previous focusable element within the currently focused cell that contains focusable elements.
   * @returns true if a previous element exists within the current cell otherwise returns false
   * @ignore
   */
  private focusPreviousElementInCell(): boolean {
    if (!this.lastFocusedCell) {
      return false;
    }
 
    // This means the cell itself is focused
    if (
      this.lastFocusedCell.index === -1 ||
      this.lastFocusedCell.index - 1 < 0
    ) {
      return false;
    }
 
    const cell = this.findCell(
      this.lastFocusedCell.cell.colIdx,
      this.lastFocusedCell.cell.rowIdx,
    );

    if (cell) {
      const focusableChildren = getKeyboardFocusableElements(
        cell.el.nativeElement,
      );
      const prevElement = focusableChildren[this.lastFocusedCell.index - 1];
      prevElement.focus();

      return true;
    }

    return false;
  }
 
  /** @ignore */
  private scrollToActiveCell(): void {
    const focusedCell = this.tdElements?.find(i =>
      i.el.nativeElement.contains(document.activeElement),
    );
 
    if (focusedCell) {
      focusedCell.el.nativeElement.scrollIntoView({
        block: 'nearest',
        inline: 'nearest',
      });
    } else {
      const focusHeaderCell = this.thElements?.find(i =>
        i.el.nativeElement.contains(document.activeElement),
      );
      focusHeaderCell?.el.nativeElement.scrollIntoView({
        block: 'nearest',
        inline: 'nearest',
      });
    }
  }
 
  /** @ignore */
  private updateAriaUpdater() {
    const state = this.displayState;
    if (state === 'loading' || state === 'search-loading') {
      this.ariaLiveReadDisposer = this.ariaLiveRegion?.readText(
        state === 'loading' ? this.LOADING_TEXT : this.LOADING_SEARCH_TEXT,
        2000,
        10_000,
      );
    } else if (state === 'search-empty') {
      this.ariaLiveReadDisposer?.(
        'Kein Treffer für diese Such- und Filterkriterien gefunden.',
      );
      this.ariaLiveReadDisposer = undefined;
    } else if (state === 'empty') {
      this.ariaLiveReadDisposer?.('Keine Tabelleneinträge vorhanden.');
      this.ariaLiveReadDisposer = undefined;
    } else {
      this.ariaLiveReadDisposer?.();
      this.ariaLiveReadDisposer = undefined;
    }
  }
}