Skip to content

Commit 88e44dd

Browse files
committed
Improve no icon logic with test
1 parent ecf3890 commit 88e44dd

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

packages/components/addon/components/hds/alert/index.hbs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<div class={{this.classNames}} ...attributes role="alert">
22
{{! template-lint-disable simple-unless}}
3-
{{#unless (eq this.icon "")}}
3+
{{!-- {{#unless (eq this.icon "")}} --}}
4+
{{#if this.icon}}
45
<div class="hds-alert__icon">
56
<FlightIcon @name={{this.icon}} @size="24" @isInlineBlock={{false}} />
67
</div>
7-
{{/unless}}
8+
{{/if}}
9+
{{!-- {{/unless}} --}}
810

911
<div class="hds-alert__content">
1012
<div class="hds-alert__text">

packages/components/addon/components/hds/alert/index.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,15 @@ export default class HdsAlertIndexComponent extends Component {
7676
get icon() {
7777
let { icon } = this.args;
7878

79-
if (icon === '') {
80-
return icon;
79+
// If `icon` isn't passed, use the pre-defined one from `color`
80+
if (icon === undefined) {
81+
return MAPPING_COLORS_TO_ICONS[this.color];
82+
// If `icon` is set explicitly to false, user doesn't want any icon in the alert
83+
} else if (icon === false) {
84+
return false;
8185
} else {
82-
return icon || MAPPING_COLORS_TO_ICONS[this.color];
86+
// If a name for `icon` is passed, set FlightIcon to that name
87+
return icon;
8388
}
8489
}
8590

packages/components/tests/integration/components/hds/alert/index-test.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,20 @@ module('Integration | Component | hds/alert/index', function (hooks) {
3535
.exists();
3636
});
3737

38+
test('Alert should display no icon, when empty string is passed', async function (assert) {
39+
await render(hbs`<Hds::Alert @title="yo" @icon="" />`);
40+
assert
41+
.dom(
42+
this.element.querySelector('.flight-icon.flight-icon-clipboard-copy')
43+
)
44+
.doesNotExist();
45+
});
46+
3847
// ASSERTIONS
3948

4049
test('Throw an assertion if @title and @description is missing/has no value', async function (assert) {
4150
const errorMessage =
4251
'you need to pass @title or @description to the "Hds::Alert" component';
43-
// TODO: Debug
4452
assert.expect(2);
4553

4654
setupOnerror(function (error) {

0 commit comments

Comments
 (0)