-
Notifications
You must be signed in to change notification settings - Fork 6.7k
add a select attribute on tabs pane to trigger a callback #141
Conversation
@revolunet thnx for the PR, it looks good. Before merging it I would like to ask if you saw that tabs got the |
@pkozlowski-opensource i dont have any idea how i could watch easily the pane.active property for each pane of the tabs as the active attribute is related to pane and not tabs. i would set multiple watchers ? in my case, i'm in a ng-repeat : <pane ng-repeat="tab in tabs" heading="{{ tab.title }}" active="tab.active" select="changeThumbnail(tab.thumbnail)">...</pane> Also, can you please explain why heading attribute have double curly braces syntax and not active attribute ? looks like inconsistency to me, isnt it ? thanks :) |
@revolunet yeh, you are right, I was playing with the $watch solution and although I've managed to make it work it is ugly... Will squash commits and merge it unless others got different idea... |
thanks :) fix me please : why that different syntax between heading and active attributes ? |
Regarding different syntax: The syntax without curly is used where there is only one value to evaluate. This is typically used for non-string values (boolean, event handlers etc.). So this "inconsistency" exists in AngularJS already and is about offering the most user-friendly syntax. |
ok thanks for clarification :) |
I have an alternative proposal:
I believe this is more flexible. @revolunet's solution works fine for ng-repeat but must be repeated manually for static panes. Also his approach does not support $watch and binding. His example would reduce to active-id="something" and then setting $watch on something. When using default index-based ids, he can lookup active pane directly with the index. In more complex scenarios it is up to the user to handle mapping between ids and panes. Alternatively more complex data structure could be stored in pane-id. If you agree I could try to implement it. I need it for my code anyway. Right now I have to do this in my controllers:
|
@darwin I agree that it is a bit more flexible but AngularJS gives as so much more ability to work with objects as compared to relaying on ids that I almost never use them in AngularJS web apps. Couldn't we do something like this in a pane:
How does it sound? |
Looks good. But I still think that you want to do this handling on tabs directive. It seems more logical to me. And the main argument it that you don't want to repeat on-select for each pane. In most cases it would contain the same expression. |
Maybe my "id" naming is confusing. Maybe you can look at it as "payload". Whatever you put there, you get back. |
@pkozlowski-opensource Please look at implementation of tabbable directive in angular.js repo: They expose my "id" on tabbable directive via ngModel and call it "value", here is the code how they get it: Actually I've switched from their implementation to yours. I'm happy, yours is much more cleaner. But I'm really missing a single place where I can hook to observe tab changes. I don't want to attach handler to each pane individually. I think it should be on |
@darwin : i understand your two-way data binding for the I thinks the pane |
👍 This would be a very desirable feature. |
* Tabs transclude to title elements instead of content elements, so the ordering is always correct (#153) * Rename `<tabs>` to `<tabset>`, `<pane>` to `<tab>` (#186) * Add `<tab-heading>` directive, which is a child of a `<tab>`. Allows HTML in tab headings (#124) * Add `select` attribute callback when tab is selected (#141) * Only the active tab's content is actually ever in the DOM
* Tabs transclude to title elements instead of content elements, so the ordering is always correct (#153) * Rename `<tabs>` to `<tabset>`, `<pane>` to `<tab>` (#186) * Add `<tab-heading>` directive, which is a child of a `<tab>`. Allows HTML in tab headings (#124) * Add `select` attribute callback when tab is selected (#141) * Only the active tab's content is actually ever in the DOM
@revolunet We've got a PR now from @ajoslin that addresses many issues with tabs, this one being one of them. As such I'm going to close this PR and focus on Andy's one (#287). Would be totally awesome if you could have a look at the code from #287 to see if it works for you. |
Hi! awesome work, and yes it fits perfectly with my needs :) Thanks guys ! |
* Tabs transclude to title elements instead of content elements, so the ordering is always correct (Closes #153) * Rename `<tabs>` to `<tabset>`, `<pane>` to `<tab>` (Closes #186) * Add `<tab-heading>` directive, which is a child of a `<tab>`. Allows HTML in tab headings (Closes #124) * Add `select` attribute callback when tab is selected (Closes #141) * Only the active tab's content is now actually ever in the DOM
* Rename 'tabs' directive to 'tabset', and 'pane' directive to 'tab'. The new syntax is more intuitive; The word pane does not obviously represent a subset of a tab group. (Closes #186) * Add 'tab-heading' directive, which is a child of a 'tab'. Allows HTML in tab headings. (Closes #124) * Add option for a 'select' attribute callback when a tab is selected. (Closes #141) * Tabs transclude to title elements instead of content elements. Now the ordering of tab titles is always correct. (Closes #153) * Only the active tab's content is ever present in the DOM. This is another plus of transcluding tabs to title elmements, and provies a performance increase. BREAKING CHANGE: The 'tabs' directive has been renamed to 'tabset', and the 'pane' directive has been renamed to 'tab'. To migrate your code, follow the example below. Before: <tabs> <pane heading="one"> First Content </pane> <pane ng-repeat="apple in basket" heading="{{apple.heading}}"> {{apple.content}} </pane> </tabs> After: <tabset> <tab heading="one"> First Content </tab> <tab ng-repeat="apple in basket" heading="{{apple.heading}}"> {{apple.content}} </tab> </tabset>
* Rename 'tabs' directive to 'tabset', and 'pane' directive to 'tab'. The new syntax is more intuitive; The word pane does not obviously represent a subset of a tab group. (Closes #186) * Add 'tab-heading' directive, which is a child of a 'tab'. Allows HTML in tab headings. (Closes #124) * Add option for a 'select' attribute callback when a tab is selected. (Closes #141) * Tabs transclude to title elements instead of content elements. Now the ordering of tab titles is always correct. (Closes #153) * Only the active tab's content is ever present in the DOM. Provides an increase in performance. BREAKING CHANGE: The 'tabs' directive has been renamed to 'tabset', and the 'pane' directive has been renamed to 'tab'. To migrate your code, follow the example below. Before: <tabs> <pane heading="one"> First Content </pane> <pane ng-repeat="apple in basket" heading="{{apple.heading}}"> {{apple.content}} </pane> </tabs> After: <tabset> <tab heading="one"> First Content </tab> <tab ng-repeat="apple in basket" heading="{{apple.heading}}"> {{apple.content}} </tab> </tabset>
* Rename 'tabs' directive to 'tabset', and 'pane' directive to 'tab'. The new syntax is more intuitive; The word pane does not obviously represent a subset of a tab group. (Closes #186) * Add 'tab-heading' directive, which is a child of a 'tab'. Allows HTML in tab headings. (Closes #124) * Add option for a 'select' attribute callback when a tab is selected. (Closes #141) * Tabs transclude to title elements instead of content elements. Now the ordering of tab titles is always correct. (Closes #153) BREAKING CHANGE: The 'tabs' directive has been renamed to 'tabset', and the 'pane' directive has been renamed to 'tab'. To migrate your code, follow the example below. Before: <tabs> <pane heading="one"> First Content </pane> <pane ng-repeat="apple in basket" heading="{{apple.heading}}"> {{apple.content}} </pane> </tabs> After: <tabset> <tab heading="one"> First Content </tab> <tab ng-repeat="apple in basket" heading="{{apple.heading}}"> {{apple.content}} </tab> </tabset>
* Rename 'tabs' directive to 'tabset', and 'pane' directive to 'tab'. The new syntax is more intuitive; The word pane does not obviously represent a subset of a tab group. (Closes #186) * Add 'tab-heading' directive, which is a child of a 'tab'. Allows HTML in tab headings. (Closes #124) * Add option for a 'select' attribute callback when a tab is selected. (Closes #141) * Tabs transclude to title elements instead of content elements. Now the ordering of tab titles is always correct. (Closes #153) BREAKING CHANGE: The 'tabs' directive has been renamed to 'tabset', and the 'pane' directive has been renamed to 'tab'. To migrate your code, follow the example below. Before: <tabs> <pane heading="one"> First Content </pane> <pane ng-repeat="apple in basket" heading="{{apple.heading}}"> {{apple.content}} </pane> </tabs> After: <tabset> <tab heading="one"> First Content </tab> <tab ng-repeat="apple in basket" heading="{{apple.heading}}"> {{apple.content}} </tab> </tabset>
* Rename 'tabs' directive to 'tabset', and 'pane' directive to 'tab'. The new syntax is more intuitive; The word pane does not obviously represent a subset of a tab group. (Closes #186) * Add 'tab-heading' directive, which is a child of a 'tab'. Allows HTML in tab headings. (Closes #124) * Add option for a 'select' attribute callback when a tab is selected. (Closes #141) * Tabs transclude to title elements instead of content elements. Now the ordering of tab titles is always correct. (Closes #153) BREAKING CHANGE: The 'tabs' directive has been renamed to 'tabset', and the 'pane' directive has been renamed to 'tab'. To migrate your code, follow the example below. Before: <tabs> <pane heading="one"> First Content </pane> <pane ng-repeat="apple in basket" heading="{{apple.heading}}"> {{apple.content}} </pane> </tabs> After: <tabset> <tab heading="one"> First Content </tab> <tab ng-repeat="apple in basket" heading="{{apple.heading}}"> {{apple.content}} </tab> </tabset>
It seems like the select callback of all tabs will be triggered when the route changes. So everytime I leave the view that includes the tabs a select event from every single tab is fired. Is this a bug? |
Hi :)
I needed to have a callback on tab selection so i added a
select
attribute on the tabs pane directive.eg:
<pane select="updateImage(tab.thumbnail)">
Comments appreciated.
Thanks !
Julien