-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(sort): show sort indicator on hover/focus/longpress #7608
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
feat(sort): show sort indicator on hover/focus/longpress #7608
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we can still keep the animation if we toggle the indicator visibility either through visibility
or display
.
I don't quite follow why showing the indicator means the animation can't exist |
This is only in reference to the animation we added for entering and exiting the sort (not transitioning between Since the arrow shows on hover/focus, I don't think it's correct to show the arrow "fly in" since it is already in place when activated. Maybe we can have the arrow still "fly out" since the hint doesn't appear after the sort is disabled, but it wouldn't be a symmetrical animation (why does it fly out but never flies in) |
I think I need to see it in action to understand |
Tried again for a few hours trying to get the animation working, its...more complex than it seems. Let's bring it back in another PR |
@andrewseguin can you give a brief summary of why the animation is hard to keep? |
Had trouble with the animation out - the indicator wants to animate to the next state since its not |
@crisbeto thoughts? I don't want to remove the animation "temporarily" and then never get around to bringing it back |
I'm still having a hard time understanding the issue. Is it that we want to avoid the "fly in" animation when the user hovers the header? |
Discussed in person - issue is in its complexity and not clear what is the best animation for some cases. Complexity: Need to watch several states - if active, arrow should be pointing in its current direction; if not active, arrow should be pointing in the start position except if the sort has just been disable (should fly out so the sort direction should persist) |
48f4152
to
7473ce9
Compare
7473ce9
to
4d9caff
Compare
Ready again for review - after a looong time playing with the animations, found a way to bring back the animation. Essentially the sort will define the right transition it should show (e.g. go from above to the middle, asc-to-active) |
src/lib/sort/sort-header.ts
Outdated
// Arrow opacity | ||
trigger('arrowOpacity', [ | ||
state('desc-to-active, asc-to-active, active', | ||
style({opacity: 1})), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the line break?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just consistency with the third state ('hint-to-desc, active-to-desc, desc, hint-to-asc, active-to-asc, asc'
) which causes wraparound. No strong opinion either way - I unwrapped it
src/lib/sort/sort-header.ts
Outdated
import {MatSortHeaderIntl} from './sort-header-intl'; | ||
import {getSortHeaderNotContainedWithinSortError} from './sort-errors'; | ||
import {AnimationCurves, AnimationDurations} from '@angular/material/core'; | ||
|
||
const SORT_ANIMATION_TRANSITION = | ||
AnimationDurations.ENTERING + ' ' + AnimationCurves.STANDARD_CURVE; | ||
|
||
/** | ||
* Valid positions for the arrow to be in for its opacity and translation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expand comment to explain what 'peek'
and 'active'
mean?
src/lib/sort/sort-header.ts
Outdated
* provide an affordance that the header is sortable by showing on focus and hover. | ||
* @docs-private | ||
*/ | ||
set showIndicatorHint(showIndicatorHint: boolean) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of making this a setter, can you make it a function like _setIndicatorHintVisible
?
src/lib/sort/sort-header.ts
Outdated
* so that there is no animation displayed. | ||
* @docs-private | ||
*/ | ||
set viewState(arrowPosition: ArrowViewStateTransition) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also make this a function? Something like _setAnimationTransitionState
?
src/lib/sort/sort-header.ts
Outdated
* facing the start direction. Otherwise if it is sorted, the arrow should point in the currently | ||
* active sorted direction. | ||
*/ | ||
_updateArrowDirection() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have an update function instead of a function like _getArrowDirection
? The problem with the update function is that you can forget to call it, or call it when it's not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried going that route but this ended up being much easier to control when the arrow changes directions.
Best example is when the sort goes from active to deactivated. By default the order for sort will be none - asc - desc
. When the sort goes from desc
to none
, the arrow direction should remain the same until the animation completes (as it flies away). Only when the arrow is displayed again should it switch to showing itself as asc
(hint is shown or activated). With just a "getter", we would probably have to rely on knowing if the arrow is animating away and have some additional logic about making it keep the "old direction" in the meantime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expand comment to explain this, then?
src/lib/sort/sort.spec.ts
Outdated
@@ -88,6 +93,95 @@ describe('MatSort', () => { | |||
expect(sortables.has('column_c')).toBe(true); | |||
}); | |||
|
|||
describe('checking correct arrow direction and view state for its various states', () => { | |||
let expectedStates: Map<string, { viewState: string, arrowDirection: string }>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omit spaces in braces
src/lib/sort/sort.spec.ts
Outdated
dispatchMouseEvent(sortElement, event); | ||
} | ||
|
||
expectViewAndDirectionStates( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add JsDoc description? It's not super obvious what this method does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@andrewseguin This has error |
624d1c7
to
ed1b956
Compare
Rebased -- should be alright now |
ed1b956
to
a358972
Compare
Woohoo, got it working! |
@andrewseguin get a presubmit going? |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Brings the sort header closer to spec but unfortunately takes away the cool animation that was added in #7180. Not sure how to reconcile the animation with this indicator hint. Perhaps only do the fade-away animation when sort is removed but not added?
Closes #6858, #8612