Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 58 additions & 42 deletions src/core/tables/__snapshots__/htmlTable.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ exports[`Html table render tests should match snapshot: Table with column variab
"<div
id="test-49857934857938475938475"
>
<p
class="tableChart-title"
id="test-49857934857938475938475-title"
>
Adoptiot 1987-1989 muuttujina Syntymävaltio, Ikä
</p>
<table
aria-labelledby="test-49857934857938475938475-title"
tabindex="0"
>
<caption
class="tableChart-caption"
>
Adoptiot 1987-1989 muuttujina Syntymävaltio, Ikä
</caption>
<thead>
<tr>
<th
Expand Down Expand Up @@ -282,16 +284,18 @@ exports[`Html table render tests should match snapshot: Table with missing data
"<div
id="test-84957394875983745"
>
<p
class="tableChart-title"
id="test-84957394875983745-title"
>
Neliöhinta (EUR/m2), Helsinki 2020Q1-2023Q2* muuttujina Talotyyppi, Huoneluku
<br />
Rivitalot | Kaksiot
</p>
<table
aria-labelledby="test-84957394875983745-title"
tabindex="0"
>
<caption
class="tableChart-caption"
>
Neliöhinta (EUR/m2), Helsinki 2020Q1-2023Q2* muuttujina Talotyyppi, Huoneluku
<br />
Rivitalot | Kaksiot
</caption>
<thead>
<tr>
<th
Expand Down Expand Up @@ -440,14 +444,16 @@ exports[`Html table render tests should match snapshot: Table with only one cell
"<div
id="test-6895638450983059889"
>
<p
class="tableChart-title"
id="test-6895638450983059889-title"
>
Lukumäärä, Vantaa, Yksiöt, Vapaarahoitteinen 2022Q4
</p>
<table
aria-labelledby="test-6895638450983059889-title"
tabindex="0"
>
<caption
class="tableChart-caption"
>
Lukumäärä, Vantaa, Yksiöt, Vapaarahoitteinen 2022Q4
</caption>
<tbody>
<tr>
<td>
Expand All @@ -469,14 +475,16 @@ exports[`Html table render tests should match snapshot: Table with row and colum
"<div
id="test-4329874982374983798"
>
<p
class="tableChart-title"
id="test-4329874982374983798-title"
>
Tiedot 2022Q1-2022Q4 muuttujina Tiedot, Alue, Huoneluku, Rahoitusmuoto
</p>
<table
aria-labelledby="test-4329874982374983798-title"
tabindex="0"
>
<caption
class="tableChart-caption"
>
Tiedot 2022Q1-2022Q4 muuttujina Tiedot, Alue, Huoneluku, Rahoitusmuoto
</caption>
<thead>
<tr>
<td
Expand Down Expand Up @@ -1109,14 +1117,16 @@ exports[`Html table render tests should match snapshot: Table with row and colum
"<div
id="test-4329874982374983798"
>
<p
class="tableChart-title"
id="test-4329874982374983798-title"
>
Tiedot 2022Q1-2022Q4 muuttujina Tiedot, Alue, Huoneluku, Rahoitusmuoto
</p>
<table
aria-labelledby="test-4329874982374983798-title"
tabindex="0"
>
<caption
class="tableChart-caption"
>
Tiedot 2022Q1-2022Q4 muuttujina Tiedot, Alue, Huoneluku, Rahoitusmuoto
</caption>
<thead>
<tr>
<td
Expand Down Expand Up @@ -2381,14 +2391,16 @@ exports[`Html table render tests should match snapshot: Table with row and colum
"<div
id="test-4329874982374983798"
>
<p
class="tableChart-title"
id="test-4329874982374983798-title"
>
Tiedot 2022Q1-2022Q4 muuttujina Tiedot, Alue, Huoneluku, Rahoitusmuoto
</p>
<table
aria-labelledby="test-4329874982374983798-title"
tabindex="0"
>
<caption
class="tableChart-caption"
>
Tiedot 2022Q1-2022Q4 muuttujina Tiedot, Alue, Huoneluku, Rahoitusmuoto
</caption>
<thead>
<tr>
<td
Expand Down Expand Up @@ -3015,14 +3027,16 @@ exports[`Html table render tests should match snapshot: Table with row variables
"<div
id="test-9483567287648723649867"
>
<p
class="tableChart-title"
id="test-9483567287648723649867-title"
>
Lukumäärä 2022Q1-2022Q4 muuttujina Alue, Huoneluku, Rahoitusmuoto
</p>
<table
aria-labelledby="test-9483567287648723649867-title"
tabindex="0"
>
<caption
class="tableChart-caption"
>
Lukumäärä 2022Q1-2022Q4 muuttujina Alue, Huoneluku, Rahoitusmuoto
</caption>
<tbody>
<tr>
<th
Expand Down Expand Up @@ -3547,14 +3561,16 @@ exports[`Html table render tests should match snapshot: Table with source and fo
"<div
id="test-6895638450983059889"
>
<p
class="tableChart-title"
id="test-6895638450983059889-title"
>
Lukumäärä, Vantaa, Yksiöt, Vapaarahoitteinen 2022Q4
</p>
<table
aria-labelledby="test-6895638450983059889-title"
tabindex="0"
>
<caption
class="tableChart-caption"
>
Lukumäärä, Vantaa, Yksiöt, Vapaarahoitteinen 2022Q4
</caption>
<tbody>
<tr>
<td>
Expand Down
15 changes: 10 additions & 5 deletions src/core/tables/htmlTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ export function renderHtmlTable(view: View, locale: string, options: IChartOptio
const table = generateTable(view, locale);

if (options.showTitles) {
const titleId = `${containerId}-title`;
const titleElement = document.createElement('p');
titleElement.id = titleId;
titleElement.textContent = view.header[locale];
titleElement.className = 'tableChart-title';

const caption = document.createElement('caption');
caption.textContent = view.header[locale];
if (view.subheaderValues.length > 0) {
const subtitle: string = view.subheaderValues.map(value => value[locale]).join(' | ');
caption.append(document.createElement('br'), subtitle);
titleElement.append(document.createElement('br'), subtitle);
}
caption.className = 'tableChart-caption';
table.prepend(caption);
// Set aria-labelledby on the table to reference the title
table.setAttribute('aria-labelledby', titleId);

container.append(titleElement);
}

container.append(table);
Expand Down
Loading
Loading