Accordion Feature Request - Title Content that does not cause expand/collapse
See original GitHub issueHi Guys, nice work on the library, it’s really starting to take shape! Thanks for your all your effort!
I have a feature request that I’d like to run by you and discuss. From what I can tell, when the ngbPanelTitle
directive is used with the accordion, all the content is wrapped in an <a>
element and as such all content will toggle the collapse state of the panel.
I have a use case where I’d like to have content in the panel header/title which does not toggle the collapse state.
For example…
<ngb-accordion>
<ngb-panel>
<template ngbPanelTitle>
<span>Click on me to toggle panel</span>
<span>Non toggle text</span>
<input placeholder="Should not cause expand/collapse">
</template>
<template ngbPanelContent>
Some Settings
</template>
</ngb-panel>
</ngb-accordion>
So with the present implementation, both <span>
and the <input>
elements will cause the toggling to occur.
Is there a way to achieve this with the current implementation ?
The first idea that comes to mind is to have another directive, say ngbPanelHeader
for argument’s sake, that is the same as ngbPanelTitle
, but does not get wrapped in the <a>
element.
So the above example would now look something like this
<ngb-accordion #acc="ngbAccordion">
<ngb-panel id="1">
<template ngbPanelHeader>
<span (click)="acc.toggle('1')">Click on me to toggle panel</span>
<span>Non toggle text</span>
<input placeholder="Should not cause expand/collapse">
</template>
<template ngbPanelContent>
Some Settings
</template>
</ngb-panel>
</ngb-accordion>
I realise that this would introduce another way to virtually do the same thing, but I can’t see another way to allow my particular use case, and keep the simplicity of the existing ngbPanelTitle
directive for the 95% of use cases.
I’d be happy to help with a contribution if this is something you’d consider supporting in ng-bootstrap.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:9
- Comments:18 (5 by maintainers)
Top GitHub Comments
Hi, I was looking for this feature too as I needed to show 3 icon buttons in the collapsed header (Edit/Clone/Delete). Came across this. I understand this is not yet available. However I was able to implement this as a hack with angular events. Posting it in case it helps anyone:
Step 1: Pass $event to handler
Step 2: Bypass default and use your code in handler
http://plnkr.co/edit/y9Iy7pk9Zj6hQ9rQmbWb?p=preview
This is kind of a hack but for now I could not find any other solution that works.
@pkozlowski-opensource ok I’ve just jotted this down, sorry if it’s incoherent!
1. ngbPanelHeader directive with manual click event handling
Pros:
ngbPanelTitle
Cons:
ngb-panel
, it needs to support bothngbPanelHeader
andngbPanelHeader
and validate that only one is present.2. Nested header/title directives (Taken from #465)
Pros:
Cons:
ngbPanelTitle
is used alone, but could be restrictive when using the more free-formngbPanelHeader
directive.3a. new ngbAction directive. 1 instance supported
ngbPanelHeader
is aware ofngbAction
and knows that it should perform toggling.ngbAction
adds click event binding to template element. Should this be within the template element??Cons:
Pros:
3b. ngbAction directive. Multiple instances supported with targeting
ngbPanelHeader
supports mutiple theoretical actions, and so targeting must be used like so. If no targeting is applied, the parent directive will either use a default action, or raise an error.Cons:
Pros:
3c. ngbAction directive. Multiple instances supported with targeting and custom event binding
Same 3b, but it with an additional directive for changing which event to bind to. If
ngbActionTrigger
is not supplied, default to onClick.Cons:
Pros:
Without a lot of control library experience, I couldn’t come up with a lot of pros & cons, let me know if you think of anything.
My personal preference would actually be 3c, which is the most complex in terms of library implementation, but IMO the most flexible for users, allowing for arbitrary actions to be define in a template, for any ngb component.