Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an isOpenInitially argument to the AuAccordion component #469

Merged
merged 3 commits into from
Feb 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add an isOpenInitially argument to the AuAccordion component
  • Loading branch information
Windvis committed Feb 16, 2024
commit 7b6bdb02a9929d1609da39367ad68222ab21e54a
9 changes: 8 additions & 1 deletion addon/components/au-accordion.gts
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ export interface AuAccordionSignature {
buttonLabel?: string;
iconClosed?: string;
iconOpen?: string;
isOpenInitially?: boolean;
loading?: boolean;
reverse?: boolean;
skin?: 'border';
@@ -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';
7 changes: 7 additions & 0 deletions stories/5-components/Content/AuAccordion.stories.js
Original file line number Diff line number Diff line change
@@ -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',
@@ -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>`,
@@ -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
@@ -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>
Loading