Skip to content

Commit

Permalink
feat(accordion): Disable content clicking (#571)
Browse files Browse the repository at this point in the history
* feat(accordion): Disable content clicking

* chore: Update package version

* chore: PR review
  • Loading branch information
TSenter authored May 9, 2024
1 parent 747baf9 commit ddba7d2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions addon/components/nrg-accordion.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
{{/if}}
</div>
<div
class="{{if item.active 'active '}}content"
data-accordion-hash={{item.hash}}
class="{{if item.active 'active '~}}
{{unless this.closeOnContentClick 'no-click'}}
content"
data-accordion-hash={{item.contentHash}}
>
{{#if @freeform}}
{{yield item.data item.active to="content"}}
Expand Down
9 changes: 7 additions & 2 deletions addon/components/nrg-accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ export default class NrgAccordionComponent extends Component {

get mappedItems() {
const items = this.args.items ?? [];
const { openItems } = this;
const { openItems, closeOnContentClick } = this;

return items.map((item) => {
const hash = stringHash(objectHash(item)).toString(36);
const contentHash = closeOnContentClick ? hash : undefined;
const active = openItems.includes(hash);

return { data: item, hash, active };
return { data: item, hash, contentHash, active };
});
}

Expand Down Expand Up @@ -82,6 +83,10 @@ export default class NrgAccordionComponent extends Component {
return this.args.forceOpen === true;
}

get closeOnContentClick() {
return this.args.contentClickable !== true;
}

openItem(item) {
this.openItems.pushObject(item.hash);

Expand Down
4 changes: 4 additions & 0 deletions addon/styles/addon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ textarea {
[role='button']:not(.disabled):not([disabled]) {
cursor: pointer;
}

.ui.accordion > div.content.no-click {
cursor: default;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-nrg-ui",
"version": "4.7.2",
"version": "4.7.3",
"description": "Opinionated UI addon based on how KUB scaffolds web applications",
"keywords": [
"ember-addon",
Expand Down

0 comments on commit ddba7d2

Please sign in to comment.