Skip to content

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

Merged
merged 1 commit into from
Jan 31, 2018

Conversation

andrewseguin
Copy link
Contributor

@andrewseguin andrewseguin commented Oct 6, 2017

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

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Oct 6, 2017
Copy link
Member

@crisbeto crisbeto left a 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.

@jelbourn
Copy link
Member

jelbourn commented Oct 8, 2017

I don't quite follow why showing the indicator means the animation can't exist

@andrewseguin
Copy link
Contributor Author

This is only in reference to the animation we added for entering and exiting the sort (not transitioning between asc and desc).

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)

@andrewseguin andrewseguin added the P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent label Oct 20, 2017
@jelbourn
Copy link
Member

I think I need to see it in action to understand

@andrewseguin
Copy link
Contributor Author

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

@jelbourn
Copy link
Member

@andrewseguin can you give a brief summary of why the animation is hard to keep?

@andrewseguin
Copy link
Contributor Author

Had trouble with the animation out - the indicator wants to animate to the next state since its not active anymore but we want to preserve what state it was in as it animates out. Then, if you sort it while its animating out, you want it to float in from the bottom with that same position. I tried getting it to remember its old state after sort is removed, but it just got too tricky to add in this PR. I suspect it's totally doable but making it a clean implementation will take some thought

@jelbourn
Copy link
Member

jelbourn commented Nov 3, 2017

@crisbeto thoughts? I don't want to remove the animation "temporarily" and then never get around to bringing it back

@crisbeto
Copy link
Member

crisbeto commented Nov 3, 2017

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?

@andrewseguin
Copy link
Contributor Author

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)

@andrewseguin andrewseguin force-pushed the sort-display-on-hover branch 2 times, most recently from 48f4152 to 7473ce9 Compare November 20, 2017 22:46
@andrewseguin
Copy link
Contributor Author

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)

@andrewseguin andrewseguin added P2 The issue is important to a large percentage of users, with a workaround and removed P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Nov 28, 2017
@andrewseguin andrewseguin added this to the 5.0 milestone Nov 28, 2017
// Arrow opacity
trigger('arrowOpacity', [
state('desc-to-active, asc-to-active, active',
style({opacity: 1})),
Copy link
Member

Choose a reason for hiding this comment

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

Why the line break?

Copy link
Contributor Author

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

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.
Copy link
Member

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?

* provide an affordance that the header is sortable by showing on focus and hover.
* @docs-private
*/
set showIndicatorHint(showIndicatorHint: boolean) {
Copy link
Member

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?

* so that there is no animation displayed.
* @docs-private
*/
set viewState(arrowPosition: ArrowViewStateTransition) {
Copy link
Member

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?

* facing the start direction. Otherwise if it is sorted, the arrow should point in the currently
* active sorted direction.
*/
_updateArrowDirection() {
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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?

@@ -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 }>;
Copy link
Member

Choose a reason for hiding this comment

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

Omit spaces in braces

dispatchMouseEvent(sortElement, event);
}

expectViewAndDirectionStates(
Copy link
Member

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

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Nov 29, 2017
@tinayuangao
Copy link
Contributor

@andrewseguin This has error _disableStateAnimation not exist.

@andrewseguin andrewseguin force-pushed the sort-display-on-hover branch from 624d1c7 to ed1b956 Compare December 1, 2017 21:58
@andrewseguin
Copy link
Contributor Author

Rebased -- should be alright now

@andrewseguin andrewseguin added target: minor This PR is targeted for the next minor release presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged labels Dec 11, 2017
@andrewseguin andrewseguin force-pushed the sort-display-on-hover branch from ed1b956 to a358972 Compare January 18, 2018 23:01
@andrewseguin
Copy link
Contributor Author

Woohoo, got it working!

@jelbourn
Copy link
Member

@andrewseguin get a presubmit going?

@tinayuangao tinayuangao merged commit cde00df into angular:master Jan 31, 2018
@andrewseguin andrewseguin deleted the sort-display-on-hover branch April 17, 2018 17:24
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P2 The issue is important to a large percentage of users, with a workaround presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Sort] Sort icon should appear on hover
5 participants