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

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

merged 1 commit into from
Mar 2, 2017

Conversation

dabeng
Copy link
Contributor

@dabeng dabeng commented Feb 9, 2017

For list views using row expansion, the row will now expand when the user clicks anywhere on the row. Previously the user had to click on the expansion indicator icon. If desired, the application code can prevent the expansion on click of the row by returning false from the config.onClick function.

@jeff-phillips-18
Copy link
Member

I have found that leaving the expanding alone for the expansion indicator and using the existing itemClick method to toggle expansion does not require the prevention of the event propagation.

This also would allow for some logic around handling row expansion and row selection options. I'm not sure what the right way to handle it is, but when using row selection and row expansion what should happen when the row is clicked? Double clicked?

I'm OK with your solution if we want to expand always regardless of the selection options, however you would also need to stop event propagation when the kebab menu items are clicked (in the handleMenuAction function).

@dabeng
Copy link
Contributor Author

dabeng commented Feb 10, 2017

Hi @jeff-phillips-18 , you are right. Placing event.stopPropagation() on everywhere is not a best preactice.

@dabeng
Copy link
Contributor Author

dabeng commented Feb 13, 2017

@jeff-phillips-18@bleathem , could you give me new suggestions ?

@bleathem
Copy link
Member

This change looks good to me. WDYT @jeff-phillips-18?

@jeff-phillips-18
Copy link
Member

My only concern is any applications currently handling the click would get both the expansion and the click handling for the row. I suppose there should be no reason to have both. I'm OK with this change but let's be sure to release note it so any applications currently handling the click are aware.

Copy link
Member

@jeff-phillips-18 jeff-phillips-18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@bleathem
Copy link
Member

Thanks @jeff-phillips-18. I'd like to work out what the release notes should say before we merge this PR. If I understand correctly, your concern is that if useExpandingRows is enabled, and the application has implemented it's own click listener, than the applications click listener would not be able to prevent the row expansion?

@jeff-phillips-18
Copy link
Member

Correct. Some applications may have already added a click listener to toggle expansion. Adding this would then toggle twice resulting in nothing more than a flicker.

I'm not sure there is much reason to have a click listener on the row when using expanding rows if we are expanding the rows on a click. This solution would certainly suggest that an application handling the click be unnecessary and discouraged when using expanding rows.

So the question becomes, do we continue to call the onClick listener when using expanding rows?

@bleathem
Copy link
Member

I think continuing to invoke the onclick listener makes sense, as we can't anticipate all the use cases an application might have for listening to that click event.

In fact, perhaps we should invoke the onclick listener first, prior to expanding the rows, to give the application a chance to prevent the automatic row expansion. WDYT @jeff-phillips-18?

@jeff-phillips-18
Copy link
Member

Interesting, we could do that. We would have to document that the onClick function would need to return false prevent further handling of the event (expansion).

@bleathem
Copy link
Member

bleathem commented Feb 22, 2017

+1, I think it's worth pursuing. Would we set the continueEvent variable to the return value of the click listener?

Copy link
Member

@bleathem bleathem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dabeng can you update this PR to invoke the toggleItemExpansion after the click listener is invoked as per the discussion in this thread?

@dabeng
Copy link
Contributor Author

dabeng commented Feb 23, 2017

Hi @jeff-phillips-18 @bleathem , I got your points, but I have a question -- If a user enable "useExpandingRows" why does he still want to write expand/collapse effect on clicking list item by himself.

@dabeng
Copy link
Contributor Author

dabeng commented Feb 23, 2017

Maybe he is just thinking the expand/collapse effect of angular-patternfly is not cool enough. Then he just need to disable "useExpandingRows" and add his own logic for expand/collapse effect into the custom onClick() function.

@dabeng
Copy link
Contributor Author

dabeng commented Feb 23, 2017

Additionally, I think it's not friendly to enforce user to append any statements(including simple return Boolean;) to his own code snippets.

@jeff-phillips-18
Copy link
Member

The issue is, this was not there before. So, applications may be doing something different on a row click (navigate, drill down, or expand themselves). Adding this will cause unexpected results for those applications (a quick expansion of the row prior to navigation or a double toggle of expansion).

We can leave this as is and release note it but if we don't allow the application to prevent the expansion, then the application's behavior may change. Adding a return is optional, only if the application returned false would the expansion not occur.

@dabeng
Copy link
Contributor Author

dabeng commented Feb 24, 2017

Great. @jeff-phillips-18 , @bleathem , How could we handle the expansion if user has inserted async operation into onClick function ?

@bleathem
Copy link
Member

If we want to handle the async case, we can check if the user returns a promise. Then promise would then resolve to true/false which would enable/disable expansion.

I think that would be overkill at this point, let's leave it as a sync operation, and implement the async use case if users request it.

Agree with @jeff-phillips-18. Returning false is optional. It allows the user to take over expanding rows if they choose, but the default behaviour works as expected.

As for a use case where a user wants expanding rows, but wants to handle it themselves is if they want to conditionally allow for expansion. eg. maybe you can only expand an item if you have first checked an "agree to terms" check box (as an arbitrary example), or one could consider role-based conditionals.

@bleathem
Copy link
Member

Thanks for updating the PR @dabeng. However can we please break apart that compound conditional to improve the readability of the code? I recommend storing the return value of the onClick listener in a variable and using that in the subsequent conditional.

enableRowExpansion = scope.config && scope.config.useExpandingRows && item && !item.disableRowExpansion;
if (typeof clickReturnValue === 'undefined' && enableRowExpansion) {
scope.toggleItemExpansion(item);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no onClick function in the config, then expansion should happen.

ie:

if (!angular.isFunction(scope.config.onClick) || scope.config.onClick(item, e) !== false) {
...
}

@bleathem
Copy link
Member

bleathem commented Feb 28, 2017

Thanks @dabeng. @jeff-phillips-18 are you happy to see this one merged?

@jeff-phillips-18
Copy link
Member

there should be an update to the ngDocs for this, documenting the change to the onClick function's return value use.

Also, please add this documentation to this PR's description and to the commit so that it can be easily added to the release notes.

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
@dabeng
Copy link
Contributor Author

dabeng commented Mar 1, 2017

Hi @jeff-phillips-18 , I have aded additional explanations both on ngDocs and PR description

@jeff-phillips-18 jeff-phillips-18 changed the title List View: Inconsistent behavior for row expansion List View: Expand rows when clicking anywhere in the row. Mar 1, 2017
@bleathem bleathem merged commit cd75239 into patternfly:master Mar 2, 2017
@abkieling
Copy link
Contributor

Please make sure the fix is merged into angular-patternfly v4 as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants