Skip to content

Commit cd75239

Browse files
authored
Merge pull request #400 from dabeng/caret-icon
List View: Expand rows when clicking anywhere in the row.
2 parents aeecfe2 + b665320 commit cd75239

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/views/listview/list-view-directive.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* <li>.onCheckBoxChange - ( function(item) ) Called to notify when a checkbox selection changes, default is none
2828
* <li>.onSelect - ( function(item, event) ) Called to notify of item selection, default is none
2929
* <li>.onSelectionChange - ( function(items) ) Called to notify when item selections change, default is none
30-
* <li>.onClick - ( function(item, event) ) Called to notify when an item is clicked, default is none
30+
* <li>.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
3131
* <li>.onDblClick - ( function(item, event) ) Called to notify when an item is double clicked, default is none
3232
* </ul>
3333
* @param {array} actionButtons List of action buttons in each row
@@ -578,6 +578,7 @@ angular.module('patternfly.views').directive('pfListView', function ($window, pf
578578
var alreadySelected;
579579
var selectionChanged = false;
580580
var continueEvent = true;
581+
var enableRowExpansion = scope.config && scope.config.useExpandingRows && item && !item.disableRowExpansion;
581582

582583
// Ignore disabled item clicks completely
583584
if (scope.checkDisabled(item)) {
@@ -620,7 +621,11 @@ angular.module('patternfly.views').directive('pfListView', function ($window, pf
620621
}
621622
}
622623
if (scope.config.onClick) {
623-
scope.config.onClick(item, e);
624+
if (scope.config.onClick(item, e) !== false && enableRowExpansion) {
625+
scope.toggleItemExpansion(item);
626+
}
627+
} else if (enableRowExpansion) {
628+
scope.toggleItemExpansion(item);
624629
}
625630

626631
return continueEvent;

test/views/listview/list-view.spec.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ describe('Directive: pfDataList', function () {
514514
expect(alteredKebab.length).toBe(1);
515515
});
516516

517-
it('should allow expanding rows', function () {
517+
it('should allow expanding rows by clicking the caret icon', function () {
518518
var items;
519519
$scope.listConfig.useExpandingRows = true;
520520

@@ -529,6 +529,19 @@ describe('Directive: pfDataList', function () {
529529
expect(openItem.length).toBe(1);
530530
});
531531

532+
it('should allow expanding rows by clicking the main-info section', function () {
533+
var items;
534+
$scope.listConfig.useExpandingRows = true;
535+
536+
$scope.$digest();
537+
538+
items = element.find('.list-view-pf-main-info');
539+
eventFire(items[0], 'click');
540+
541+
var openItem = element.find('.list-group-item-container');
542+
expect(openItem.length).toBe(1);
543+
});
544+
532545
it('should allow expanding rows to disable individual expansion', function () {
533546
$scope.systemModel[0].disableRowExpansion = true;
534547
$scope.listConfig.useExpandingRows = true;

0 commit comments

Comments
 (0)