Skip to content

Commit 1f0b8b3

Browse files
authored
[AuButton] deprecate the default loading message (#497)
The default loading message is a footgun. Many projects forget to properly set this which means the default is used, even though it's not a good fit for the context. By requiring an explicit loading message this should no longer be an issue.
1 parent 7274779 commit 1f0b8b3

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

addon/components/au-button.gts

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Component from '@glimmer/component';
2+
import { deprecate } from '@ember/debug';
23
import AuIcon, { type AuIconSignature } from './au-icon';
34
import { LoadingAnimation } from '../private/components/loading-animation';
45

@@ -71,8 +72,31 @@ export default class AuButton extends Component<AuButtonSignature> {
7172
}
7273

7374
get loadingMessage() {
74-
if (this.args.loadingMessage) return this.args.loadingMessage;
75-
else return 'Aan het laden';
75+
if (this.args.loadingMessage) {
76+
return this.args.loadingMessage;
77+
}
78+
79+
deprecate(
80+
`[AuButton] Not providing \`@loadingMessage\` when setting \`@loading\` to \`true\` is deprecated. Add the \`@loadingMessage\` argument explicitly.
81+
82+
Use \`@loadingMessage="Aan het laden"\` to get the same behavior as before.
83+
84+
More info in the migration guide: https://github.com/appuniversum/ember-appuniversum/pull/497
85+
86+
`,
87+
false,
88+
{
89+
id: '@appuniversum/ember-appuniversum.au-button-loading-message',
90+
until: '4.0.0',
91+
for: '@appuniversum/ember-appuniversum',
92+
since: {
93+
available: '3.5.0',
94+
enabled: '3.5.0',
95+
},
96+
},
97+
);
98+
99+
return 'Aan het laden';
76100
}
77101

78102
get isIconLeft() {

tests/integration/components/au-button-test.gts

+45
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { setupRenderingTest } from 'ember-qunit';
33
import { render, settled } from '@ember/test-helpers';
44
import AuButton from '@appuniversum/ember-appuniversum/components/au-button';
55
import { tracked } from '@glimmer/tracking';
6+
import { hasDeprecationStartingWith } from 'dummy/tests/helpers/deprecations';
67

78
class TestState {
89
@tracked isDisabled?: boolean;
910
@tracked isLoading?: boolean;
11+
@tracked loadingMessage?: string;
1012
}
1113

1214
module('Integration | Component | au-button', function (hooks) {
@@ -65,4 +67,47 @@ module('Integration | Component | au-button', function (hooks) {
6567
await settled();
6668
assert.dom('[data-test-button]').isDisabled();
6769
});
70+
71+
test('the default loading message is deprecated', async function (assert) {
72+
const state = new TestState();
73+
state.isLoading = false;
74+
75+
await render(
76+
<template>
77+
<AuButton
78+
@loading={{state.isLoading}}
79+
@loadingMessage={{state.loadingMessage}}
80+
data-test-button
81+
>
82+
Foo
83+
</AuButton>
84+
</template>,
85+
);
86+
87+
assert.false(
88+
showsDeprecationMessage(),
89+
"it does't show the deprecation if @loading isn't true",
90+
);
91+
92+
state.isLoading = true;
93+
state.loadingMessage = 'Loading';
94+
await settled();
95+
assert.false(
96+
showsDeprecationMessage(),
97+
"it does't show the deprecation if @loadingMessage is set",
98+
);
99+
100+
state.loadingMessage = undefined;
101+
await settled();
102+
assert.true(
103+
showsDeprecationMessage(),
104+
"it shows the deprecation message if @loadingMessage isn't set",
105+
);
106+
});
68107
});
108+
109+
function showsDeprecationMessage() {
110+
return hasDeprecationStartingWith(
111+
'[AuButton] Not providing `@loadingMessage` when setting `@loading` to `true` is deprecated.',
112+
);
113+
}

0 commit comments

Comments
 (0)