File tree Expand file tree Collapse file tree 4 files changed +24
-6
lines changed
Expand file tree Collapse file tree 4 files changed +24
-6
lines changed Original file line number Diff line number Diff line change 1+ import { createContextWithRoot } from '@patternfly/pfe-core/functions/context.js' ;
2+
3+ export const thRoleContext : {
4+ __context__ : unknown ;
5+ } = createContextWithRoot < 'rowheader' | 'colheader' > ( 'pf-th-role' ) ;
Original file line number Diff line number Diff line change @@ -3,7 +3,11 @@ import { customElement } from 'lit/decorators/custom-element.js';
33import { styleMap } from 'lit/directives/style-map.js' ;
44import { state } from 'lit/decorators/state.js' ;
55
6+ import { provide } from '@lit/context' ;
7+ import { thRoleContext } from './context.js' ;
8+
69import { PfTh , RequestSortEvent } from './pf-th.js' ;
10+ import { PfTd } from './pf-td.js' ;
711import { PfTr , RequestExpandEvent } from './pf-tr.js' ;
812
913export * from './pf-caption.js' ;
@@ -14,7 +18,6 @@ export * from './pf-th.js';
1418export * from './pf-td.js' ;
1519
1620import styles from './pf-table.css' ;
17- import { PfTd } from './pf-td.js' ;
1821
1922const rowQuery = [
2023 ':scope > pf-tbody:not([expandable]) > pf-tr' ,
@@ -671,6 +674,8 @@ export class PfTable extends LitElement {
671674
672675 @state ( ) private columns = 0 ;
673676
677+ @provide ( { context : thRoleContext } ) private thRowContext = 'rowheader' ;
678+
674679 override connectedCallback ( ) : void {
675680 super . connectedCallback ( ) ;
676681 this . setAttribute ( 'role' , 'table' ) ;
Original file line number Diff line number Diff line change @@ -3,6 +3,10 @@ import { customElement } from 'lit/decorators/custom-element.js';
33import { property } from 'lit/decorators/property.js' ;
44import { classMap } from 'lit/directives/class-map.js' ;
55
6+ import { consume } from '@lit/context' ;
7+
8+ import { thRoleContext } from './context.js' ;
9+
610import '@patternfly/elements/pf-button/pf-button.js' ;
711
812import styles from './pf-th.css' ;
@@ -46,13 +50,12 @@ export class PfTh extends LitElement {
4650
4751 @property ( ) key ! : string ;
4852
53+ @consume ( { context : thRoleContext } )
54+ private contextualRole : 'colheader' | 'rowheader' = 'rowheader' ;
55+
4956 override connectedCallback ( ) : void {
5057 super . connectedCallback ( ) ;
51- const closestThead = this . closest ( 'pf-thead' ) ;
52- const closestTable = this . closest ( 'pf-table' ) ;
53- const isChildOfThead = ! ! closestThead && ! ! closestTable ?. contains ( closestThead ) ;
54- const role = isChildOfThead ? 'colheader' : 'rowheader' ;
55- this . setAttribute ( 'role' , role ) ;
58+ this . setAttribute ( 'role' , this . contextualRole ) ;
5659 }
5760
5861 render ( ) : TemplateResult < 1 > {
Original file line number Diff line number Diff line change 11import { LitElement , html , type TemplateResult } from 'lit' ;
22import { customElement } from 'lit/decorators/custom-element.js' ;
33
4+ import { thRoleContext } from './context.js' ;
5+
46import styles from './pf-thead.css' ;
7+ import { provide } from '@lit/context' ;
58
69/**
710 * Table head
@@ -11,6 +14,8 @@ import styles from './pf-thead.css';
1114export class PfThead extends LitElement {
1215 static readonly styles : CSSStyleSheet [ ] = [ styles ] ;
1316
17+ @provide ( { context : thRoleContext } ) private thRowContext = 'colheader' ;
18+
1419 connectedCallback ( ) : void {
1520 super . connectedCallback ( ) ;
1621 this . setAttribute ( 'role' , 'rowgroup' ) ;
You can’t perform that action at this time.
0 commit comments