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

feat(accordion): new accordion directives #4437

Merged

Conversation

ValentinNelu
Copy link
Contributor

Before submitting a pull request, please make sure you have at least performed the following:

  • read and followed the CONTRIBUTING.md and DEVELOPER.md guide.
  • built and tested the changes locally.
  • added/updated any applicable tests.
  • added/updated any applicable API documentation.
  • added/updated any applicable demos.

@maxokorokov
Copy link
Member

<div
	ngbAccordion
	[animation]="animation"
	[closeOthers]="closeOthers"
	[destroyOnHide]="true"
	(shown)="log('shown ' + $event)"
	(hidden)="log('hidden ' + $event)"
>
<!--	ngb-accordion-header-XXX-->
<!--	ngb-accordion-collapse-XXX-->
	<div ngbAccordionItem [destroyOnHide]="true" [disabled] (shown) (hidden) [collapse]="true">
		<h2 ngbAccordionHeader>
			<button ngbAccordionToggle>Accordion Item #1</button>
		</h2>
		<div ngbAccordionCollapse>
			<div ngbAccordionBody>
				<ng-template>
					<strong>This is the first item's accordion body.</strong> It is shown by default, until the collapse plugin
					adds the appropriate classes that we use to style each element. These classes control the overall appearance,
					as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or
					overriding our default variables. It's also worth noting that just about any HTML can go within the
					<code>.accordion-body</code>, though the transition does limit overflow.
				</ng-template>
			</div>
		</div>
	</div>
</div>

@ValentinNelu ValentinNelu force-pushed the feat/accordion-directive branch 3 times, most recently from 5ea1bbe to 0c2801b Compare December 16, 2022 13:41
@ValentinNelu
Copy link
Contributor Author

Need to add proper documentation, and do the demo page.
Should we split it in a different module or keep all in the ngb-accordion module?

@codecov-commenter
Copy link

codecov-commenter commented Dec 16, 2022

Codecov Report

Base: 88.67% // Head: 88.84% // Increases project coverage by +0.17% 🎉

Coverage data is based on head (5a5c86f) compared to base (39715ee).
Patch coverage: 95.69% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4437      +/-   ##
==========================================
+ Coverage   88.67%   88.84%   +0.17%     
==========================================
  Files         114      115       +1     
  Lines        3999     4096      +97     
  Branches      843      864      +21     
==========================================
+ Hits         3546     3639      +93     
- Misses        413      417       +4     
  Partials       40       40              
Flag Coverage Δ
e2e 53.53% <9.75%> (-0.97%) ⬇️
unit 89.34% <98.79%> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/accordion/accordion.module.ts 100.00% <ø> (ø)
src/index.ts 100.00% <ø> (ø)
src/accordion/accordion.directive.ts 95.69% <95.69%> (ø)
src/rating/rating.ts 84.93% <0.00%> (ø)
src/popover/popover.ts 95.12% <0.00%> (ø)
src/tooltip/tooltip.ts 98.57% <0.00%> (ø)
src/util/positioning.ts 100.00% <0.00%> (ø)
src/dropdown/dropdown.ts 91.42% <0.00%> (ø)
src/modal/modal.module.ts 100.00% <0.00%> (ø)
src/typeahead/typeahead.ts 96.35% <0.00%> (ø)
... and 3 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@maxokorokov maxokorokov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, @ValentinNelu, looks good overall!

Left some comments (details in code comments):

  1. Please use underscore for all private vars private _varName, not private varName. Sorry, it's the repository code style.
  2. I'm not convinces with how disabled is handled, also the demo doesn't seem to work to me? You should be able to open/ close disabled panels via API, but user shouldn't. Some old tests checking this are missing: ex. we've had it('should not open disabled panels from click') test and it('should open/collapse disabled panels'). Now you seem to have different behavior.(let's discuss it)
  3. Subscriptions are leaking
  4. Seems like destroyOnHide might not work properly at runtime

I haven't checked test code coverage and API coverage yet.
Will do after your fixes!

Cheers,
Max

standalone: true,
imports: [NgTemplateOutlet],
host: { '[class.accordion-body]': 'true' },
template: ` <ng-template [ngTemplateOutlet]="addToDOM() ? bodyTpl : null" ]></ng-template> `,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idea: maybe it is even better to extract it into something like

<ng-template [ngTemplateOutlet]="template()"></ng-template>

WDYT?

@ContentChild(TemplateRef) bodyTpl: TemplateRef<any>;

addToDOM() {
return this.item.destroyOnHide === false || this.item.animatingBodyCollapse;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.item.destroyOnHide is only initialized once, so it might be wrong I guess.

export class NgbAccordionBody {
constructor(@Inject(forwardRef(() => NgbAccordionItem)) private item: NgbAccordionItem) {}

@ContentChild(TemplateRef) bodyTpl: TemplateRef<any>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should have {static: true} option

standalone: true,
selector: '[ngbAccordionCollapse]',
host: {
role: 'region',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will a user be able to override a role is necessary?

'[class.collapsed]': 'item.collapsed',
'[attr.aria-controls]': 'item.collapseId',
'[attr.aria-expanded]': '!item.collapsed',
'[type]': '"button"',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just 'type': 'button' ?

* Has no effect if the panel is disabled.
*/
toggle(itemId: string) {
if (this.canBeToggled(itemId)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doing this.canBeToggled seemed like a lot of redundant work, but indeed I don't see how to do it better...

src/accordion/accordion.directive.ts Show resolved Hide resolved
}
} else {
this.items.forEach((item) => {
if (!item.disabled) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about disabled handling again... why can't you work with disabled items programmatically? I understand that the user can't do anything with them, but why do APIs not allow it?

}

collapse(itemId: string) {
this.items.find((item) => item.id === itemId)!.collapsed = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should fail when find finds no matching item. Tests missing?

}

private canBeToggled(itemId: string) {
return this.items.find((item) => item.id === itemId && !item.disabled) ? true : false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: might be simpler with !!this._items.find...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants