Skip to content

Commit

Permalink
feat(pix-progress-gauge): add isDecorative attribute
Browse files Browse the repository at this point in the history
Co-authored-by: Clément Latzarus <[email protected]>
  • Loading branch information
dianeCdrPix and clemlatz committed Nov 12, 2024
1 parent 12e59a0 commit 8da5292
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
6 changes: 5 additions & 1 deletion addon/components/pix-progress-gauge.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<div class="progress-gauge {{this.themeMode}} {{this.colorClass}}" ...attributes>
<div
class="progress-gauge {{this.themeMode}} {{this.colorClass}}"
role={{if @isDecorative "presentation"}}
...attributes
>
{{#unless @hidePercentage}}
<div class="progress-gauge__text" role="presentation">{{this.percentageValue}}</div>
{{/unless}}
Expand Down
4 changes: 3 additions & 1 deletion addon/components/pix-progress-gauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export default class PixProgressGauge extends Component {
}

get label() {
if (!this.args.label || !this.args.label.trim()) {
const thereIsNoLabel = !this.args.label || !this.args.label.trim();

if (thereIsNoLabel && !this.args.isDecorative) {
throw new Error('ERROR in PixProgressGauge component, @label param is not provided.');
}
return this.args.label;
Expand Down
3 changes: 2 additions & 1 deletion app/stories/pix-progress-gauge.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as ComponentStories from './pix-progress-gauge.stories';

Permet d'afficher un barre de progression sur un barème de 100%. Des paramètres existent pour changer le mode (dark ou light) ou la couleur du composant.

> **⚠️** **Il est nécessaire d'avoir un `label` pour rendre le composant accessible !**
> **⚠️** **Il est nécessaire d'avoir un `label` pour rendre le composant accessible, sauf si le composant est utilisé uniquement pour de la décoration. Dans ce cas, mettre le paramètre `@isDecorative` à `true`.**
<Story of={ComponentStories.Default} height={60} />

Expand All @@ -33,6 +33,7 @@ Démonstration d'une barre de progression blanche en dark mode avec un sous titr
@themeMode="dark"
@subTitle="Un sous titre"
@hidePercentage=false
@isDecorative={{true}}
/>
```

Expand Down
7 changes: 7 additions & 0 deletions app/stories/pix-progress-gauge.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export default {
type: { name: 'boolean', required: false },
table: { defaultValue: { summary: 'false' } },
},
isDecorative: {
name: 'isDecorative',
description:
'Indiquer que la barre de progression est utilisée pour de la présentation et doit être ignorée par les lecteurs d’écran',
type: { name: 'boolean', required: false },
table: { defaultValue: { summary: 'false' } },
},
},
};

Expand Down
20 changes: 20 additions & 0 deletions tests/integration/components/pix-progress-gauge-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ module('Integration | Component | progress-gauge', function (hooks) {
component.label;
}, expectedError);
});

test('it should not throw an error if there is no label and if @isDecorative is true', async function (assert) {
// given & when
const componentParams = { label: null, isDecorative: true };
const component = createGlimmerComponent('pix-progress-gauge', componentParams);

// then
component.label;
assert.ok(true);
});
});

module('Attributes @color', function () {
Expand Down Expand Up @@ -206,4 +216,14 @@ module('Integration | Component | progress-gauge', function (hooks) {
assert.dom('.progress-gauge__text').doesNotExist();
});
});

module('Attributes @isDecorative', function () {
test('it sets gauge role to "presentation"', async function (assert) {
// when
await render(hbs`<PixProgressGauge @value='50' @isDecorative='true' />`);

// then
assert.dom('.progress-gauge').hasProperty('role', 'presentation');
});
});
});

0 comments on commit 8da5292

Please sign in to comment.