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

fix(accordion): ids that begin with number were not accepted, #4195 #4196

Merged
merged 1 commit into from
Mar 21, 2022

Conversation

ExFlo
Copy link
Collaborator

@ExFlo ExFlo commented Dec 7, 2021

fix #4195

@ExFlo ExFlo force-pushed the fix/accordionsId branch 8 times, most recently from ed0ea61 to 927daf2 Compare December 7, 2021 15:06
@codecov-commenter
Copy link

Codecov Report

Merging #4196 (9b4a23b) into master (3e1a33e) will decrease coverage by 0.02%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4196      +/-   ##
==========================================
- Coverage   88.48%   88.46%   -0.03%     
==========================================
  Files         110      111       +1     
  Lines        3283     3623     +340     
  Branches      639      690      +51     
==========================================
+ Hits         2905     3205     +300     
- Misses        325      368      +43     
+ Partials       53       50       -3     
Flag Coverage Δ
e2e 46.50% <0.00%> (?)
unit 88.49% <100.00%> (+0.01%) ⬆️

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/accordion/accordion.ts 82.45% <88.88%> (-16.45%) ⬇️
src/pagination/pagination.ts 59.12% <0.00%> (-40.88%) ⬇️
src/toast/toast.ts 71.42% <0.00%> (-28.58%) ⬇️
src/progressbar/progressbar.ts 72.22% <0.00%> (-27.78%) ⬇️
src/alert/alert.ts 73.68% <0.00%> (-26.32%) ⬇️
src/datepicker/datepicker-navigation.ts 85.29% <0.00%> (-14.71%) ⬇️
src/carousel/carousel.ts 82.87% <0.00%> (-13.88%) ⬇️
src/rating/rating.ts 87.09% <0.00%> (-12.91%) ⬇️
... and 36 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3e1a33e...9b4a23b. Read the comment docs.

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,

is there actually an issue for this?
The one that is referenced is about something else.

My bad, it's fine

I'm not convinced by passing the id as the event on init and having a special directive for this on my side :)

Can't we just change the query? WDYT?

@@ -425,10 +436,6 @@ export class NgbAccordion implements AfterContentChecked {
}
});
}

private _getPanelElement(panelId: string): HTMLElement | null {
return this._element.nativeElement.querySelector('#' + panelId);
Copy link
Member

Choose a reason for hiding this comment

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

Can't we just querySelector('[id="{panelId}"]') ?

@@ -195,7 +208,7 @@ export interface NgbPanelChangeEvent {
<ng-template [ngTemplateOutlet]="panel.headerTpl?.templateRef || t"
[ngTemplateOutletContext]="{$implicit: panel, opened: panel.isOpen}"></ng-template>
</div>
<div id="{{panel.id}}" role="tabpanel" [attr.aria-labelledby]="panel.id + '-header'"
<div id="{{panel.id}}" (ngbRef)="panel.panelDiv = $event" role="tabpanel" [attr.aria-labelledby]="panel.id + '-header'"
Copy link
Member

Choose a reason for hiding this comment

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

Oh, Im so not convinced by passing id as the event on init :)

Copy link
Member

Choose a reason for hiding this comment

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

Note that this is not an id, it is the reference to the element itself, thus removing the need of an id.

Copy link
Member

Choose a reason for hiding this comment

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

Sure. But on the other hand I just thought that it also avoids doing querySelector for each panel on every ngAfterContentChecked...

Copy link
Member

Choose a reason for hiding this comment

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

ngbRef seems to be inspired from callback refs in react.
We could instead use refs object as in react which would perhaps convince you more than the callback form.

Copy link
Member

Choose a reason for hiding this comment

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

I see, and on my side I can't really find a simpler way to pass the element ref once during the initialization

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.

Hmm, on reflection:

I don't like the idea of firing events in lifecycle hooks, it sometimes leads to nasty side-effects, doesn't it? However in this case ids never change and it's pretty simple, so it looks ok to me. I can't find any simpler ways to do it once on my side.

Simpler version would be to just change selector to use the attribute, but this PR also removes doing querySelector on each ngAfterContentChecked which is a good thing.

I think it is LGTM.

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.

multiple Accordion's build with ngFor ['Element': '#3.1' is not a valid selector.]
4 participants