Skip to content

List View: Expand rows when clicking anywhere in the row. #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/views/listview/list-view-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* <li>.onCheckBoxChange - ( function(item) ) Called to notify when a checkbox selection changes, default is none
* <li>.onSelect - ( function(item, event) ) Called to notify of item selection, default is none
* <li>.onSelectionChange - ( function(items) ) Called to notify when item selections change, default is none
* <li>.onClick - ( function(item, event) ) Called to notify when an item is clicked, default is none
* <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
* <li>.onDblClick - ( function(item, event) ) Called to notify when an item is double clicked, default is none
* </ul>
* @param {array} actionButtons List of action buttons in each row
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 14 additions & 1 deletion test/views/listview/list-view.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down