Skip to content

Commit

Permalink
Feat: add cookieTable.caption for better a11y (ref. #485)
Browse files Browse the repository at this point in the history
  • Loading branch information
orestbida committed Mar 25, 2023
1 parent ee33d54 commit 35b3457
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions demo/demo_gtm/cookieconsent-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ CookieConsent.run({

language: {
default: 'en',
rtl: 'en',

translations: {
en: {
Expand Down Expand Up @@ -85,6 +86,7 @@ CookieConsent.run({
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
linkedCategory: 'analytics',
cookieTable: {
caption: 'Cookie tableeee',
headers: {
name: 'Cookie',
domain: 'Domain',
Expand Down
2 changes: 1 addition & 1 deletion dist/cookieconsent.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cookieconsent.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cookieconsent.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/css-components/preferences-modal.css

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/core/modals/preferencesModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export const createPreferencesModal = (api, createMainContainer) => {
sCurrentCategoryObject = sLinkedCategory && state._allDefinedCategories[sLinkedCategory],
sCookieTableData = section.cookieTable,
sCookieTableBody = sCookieTableData?.body,
sCookieTableCaption = sCookieTableData?.caption,
sCreateCookieTable = sCookieTableBody?.length > 0,
hasToggle = !!sCurrentCategoryObject,

Expand Down Expand Up @@ -322,6 +323,13 @@ export const createPreferencesModal = (api, createMainContainer) => {
const thead = createNode('thead');
const tbody = createNode('tbody');

if(sCookieTableCaption) {
const caption = createNode('caption');
addClassPm(caption, 'table-caption');
caption.innerHTML = sCookieTableCaption;
table.appendChild(caption);
}

addClassPm(table, 'section-table');
addClassPm(thead, 'table-head');
addClassPm(tbody, 'table-body');
Expand Down
7 changes: 7 additions & 0 deletions src/scss/core/components/_preferences-modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,12 @@ $service-toggle-knob-icon-width: 1.7px;
font-size: .9em;
}

.pm__table-caption {
border-top: 1px solid var(--cc-cookie-category-block-border);
text-align: start;
}

.pm__table-caption,
.pm__table-head > tr{
font-weight: 600;
color: var(--cc-primary-color);
Expand All @@ -589,6 +595,7 @@ $service-toggle-knob-icon-width: 1.7px;
}
}

.pm__table-caption,
.pm__table-th,
.pm__table-td{
padding: 0.625em;
Expand Down
6 changes: 6 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ declare namespace CookieConsent {
}

interface CookieTable {

/**
* Table caption
*/
caption?: string,

/**
* Define the table headers (columns).
*/
Expand Down

0 comments on commit 35b3457

Please sign in to comment.