Skip to content

Commit

Permalink
Add an isOpenInitially argument to the AuAccordion component
Browse files Browse the repository at this point in the history
  • Loading branch information
Windvis committed Feb 16, 2024
1 parent 42d72f8 commit 7b6bdb0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion addon/components/au-accordion.gts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface AuAccordionSignature {
buttonLabel?: string;
iconClosed?: string;
iconOpen?: string;
isOpenInitially?: boolean;
loading?: boolean;
reverse?: boolean;
skin?: 'border';
Expand All @@ -30,7 +31,13 @@ export interface AuAccordionSignature {
}

export default class AuAccordion extends Component<AuAccordionSignature> {
@tracked isOpen = false;
@tracked isOpen;

constructor(owner: unknown, args: AuAccordionSignature['Args']) {
super(owner, args);

this.isOpen = Boolean(this.args.isOpenInitially);
}

get loading() {
if (this.args.loading) return 'is-loading';
Expand Down
7 changes: 7 additions & 0 deletions stories/5-components/Content/AuAccordion.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export default {
control: 'boolean',
description: 'Adds a loading state to the button',
},
isOpenInitially: {
control: 'boolean',
description:
'When set to `true`, this will render the accordion in the "open" state from the start.',
},
},
parameters: {
layout: 'padded',
Expand All @@ -50,6 +55,7 @@ const Template = (args) => ({
@iconClosed={{this.iconClosed}}
@buttonLabel={{this.buttonLabel}}
@loading={{this.loading}}
@isOpenInitially={{this.isOpenInitially}}
>
<p>I am information. I can even contain a <AuLink>A Link</AuLink>!</p>
</AuAccordion>`,
Expand All @@ -65,4 +71,5 @@ Component.args = {
iconClosed: 'nav-right',
buttonLabel: 'Accordion with arrows',
loading: false,
isOpenInitially: false,
};
12 changes: 12 additions & 0 deletions tests/integration/components/au-accordion-test.gts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ module('Integration | Component | au-accordion', function (hooks) {
assert.dom(ACCORDION.CONTENT).doesNotExist();
});

test('it renders the content by default if `isOpenInitially` is set to `true`', async function (assert) {
await render(
<template>
<AuAccordion @isOpenInitially={{true}}>
Content
</AuAccordion>
</template>,
);

assert.dom(ACCORDION.CONTENT).exists().hasText('Content');
});

test('it toggles its content rendering when clicking it', async function (assert) {
await render(
<template>
Expand Down

0 comments on commit 7b6bdb0

Please sign in to comment.