Skip to content

Commit 1f2e4c0

Browse files
committed
Add a defaultOpen argument to the AuAccordion component
1 parent 42d72f8 commit 1f2e4c0

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

addon/components/au-accordion.gts

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface AuAccordionSignature {
1818
buttonLabel?: string;
1919
iconClosed?: string;
2020
iconOpen?: string;
21+
defaultOpen?: boolean;
2122
loading?: boolean;
2223
reverse?: boolean;
2324
skin?: 'border';
@@ -30,7 +31,13 @@ export interface AuAccordionSignature {
3031
}
3132

3233
export default class AuAccordion extends Component<AuAccordionSignature> {
33-
@tracked isOpen = false;
34+
@tracked isOpen;
35+
36+
constructor(owner: unknown, args: AuAccordionSignature['Args']) {
37+
super(owner, args);
38+
39+
this.isOpen = Boolean(this.args.defaultOpen);
40+
}
3441

3542
get loading() {
3643
if (this.args.loading) return 'is-loading';

stories/5-components/Content/AuAccordion.stories.js

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ export default {
3434
control: 'boolean',
3535
description: 'Adds a loading state to the button',
3636
},
37+
defaultOpen: {
38+
control: 'boolean',
39+
description:
40+
'When set to true, this will render the accordion in the "open" state from the start.',
41+
},
3742
},
3843
parameters: {
3944
layout: 'padded',
@@ -50,6 +55,7 @@ const Template = (args) => ({
5055
@iconClosed={{this.iconClosed}}
5156
@buttonLabel={{this.buttonLabel}}
5257
@loading={{this.loading}}
58+
@defaultOpen={{this.defaultOpen}}
5359
>
5460
<p>I am information. I can even contain a <AuLink>A Link</AuLink>!</p>
5561
</AuAccordion>`,
@@ -65,4 +71,5 @@ Component.args = {
6571
iconClosed: 'nav-right',
6672
buttonLabel: 'Accordion with arrows',
6773
loading: false,
74+
defaultOpen: false,
6875
};

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

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ module('Integration | Component | au-accordion', function (hooks) {
3535
assert.dom(ACCORDION.CONTENT).doesNotExist();
3636
});
3737

38+
test('it renders the content by default if `defaultOpen` is set to `true`', async function (assert) {
39+
await render(
40+
<template>
41+
<AuAccordion @defaultOpen={{true}}>
42+
Content
43+
</AuAccordion>
44+
</template>,
45+
);
46+
47+
assert.dom(ACCORDION.CONTENT).exists().hasText('Content');
48+
});
49+
3850
test('it toggles its content rendering when clicking it', async function (assert) {
3951
await render(
4052
<template>

0 commit comments

Comments
 (0)