From b66532005faaa323f23ebf0974ae155b344476fe Mon Sep 17 00:00:00 2001 From: dabeng Date: Fri, 10 Feb 2017 11:24:26 +0800 Subject: [PATCH] List View: Inconsistent behavior for row expansion Note: row expansion is the default behavior after onClick performed, but user can stop such default behavior by adding the sentence "return false;" to the end of onClick function body --- src/views/listview/list-view-directive.js | 9 +++++++-- test/views/listview/list-view.spec.js | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/views/listview/list-view-directive.js b/src/views/listview/list-view-directive.js index 47f9c0781..0fd8479b4 100644 --- a/src/views/listview/list-view-directive.js +++ b/src/views/listview/list-view-directive.js @@ -27,7 +27,7 @@ *
  • .onCheckBoxChange - ( function(item) ) Called to notify when a checkbox selection changes, default is none *
  • .onSelect - ( function(item, event) ) Called to notify of item selection, default is none *
  • .onSelectionChange - ( function(items) ) Called to notify when item selections change, default is none - *
  • .onClick - ( function(item, event) ) Called to notify when an item is clicked, default is none + *
  • .onClick - ( function(item, event) ) Called to notify when an item is clicked, default is none. Note: row expansion is the default behavior after onClick performed, but user can stop such default behavior by adding the sentence "return false;" to the end of onClick function body *
  • .onDblClick - ( function(item, event) ) Called to notify when an item is double clicked, default is none * * @param {array} actionButtons List of action buttons in each row @@ -578,6 +578,7 @@ angular.module('patternfly.views').directive('pfListView', function ($timeout, $ var alreadySelected; var selectionChanged = false; var continueEvent = true; + var enableRowExpansion = scope.config && scope.config.useExpandingRows && item && !item.disableRowExpansion; // Ignore disabled item clicks completely if (scope.checkDisabled(item)) { @@ -620,7 +621,11 @@ angular.module('patternfly.views').directive('pfListView', function ($timeout, $ } } if (scope.config.onClick) { - scope.config.onClick(item, e); + if (scope.config.onClick(item, e) !== false && enableRowExpansion) { + scope.toggleItemExpansion(item); + } + } else if (enableRowExpansion) { + scope.toggleItemExpansion(item); } return continueEvent; diff --git a/test/views/listview/list-view.spec.js b/test/views/listview/list-view.spec.js index be9c653e2..a1763a4bf 100644 --- a/test/views/listview/list-view.spec.js +++ b/test/views/listview/list-view.spec.js @@ -514,7 +514,7 @@ describe('Directive: pfDataList', function () { expect(alteredKebab.length).toBe(1); }); - it('should allow expanding rows', function () { + it('should allow expanding rows by clicking the caret icon', function () { var items; $scope.listConfig.useExpandingRows = true; @@ -529,6 +529,19 @@ describe('Directive: pfDataList', function () { expect(openItem.length).toBe(1); }); + it('should allow expanding rows by clicking the main-info section', function () { + var items; + $scope.listConfig.useExpandingRows = true; + + $scope.$digest(); + + items = element.find('.list-view-pf-main-info'); + eventFire(items[0], 'click'); + + var openItem = element.find('.list-group-item-container'); + expect(openItem.length).toBe(1); + }); + it('should allow expanding rows to disable individual expansion', function () { $scope.systemModel[0].disableRowExpansion = true; $scope.listConfig.useExpandingRows = true;