File tree Expand file tree Collapse file tree 3 files changed +72
-0
lines changed Expand file tree Collapse file tree 3 files changed +72
-0
lines changed Original file line number Diff line number Diff line change 1+ import AbstractDomElement from './AbstractDomElement'
2+ import each from '../utils/each'
3+
4+ // ----
5+ // class
6+ // ----
7+ class TableBlock extends AbstractDomElement {
8+ constructor ( element , options ) {
9+ const instance = super ( element , options )
10+
11+ // avoid double init :
12+ if ( ! instance . isNewInstance ( ) ) {
13+ return instance
14+ }
15+
16+ const el = this . _element
17+ const table = el . querySelector ( 'table' )
18+ const thead = table . querySelector ( 'thead' )
19+ const legend = el . querySelector ( 'figcaption' )
20+
21+ // Tableau de données
22+ if ( thead ) {
23+ const ths = thead . querySelectorAll ( 'th' )
24+
25+ each ( ths , function ( th ) {
26+ th . setAttribute ( 'scope' , 'col' )
27+ } )
28+
29+ // Fix de la légende / titre du tableau. figcaption n'est pas supporté : https://accessibilite.numerique.gouv.fr/methode/glossaire/#tableau-de-donnees-ayant-un-titre
30+ if ( legend ) {
31+ const caption = document . createElement ( 'caption' )
32+ caption . className = legend . className
33+ caption . innerHTML = legend . innerHTML
34+ table . insertBefore ( caption , table . firstChild )
35+ legend . remove ( )
36+ }
37+ }
38+
39+ // Tableau de mise en forme
40+ if ( ! thead ) {
41+ table . setAttribute ( 'role' , 'presentation' )
42+ }
43+ }
44+ }
45+
46+ // ----
47+ // init
48+ // ----
49+ TableBlock . init ( '.wp-block-table' )
50+
51+ // ----
52+ // export
53+ // ----
54+ export default TableBlock
Original file line number Diff line number Diff line change @@ -5,3 +5,4 @@ import './classes/ButtonSeoClick'
55import './classes/Header'
66import './classes/Animation'
77import './classes/ImageBlock'
8+ import './classes/TableBlock'
Original file line number Diff line number Diff line change 22 width : 100% ;
33 min-width : 240px ;
44 border-collapse : collapse ;
5+
6+ th {
7+ font-weight : 700 ;
8+ }
9+
10+ figcaption ,
11+ caption {
12+ margin-bottom : var (--spacing--block-1 );
13+ font-size : var (--paragraph--font-size-default );
14+ font-weight : 700 ;
15+ line-height : var (--paragraph--line-height-default );
16+ text-align : left ;
17+ }
518}
619
720.wp-block-table {
821 @extend %table ;
22+
23+ display : flex ;
24+ flex-direction : column-reverse ;
25+ align-items : flex-start ;
926}
1027
1128// Not apply style to ACF fields
You can’t perform that action at this time.
0 commit comments