Skip to content

Commit 9787274

Browse files
authored
Merge pull request #479 from appuniversum/fix/modal-classes-incompatibilities
Fix incompatibilities between some `AuModal` arguments
2 parents 6c40168 + 9ac673c commit 9787274

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

addon/components/au-modal.gjs

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { on } from '@ember/modifier';
55
import { action } from '@ember/object';
66
import Component from '@glimmer/component';
77
import { focusTrap } from 'ember-focus-trap';
8+
import { cn } from '../private/helpers/class-names';
89

910
// TODO: replace these with the named imports from ember-truth-helpers v4 once our dependencies support that version
1011
import not from 'ember-truth-helpers/helpers/not';
@@ -33,7 +34,7 @@ export default class AuModal extends Component {
3334
}
3435

3536
get padding() {
36-
if (this.args.padding === 'none') return ' au-c-modal--flush';
37+
if (this.args.padding === 'none') return 'au-c-modal--flush';
3738
else return '';
3839
}
3940

@@ -89,12 +90,12 @@ export default class AuModal extends Component {
8990
<div class="au-c-modal-backdrop {{if @modalOpen 'is-visible'}}"></div>
9091
<div
9192
id="{{@id}}"
92-
class={{concat
93-
"au-c-modal "
93+
class={{cn
94+
"au-c-modal"
9495
this.size
9596
this.padding
9697
this.overflow
97-
(if @modalOpen " is-visible")
98+
(if @modalOpen "is-visible")
9899
}}
99100
role="dialog"
100101
aria-describedby={{concat "au-c-modal-title-" @id}}

addon/private/helpers/class-names.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* A very basic alternative to https://github.com/JedWatson/classnames
3+
*/
4+
export function cn(...classNames: Array<string | undefined>) {
5+
return classNames.filter(Boolean).join(' ');
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { settled, render } from '@ember/test-helpers';
2+
import { tracked } from '@glimmer/tracking';
3+
import { setupRenderingTest } from 'ember-qunit';
4+
import { module, test } from 'qunit';
5+
import { cn } from '@appuniversum/ember-appuniversum/private/helpers/class-names';
6+
7+
module('Integration | Private Helper | class-names', function (hooks) {
8+
setupRenderingTest(hooks);
9+
10+
test('it accepts a list of classes and adds the needed whitespace', async function (assert) {
11+
await render(
12+
<template>
13+
<div data-test class={{cn "foo" "bar" "baz"}}></div>
14+
</template>,
15+
);
16+
17+
assert.dom('[data-test]').hasClass('foo').hasClass('bar').hasClass('baz');
18+
});
19+
20+
test('it removes falsy values', async function (assert) {
21+
class TestState {
22+
@tracked someFlag: boolean = false;
23+
}
24+
25+
const state = new TestState();
26+
await render(
27+
<template>
28+
<div data-test class={{cn "foo" (if state.someFlag "bar") "baz"}}></div>
29+
</template>,
30+
);
31+
32+
assert.dom('[data-test]').hasClass('foo').hasNoClass('bar').hasClass('baz');
33+
34+
state.someFlag = true;
35+
await settled();
36+
37+
assert.dom('[data-test]').hasClass('foo').hasClass('bar').hasClass('baz');
38+
});
39+
});

0 commit comments

Comments
 (0)