Skip to content

Commit

Permalink
✨ feat(table): supporte le comportement row-select via data attribu…
Browse files Browse the repository at this point in the history
…te (#1053)

- la sélection de ligne du tableau est implémentée via l'attribut data-fr-row-select="true" sur la case à cocher, le fonctionnement via l'attribut name="row-select" est déprécié.
  • Loading branch information
colinux authored Nov 26, 2024
1 parent a11427c commit da2a973
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ for(let r = 0; r < rowsLength; r++) {
markup: 'th',
attributes: {scope: 'row'},
classes: [`${prefix}-cell--fixed`],
content: getCheckbox({id: `${table.id}-select-row-checkbox-${r + 1}`, label: `${getText('data.cell.action.selectRow', 'table')} ${r + 1} : ${getText('data.cell.title', 'table')}`, attributes: {name: 'row-select', checked: selectedLines.includes(r) || undefined}}) + getTitleCell('span')
content: getCheckbox({id: `${table.id}-select-row-checkbox-${r + 1}`, label: `${getText('data.cell.action.selectRow', 'table')} ${r + 1} : ${getText('data.cell.title', 'table')}`, attributes: {[`data-${prefix}-row-select`]: 'true', checked: selectedLines.includes(r) || undefined}}) + getTitleCell('span')
},
{
content: getText('data.cell.text', 'table')
Expand Down
2 changes: 1 addition & 1 deletion src/dsfr/component/table/example/data/data-simple.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if (table.selectable) {
markup: 'th',
attributes: {scope: 'row'},
classes: [`${prefix}-cell--fixed`],
content: getCheckbox({id: `${uniqueId('table-select-checkbox')}--${index}`, label: `${getText('data.cell.action.selectRow', 'table')} ${index + 1}`, attributes: {name: 'row-select'}})
content: getCheckbox({id: `${uniqueId('table-select-checkbox')}--${index}`, label: `${getText('data.cell.action.selectRow', 'table')} ${index + 1}`, attributes: {[`data-${prefix}-row-select`]: 'true'}})
});
});
});
Expand Down
3 changes: 2 additions & 1 deletion src/dsfr/component/table/script/table/table-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class TableRow extends api.core.Instance {
}

_handleCheckboxChange (node) {
if (node.name === 'row-select') {
if (node.name === 'row-select' ||
node.getAttribute(api.internals.ns.attr('row-select')) === 'true') {
this.isSelected = node.checked === true;
}
}
Expand Down

0 comments on commit da2a973

Please sign in to comment.