Skip to content

Commit bc7ee1f

Browse files
committed
better handle tab selection
Especially when data regarding the current tab may not be available at link time
1 parent 510a907 commit bc7ee1f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

fancy-tab.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
restrict: 'E',
1818
transclude: true,
1919
scope: {
20-
current: '=?'
20+
current: '=?',
21+
autoSelect: '=?'
2122
},
2223
controller: ['$scope', '$element', function($scope, $element) {
2324
var panes = $scope.panes = [],
2425
selected;
2526

27+
$scope.autoSelect = $scope.autoSelect === undefined ? true : $scope.autoSelect;
28+
2629
$scope.select = function(pane) {
2730
selected = pane;
2831
angular.forEach(panes, function(pane) {
@@ -33,15 +36,16 @@
3336
}
3437

3538
this.addPane = function(pane) {
36-
if (panes.length == 0)
39+
if (panes.length == 0 && $scope.autoSelect ||
40+
(pane.name || pane.title) === $scope.current)
3741
$scope.select(pane);
3842

3943
panes.push(pane);
4044
}
4145

4246
// Allow for programmatic tab selection
4347
$scope.$watch('current', function (val) {
44-
if (val !== (selected.name || selected.title)) {
48+
if (val && (selected === undefined || val !== (selected.name || selected.title))) {
4549
angular.forEach(panes, function(pane) {
4650
if (val === (selected.name || selected.title)) {
4751
pane.selected = true;

0 commit comments

Comments
 (0)