Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TECH] Autorise les lignes du tableaux à avoir une cellule de type heading scope "row" (PIX-16895) #838

Merged
merged 3 commits into from
Mar 7, 2025
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
12 changes: 9 additions & 3 deletions addon/components/pix-table-column.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
</div>
</th>
{{else}}
<td ...attributes class={{this.typeClass}}>
{{yield to="cell"}}
</td>
{{#if @isMainRow}}
<th scope="row" class={{this.typeClass}} ...attributes>
{{yield to="cell"}}
</th>
{{else}}
<td class={{this.typeClass}} ...attributes>
{{yield to="cell"}}
</td>
{{/if}}
{{/if}}
2 changes: 1 addition & 1 deletion addon/styles/_pix-table-column.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.pix-table-column {
&--number{
text-align: right;
text-align: left;
}
}
8 changes: 7 additions & 1 deletion addon/styles/_pix-table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,17 @@
align-items: center;
}

th {
th[scope='col'] {
font-weight: var(--pix-font-bold);
text-align: start;
vertical-align: middle;
}

th[scope='row'] {
font-weight: var(--pix-font-normal);
}


td, th {
padding: var(--pix-spacing-6x) var(--pix-spacing-4x);

Expand Down
11 changes: 10 additions & 1 deletion app/stories/pix-table-column.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ export default {
description: 'Defini le style avec lequel nous afficherons la colonne',
},
},
isMainRow: {
name: 'isMainRow',
description:
'Permet de définir la cellule qui portera la valeur principale de la ligne entière',
type: {
name: 'boolean',
required: false,
},
},
header: {
name: '<:header>',
description: 'En-tête de la colonne',
Expand All @@ -75,7 +84,7 @@ const Template = (args) => {
return {
template: hbs`<PixTable @data={{this.data}} @caption={{this.caption}}>
<:columns as |row context|>
<PixTableColumn @context={{context}}>
<PixTableColumn @context={{context}} @isMainRow={{this.isMainRow}}>
<:header>
Nom
</:header>
Expand Down
34 changes: 33 additions & 1 deletion tests/integration/components/pix-table-column-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,39 @@ module('Integration | Component | table-column', function (hooks) {
const cell = screen.queryByRole('cell', { name: '15' });
assert.dom(cell).exists();
const textAlign = window.getComputedStyle(cell).getPropertyValue('text-align');
assert.strictEqual(textAlign, 'right');
assert.strictEqual(textAlign, 'left');
});
});

module('when isMainRow defined', function () {
test('it renders a defined row title', async function (assert) {
// when
const screen = await render(
hbs`<PixTable @caption='Ceci est le caption de notre table' @data={{this.data}}>
<:columns as |row context|>
<PixTableColumn @context={{context}} @isMainRow={{true}}>
<:header>
Nom
</:header>
<:cell>
{{row.name}}
</:cell>
</PixTableColumn>
<PixTableColumn @context={{context}} @type='number'>
<:header>
Âge
</:header>
<:cell>
{{row.age}}
</:cell>
</PixTableColumn>
</:columns>
</PixTable>`,
);

// then
const row = screen.getByRole('row', { name: 'jean 15' });
assert.ok(row);
});
});
});