CSS ComponentThe latest version of this package is: 17.0.30-alpha.8, Opens in new window
A Product Matrix Table is a table for product comparison.
This component provides .css
, .styl
, .less
and .scss
-files.
To be able to install this component, please refer to the Project Setup documentation.
$ npm i @ids-core/product-matrix-table@17.0.30-alpha.8
This is the baseline component for product matrices and product comparison tables.
Vad täcker försäkringen? | Basic | Extra | |
---|---|---|---|
Ansvars- och rättskydd | This is included in the product: Extra | ||
Du får ersättning för dina saker som skadas eller förloras vid inbrott eller skadegörelse i bostaden, vattenläckage, brand eller blixtnedslag. Försäkringsbeloppet är 1,5 miljoner kr om du inte själv valt ett högre belopp. | |||
Brand och explosion | |||
Du får ersättning för dina saker som skadas eller förloras vid inbrott eller skadegörelse i bostaden, vattenläckage, brand eller blixtnedslag. Försäkringsbeloppet är 1,5 miljoner kr om du inte själv valt ett högre belopp. |
Table of Contents
Edit this section, Opens in new windowUsage
Product comparison
<div class="if block">
<div class="if container">
<table
class="if table product"
data-if-selected="1"
aria-label="Product comparison of our home insurance"
aria-describedby="pm-implementation-1"
>
<thead class="if">
<tr class="if">
<th scope="col" class="if">
<span class="if" id="pm-implementation-1">Vad täcker försäkringen?</span>
</th>
<th scope="col" class="if">
<button type="button" class="if product-selector previous">
<span class="if axe sr-only">Previous</span>
</button>
<span class="if product-name"> Basic</span>
<span class="if product-indicator">
<span class="if"></span>
<span class="if"></span>
<span class="if"></span>
</span>
<button type="button" class="if product-selector next">
<span class="if axe sr-only">Next</span>
</button>
</th>
<th scope="col" class="if spacer"></th>
<th scope="col" class="if">
<button type="button" class="if product-selector previous">
<span class="if axe sr-only">Previous</span>
</button>
<span class="if product-name"> Extra</span>
<span class="if product-indicator">
<span class="if"></span>
<span class="if"></span>
<span class="if"></span>
</span>
<button type="button" class="if product-selector next">
<span class="if axe sr-only">Next</span>
</button>
</th>
</tr>
</thead>
<tbody class="if">
<tr class="if expandable">
<td scope="row" class="if" tabindex="0">Ansvars- och rättskydd</td>
<td class="if"></td>
<td class="if spacer"></td>
<td class="if included">
<span class="if axe sr-only">This is included in the product: Extra</span>
</td>
</tr>
<tr class="if">
<td class="if">
Du får ersättning för dina saker som skadas eller förloras vid inbrott eller
skadegörelse i bostaden, vattenläckage, brand eller blixtnedslag.
Försäkringsbeloppet är 1,5 miljoner kr om du inte själv valt ett högre
belopp.
</td>
<td class="if"></td>
<td class="if spacer"></td>
<td class="if included"></td>
</tr>
<tr class="if expandable">
<td scope="row" class="if" tabindex="0">Brand och explosion</td>
<td class="if"></td>
<td class="if spacer"></td>
<td class="if"></td>
</tr>
<tr class="if">
<td class="if">
Du får ersättning för dina saker som skadas eller förloras vid inbrott eller
skadegörelse i bostaden, vattenläckage, brand eller blixtnedslag.
Försäkringsbeloppet är 1,5 miljoner kr om du inte själv valt ett högre
belopp.
</td>
<td class="if"></td>
<td class="if spacer"></td>
<td class="if"></td>
</tr>
</tbody>
</table>
</div>
</div>
Product chooser
<form class="if">
<div class="if block">
<div class="if container">
<table
class="if table product selectable"
data-if-selected="1"
aria-label="Product comparison of our home insurance"
aria-describedby="pm-implementation-2"
>
<thead class="if">
<tr class="if">
<th scope="col" class="if">
<span class="if" id="pm-implementation-2"
>Vad täcker försäkringen?</span
>
</th>
<th scope="col" class="if">
<button type="button" class="if product-selector previous">
<span class="if axe sr-only">Previous</span>
</button>
<input
type="radio"
tabindex="-1"
id="product-matrix-selectable-group-1-1"
class="if checkbox standalone"
name="product-matrix-selectable-group-1"
/>
<label tabindex="-1" for="product-matrix-selectable-group-1-1"></label>
<span class="if product-name"> Basic</span>
<span class="if product-indicator">
<span class="if"></span>
<span class="if"></span>
<span class="if"></span>
</span>
<button type="button" class="if product-selector next">
<span class="if axe sr-only">Next</span>
</button>
</th>
<th scope="col" class="if spacer"></th>
<th scope="col" class="if">
<button type="button" class="if product-selector previous">
<span class="if axe sr-only">Previous</span>
</button>
<input
type="radio"
tabindex="-1"
id="product-matrix-selectable-group-1-2"
class="if checkbox standalone"
name="product-matrix-selectable-group-1"
/>
<label tabindex="-1" for="product-matrix-selectable-group-1-2"></label>
<span class="if product-name"> Extra</span>
<span class="if product-indicator">
<span class="if"></span>
<span class="if"></span>
<span class="if"></span>
</span>
<button type="button" class="if product-selector next">
<span class="if axe sr-only">Next</span>
</button>
</th>
</tr>
</thead>
<tbody class="if">
<tr class="if expandable">
<td scope="row" class="if" tabindex="0">Ansvars- och rättskydd</td>
<td class="if"></td>
<td class="if spacer"></td>
<td class="if included">
<span class="if axe sr-only"
>This is included in the product: Extra</span
>
</td>
</tr>
<tr class="if">
<td class="if">
Du får ersättning för dina saker som skadas eller förloras vid inbrott
eller skadegörelse i bostaden, vattenläckage, brand eller blixtnedslag.
Försäkringsbeloppet är 1,5 miljoner kr om du inte själv valt ett högre
belopp.
</td>
<td class="if"></td>
<td class="if spacer"></td>
<td class="if included"></td>
</tr>
<tr class="if expandable">
<td scope="row" class="if" tabindex="0">Brand och explosion</td>
<td class="if"></td>
<td class="if spacer"></td>
<td class="if"></td>
</tr>
<tr class="if">
<td class="if">
Du får ersättning för dina saker som skadas eller förloras vid inbrott
eller skadegörelse i bostaden, vattenläckage, brand eller blixtnedslag.
Försäkringsbeloppet är 1,5 miljoner kr om du inte själv valt ett högre
belopp.
</td>
<td class="if"></td>
<td class="if spacer"></td>
<td class="if"></td>
</tr>
</tbody>
</table>
</div>
</div>
</form>
JavaScript implementation example
Here follows an implementation example of the JavaScript required to make the table accessible and interactive.
const minMedium = '60rem';
const mediumMQ = window.matchMedia(`screen and (min-width: ${minMedium})`);
const setColumnAsSelectedByElement = (el) => {
let nodeIndex = getNodeIndex(el);
let normalizedIndex = nodeIndex + 1;
let productIndex = normalizedIndex / 2;
setColumnAsSelectedByProductIndex(el, productIndex);
};
const setColumnAsSelectedByProductIndex = (el, productIndex) => {
el.closest('.if.table.product').setAttribute('data-if-selected', productIndex);
const selectable = el.closest('.if.table.product.selectable');
if (selectable) {
selectable.querySelector(
`* > tr > th:nth-child(${productIndex * 2}) [type=radio]`
).checked = true;
}
};
const setColumnAsFocused = (el) => {
let nodeIndex = getNodeIndex(el);
let normalizedIndex = nodeIndex + 1;
let productIndex = normalizedIndex / 2;
el.closest('.if.table.product.selectable').setAttribute('data-if-focused', productIndex);
};
const clearColumnFocus = (el) => {
el.closest('.if.table.product.selectable').removeAttribute('data-if-focused');
};
const selectPreviousProduct = (prev) => {
const products = Array.prototype.map.call(
prev.closest('thead').querySelectorAll('tr > th:nth-child(even)'),
(th) => th
);
if (products.indexOf(prev) === 0) {
setColumnAsSelectedByElement(products[products.length - 1]);
} else {
setColumnAsSelectedByElement(products[products.indexOf(prev) - 1]);
}
};
const selectNextProduct = (next) => {
const products = Array.prototype.map.call(
next.closest('thead').querySelectorAll('tr > th:nth-child(even)'),
(th) => th
);
if (products.indexOf(next) === products.length - 1) {
setColumnAsSelectedByElement(products[0]);
} else {
setColumnAsSelectedByElement(products[products.indexOf(next) + 1]);
}
};
const handleMedium = (mql) => {
if (mql.matches) {
document.querySelectorAll('.if.product-selector.previous').forEach((prev) => {
prev.removeEventListener('click', (e) => {
selectPreviousProduct(prev.closest('th'));
});
});
document.querySelectorAll('.if.product-selector.next').forEach((next) => {
next.removeEventListener('click', (e) => {
selectNextProduct(next.closest('th'));
});
});
document
.querySelectorAll(
'.if.table.product.selectable > * > tr > th:nth-child(even),.if.table.product.selectable > * > tr > td:nth-child(even)'
)
.forEach((el) => {
el.addEventListener('click', (e) => {
setColumnAsSelectedByElement(el);
});
el.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
setColumnAsSelectedByElement(el);
}
});
el.addEventListener('focus', (e) => {
setColumnAsFocused(el);
});
el.addEventListener('blur', (e) => {
clearColumnFocus(el);
});
});
document
.querySelectorAll('.if.table.product.selectable > * > tr > th:nth-child(even)')
.forEach((el) => {
el.setAttribute('tabindex', '0');
});
} else {
document.querySelectorAll('.if.product-selector.previous').forEach((prev) => {
prev.addEventListener('click', (e) => {
selectPreviousProduct(prev.closest('th'));
});
});
document.querySelectorAll('.if.product-selector.next').forEach((next) => {
next.addEventListener('click', (e) => {
selectNextProduct(next.closest('th'));
});
});
document
.querySelectorAll(
'.if.table.product.selectable > * > tr > th:nth-child(even),.if.table.product.selectable > * > tr > td:nth-child(even)'
)
.forEach((el) => {
el.removeEventListener('click', (e) => {
setColumnAsSelectedByElement(el);
});
el.removeEventListener('keydown', (e) => {
if (e.key === 'Enter') {
setColumnAsSelectedByElement(el);
}
});
el.removeEventListener('focus', (e) => {
setColumnAsFocused(el);
});
el.removeEventListener('blur', (e) => {
clearColumnFocus(el);
});
});
document
.querySelectorAll('.if.table.product.selectable > * > tr > th:nth-child(even)')
.forEach((el) => {
el.setAttribute('tabindex', '-1');
});
}
};
mediumMQ.addListener(handleMedium);
handleMedium(mediumMQ);
const getNodeIndex = (elm) => [...elm.parentNode.children].indexOf(elm);
document.querySelectorAll('.if.table.product tr.expandable > td:first-child').forEach((td) => {
td.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
if (td.parentElement.classList.contains('is-expanded')) {
td.parentElement.classList.remove('is-expanded');
} else {
document
.querySelectorAll('.if.table.product tr.expandable.is-expanded')
.forEach((tr) => {
tr.classList.remove('is-expanded');
});
td.parentElement.classList.add('is-expanded');
}
}
});
td.addEventListener('click', (e) => {
if (td.parentElement.classList.contains('is-expanded')) {
td.parentElement.classList.remove('is-expanded');
} else {
document
.querySelectorAll('.if.table.product tr.expandable.is-expanded')
.forEach((tr) => {
tr.classList.remove('is-expanded');
});
td.parentElement.classList.add('is-expanded');
}
});
});
Changelog
Change Log
All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.
14.22.2 (2022-05-03)
Miscellaneous chores
- package locks: update package locks (813eac7)
14.20.1 (2022-04-19)
Miscellaneous chores
- changelog: regenerate all CHANGELOG.md files (64ab385) , closes #586342
- changelog: regenerate all changelogs after updating changelog generation (70789c9) , closes #587270
14.18.3 (2022-04-13)
Bug Fixes
- changelog: generate new CHANGELOG.md files for root and
packages (349fda4)
,
closes #586063
. We regenerate the files to include all relevant commits and to use
conventional-commits
at 100%
14.16.0 (2022-04-07)
Bug Fixes
14.9.0 (2022-03-03)
Miscellaneous chores
- 🤖 Bootstrap (6822f5b)
14.8.1 (2022-02-23)
Bug Fixes
reinstall (d425056)
bootstrap (9a713df)
merge (2b1c5f1)
reinstall (5221600)
reinstall (147df55)
reinstall (afce1f2)
reinstall (67f3140)
-
Add changelog.md to files (3338314)
Reinstall (a2abf51)
14.2.2 (2021-12-10)
Code Refactoring
reinstall (885c74b)
-
fix changelogs manually (b1232b4)
reinstall (545a069)
reinstall (e149c2c)
13.12.3 (2021-11-09)
⚠ BREAKING CHANGES
- 🧨 The scope for If Design System npm packages has now changed from
@if-design-system
to@ids-core
. We have also renamed the repository fromif-design-system
toids-core
- 🧨 Util is now renamed to Utils
- 🧨 We have now changed the navigation structure for the documentation site. Please update any saved links!
- 🧨 Navigation structure has now changed. Please see release notes!
Documentation Updates
-
✏️ Move position of the quick links (5cb0897)
-
✏️ Remove unneeded margins for shortcuts (36c7e8d)
-
✏️ Separate out CSS documentation (a4c9341) , closes #467386
-
✏️ Update links and change navigation structure (0bfd27d) , closes #490579
Code Refactoring
-
💡 Reduce spacing tokens, use correct size tokens (97aa461)
-
💡 Rename scope and repository (3ea5423)
-
💡 Use new navigation structure for documentation (415aee5) , closes #490579
-
another change in the structure (38a0d2e)
Miscellaneous chores
bootstrap (6fc1ed8)
reinstall (da80dba)
13.11.0 (2021-10-19)
Features
- 🎸 Input field hot reload (eac76b7)
13.7.0 (2021-09-22)
Documentation Updates
- ✏️ Update linking layout and naming (15c383b)
13.6.3 (2021-09-17)
Bug Fixes
13.6.0 (2021-09-08)
Documentation Updates
bootstrap (d23e139)
- 🤖 Use correct order for diff (cc6a4fd)
13.0.0 (2021-08-25)
⚠ BREAKING CHANGES
-
🧨 We are removing IE11 support
-
🤖 Remove IE11 support for product-matrix-table (8d70520) , closes #336127
12.14.1 (2021-08-12)
Miscellaneous chores
12.13.1 (2021-08-11)
Bug Fixes
-
🐛 Whitelist docs dir for npm packaging (1a5cfd0) , closes #457621
-
🤖 Remove .gitignore, use npm package.json files instead, ignore zip files for npm pack (49f0269) , closes #412081 . This will whitelist files to be used in "npm pack"
-
🤖 Reinstall (e660696)
-
🤖 Update published date (61e7ccf)
12.6.0 (2021-05-27)
Bug Fixes
12.0.0 (2021-05-05)
⚠ BREAKING CHANGES
- 🧨 All of the mixins have now been renamed
- 🧨 Teasers are no more. It has been replaces with Lifestyle Navigational Card, Text Navigational Card. Studio Teasers is gone, use Studio Navigational Card instead, which is based on the old Studio Crosslinks
- 🧨 Notification is now renamed to Alert Banner
- 🧨 This extracts the Hero variation with no image into a separate, design updated component named Header
- 🧨 Footer is now renamed to Global Footer
- 🧨 Selection controls is no more. Has ceased to be. Bereft of life, it rests in peace. This is an ex-component. The component is split into Radio Buttons, Toggle Control and Checkbox
Features
-
🎸 Extract components from selection control (50607a4) , closes #336508
-
🎸 Rename and extract and update hero with no image to (384eb77) , closes #336508 . Header component
Bug Fixes
- 🐛 Update references (c08f107)
Code Refactoring
-
💡 Remove Teasers, added Text and Lifestyle cards (1247479) , closes #336508
-
💡 Rename Notification to Alert Banner (8b4e48d) , closes #336508
Miscellaneous chores
-
🤖 Convert typography tokens from theo to SD (e48f255)
-
🤖 Convert util tokens from theo to style-dictionary (99fb4f5)
-
🤖 Finalize breakpoint token conversion (f50ea0d)
-
🤖 Make sure all components are named with capital first (08e9a26)
-
🤖 Reinstall (2c763ea)
-
🤖 Reinstall (69e1a5b)
-
🤖 Update all design token references (c640d15)
-
🤖 Update references to util variables (b79ec36)
-
🤖 Updating links (70f166e)
rebuild (7edb430)
-
🤖 Rename Change Log to Changelog (d412e63)
-
🤖 Remove all references to sketch (35fc554) , closes #339203
-
🤖 Update package fields (200c0af)
-
reinstall packages (fcfacf4)
7.12.0 (2020-12-08)
Features
6.43.3 (2020-11-03)
Miscellaneous chores
reinstall (2cefe15)
6.36.0 (2020-10-12)
Features
- 🎸 Add updated focus styling for product-matrix-table (f1c375e)
Miscellaneous chores
6.29.4 (2020-09-09)
Documentation Updates
- ✏️ Use correct strong element with if class (6b484df)
6.29.3 (2020-09-07)
Documentation Updates
- ✏️ Merge atoms/molecules/organisms into components (90ed590)
6.26.12 (2020-08-03)
Documentation Updates
- ✏️ Update documentation for the new registry (3e7ba20)
Miscellaneous chores
-
🤖 lerna bootstrap (d835ec9)
-
🤖 Temporarily remove package-lock.json-files (87b3f7f)
-
🤖 Update references to new scope (b5575dd)
6.26.10 (2020-07-14)
Miscellaneous chores
-
🤖 Manually update some links (ecc0133)
-
🤖 Update CHANGELOG.md links to workitems and commits (ab2887b)
6.23.0 (2020-07-01)
Miscellaneous chores
reinstall (1ab1527)
6.22.0 (2020-07-01)
Miscellaneous chores
- 🤖 Search and replace old color usage (3e5abb0)
6.21.6 (2020-06-11)
Miscellaneous chores
- 🤖 Remove .zip files from .npmignore (b3bc7dc)
6.19.0 (2020-06-02)
Miscellaneous chores
reinstall (3416c65)
6.15.5 (2020-05-15)
Miscellaneous chores
-
prepped and ready to separate documentation site from code (d3e1fd9)
-
pruning and reinstalling (5cda0bc)
-
Remove livingcss data and add frontmatter data (b384946)
6.15.4 (2020-05-14)
Miscellaneous chores
6.11.0 (2020-04-22)
Bug Fixes
- 🐛 Add sr only text for footer logo link (2971dd9)
6.10.9 (2020-04-22)
Miscellaneous chores
- 🤖 Add *.zip-files to .npmignore-files (062b8b0)
6.10.6 (2020-04-17)
Miscellaneous chores
- 🤖 lerna bootstrap (d8faf26)
6.9.1 (2020-04-16)
Documentation Updates
- ✏️ Use correct badge color in README.md (03b563e)
6.6.0 (2020-04-09)
Documentation Updates
- ✏️ Change edit this document to edit this section (791b646)
6.5.4 (2020-04-08)
Bug Fixes
6.5.3 (2020-04-06)
Documentation Updates
- ✏️ Some more sg updates and tweaks (d1d6802)
6.3.4 (2020-04-01)
Miscellaneous chores
- 🤖 Use more of if styling on documentation site (2eaf386)
6.3.2 (2020-03-31)
Documentation Updates
- ✏️ Replace sg.message with if.notification (5d1aa99)
5.2.0 (2020-03-17)
Code Refactoring
- 💡 Reorganized sections in the documentations (dd31802) . Adjust navigation styling on the left hand side. The reorganization is mostly to make the site load a bit smoother
5.0.4 (2020-03-14)
Miscellaneous chores
5.0.1-alpha.160 (2020-03-12)
Miscellaneous chores
5.0.1-alpha.151 (2020-03-05)
Features
- 🎸 Add new typography rule for captions. Refactor weights (a033f4e) . and updated documentation
5.0.1-alpha.150 (2020-03-05)
Bug Fixes
- 🐛 Adjusting components to baseline grid (5a53cd9)
5.0.1-alpha.149 (2020-03-05)
Miscellaneous chores
-
🤖 Finish adjusting components to baseline grid (50f7a69) . Chang approx 6888 raw values to variables
-
🤖 Start updating documentation with the changed grid (85a468b)
-
🤖 Starting to align components to new baseline grid (cf2c073)
-
Align typography to baseline. First attempt (f4447e9)
5.0.1-alpha.147 (2020-03-02)
Miscellaneous chores
5.0.1-alpha.143 (2020-02-26)
Documentation Updates
- ✏️ Some tweaks (4db6b23)
5.0.1-alpha.127 (2020-02-18)
Documentation Updates
- ✏️ Add some icon to footer in all demo and doc files (f2bdaae)
5.0.1-alpha.120 (2020-02-17)
Bug Fixes
- 🐛 Imports and usage of extend (f22b281)
Documentation Updates
- ✏️ Update demo page for product matrix with layout helper (f1af8e5)
Miscellaneous chores
- 🤖 Use variables instead of hardcoded values (db103b1)
5.0.1-alpha.117 (2020-02-06)
Documentation Updates
- ✏️ Add edit links to documentation files (7c6e770)
5.0.1-alpha.110 (2020-01-21)
Bug Fixes
5.0.1-alpha.87 (2019-12-04)
Bug Fixes
- 🐛 Several fixes (3cb042e)
5.0.1-alpha.79 (2019-12-03)
Documentation Updates
- ✏️ Scope all examples to .if (26bd7cd)
5.0.1-alpha.76 (2019-12-02)
Bug Fixes
- 🐛 Reduce greedy selector (fd8d7f2)
5.0.1-alpha.70 (2019-11-28)
Miscellaneous chores
- 🤖 Remove polymer, updated styling accordingly (04e1941)
5.0.1-alpha.67 (2019-11-26)
Bug Fixes
5.0.1-alpha.62 (2019-11-24)
Miscellaneous chores
- 🤖 Some documentation fixes (8d66129)
5.0.1-alpha.59 (2019-11-22)
Bug Fixes
- 🐛 Make state list wider for items (fee039e)
5.0.1-alpha.58 (2019-11-22)
Features
- 🎸 Remove normalize.css (2c23c2b)
Miscellaneous chores
5.0.1-alpha.57 (2019-11-22)
Miscellaneous chores
- 🤖 lerna bootstrap (99e08e6)
5.0.1-alpha.56 (2019-11-22)
Features
Bug Fixes
-
🐛 Fix javascript and css implementation for selecting cols (dc9a38e)
-
🐛 Prevent overflow on radio button (fc56a5e)
-
add fake blocks for now (f188b0c)
Documentation Updates
-
✏️ Continue documenting the product matrices (70ba770)
-
✏️ Finalize documentation for product matrices, for now (a7d8405)
-
✏️ Update documentation (1334d99)
Miscellaneous chores
-
🤖 Adjustments for product matrices (f0d14f5)
-
🤖 Contiue to improve the matrix (b9b518d)
-
🤖 Created mixin for the selectable and focusabled th (75cbb25)
-
🤖 Finalize the first version of the product matrix (49306a8)
-
🤖 Finish mobile version (9f9f581)
-
🤖 lerna bootstrap (a01ebb6)
-
🤖 lerna bootstrap (01db73c)
-
more touchups for matrix (4fbc1bf)