Skip to content
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

fix(select): Arrow position/animation for appearance="standard" #12045

Merged
merged 2 commits into from
Aug 23, 2018

Conversation

seritools
Copy link
Contributor

@seritools seritools commented Jul 3, 2018

This commit aims to fix the arrow positioning of mat-selects
with appearance="standard". Since the label moves down whenever
the selected value is empty, the arrow looks out of place.
I added an animation that matches the speed of the label
animation:

  • Going from filled to empty transitions the arrow down so that it
    sits level with the label.
  • Going from empty to filled snaps the arrow back up, matching the
    label's behavior.

To test/compare the different appearances I added another card
to the demo-app with all of them.

Fixes #11925.

@seritools seritools requested a review from crisbeto as a code owner July 3, 2018 18:34
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 3, 2018
@seritools seritools changed the title fix(select): Arrow position/animation for appearance="standard" (#11925) fix(select): Arrow position/animation for appearance="standard" Jul 3, 2018
@@ -144,6 +144,59 @@
</mat-card-content>
</mat-card>

<mat-card class=".demo-appearance-comparison">
Copy link
Member

Choose a reason for hiding this comment

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

The dot in the class name looks like it shouldn't be there. Also it doesn't look like this class is being used anywhere.

/**
* This animation moves the panel toggle arrow up whenever the select is not empty to match the
* visual middle. This affects only mat-selects with appearance='standard'.
*/
Copy link
Member

Choose a reason for hiding this comment

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

Defining an animation just to move the arrow around is overkill and it makes it very hard for people to override the styles. Since the empty state is on the mat-select already, you can use it to toggle a class either on the select or the arrow itself which tells it where it's supposed to be positioned.

Copy link
Contributor

Choose a reason for hiding this comment

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

Using a normal CSS transition will make it easy to target the specific appearance as well, since the form field already has a class indicating the variant.

You can hook into the Angular Animations to disable this transition when Angular Animations are disabled. As an example see here: https://github.com/angular/material2/blob/master/src/lib/form-field/form-field.scss#L220

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, using just simple CSS seems way better and easier to handle - I'm gonna update the PR on the weekend!

@mmalerba mmalerba self-assigned this Jul 6, 2018
@@ -144,6 +144,59 @@
</mat-card-content>
</mat-card>

<mat-card class=".demo-appearance-comparison">
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a button to this demo that allows me to toggle all of the selects to either have a value or be cleared? It's tough to see the animation when manually selecting the value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will do!

/**
* This animation moves the panel toggle arrow up whenever the select is not empty to match the
* visual middle. This affects only mat-selects with appearance='standard'.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Using a normal CSS transition will make it easy to target the specific appearance as well, since the form field already has a class indicating the variant.

You can hook into the Angular Animations to disable this transition when Angular Animations are disabled. As an example see here: https://github.com/angular/material2/blob/master/src/lib/form-field/form-field.scss#L220

@seritools
Copy link
Contributor Author

Alright! Switched over to a simple css animation and added a toggle button to the select-demo to quickly see the effect.

Copy link
Contributor

@mmalerba mmalerba 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 this feature looks good and is limited-scope enough to not interfere with adherence to the spec in other situations. Thanks for working on it!

@@ -202,6 +202,7 @@ export class MatSelectTrigger {}
'[class.mat-select-disabled]': 'disabled',
'[class.mat-select-invalid]': 'errorState',
'[class.mat-select-required]': 'required',
'[class.mat-select-empty]': 'empty',
Copy link
Contributor

Choose a reason for hiding this comment

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

iirc, form-field has an empty class that you can probably use instead of adding a new one here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, just checked this out, but the .mat-form-field-empty is only set on the floating label, not the mat-form-field itself. What would be the best change @mmalerba?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh ok, in that case we can just leave it as is

@mmalerba mmalerba added pr: lgtm action: merge The PR is ready for merge by the caretaker target: minor This PR is targeted for the next minor release labels Jul 16, 2018
@ngbot
Copy link

ngbot bot commented Jul 16, 2018

I see that you just added the pr: merge ready label, but the following checks are still failing:
    failure status "ci/circleci: build" is failing

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken master, please try rebasing to master and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

…lar#11925)

This commit aims to fix the arrow positioning of mat-selects
with appearance="standard". Since the label moves down whenever
the selected value is empty, the arrow looks out of place.
I added an animation that matches the speed of the label
animation:
Going from filled to empty transitions the arrow down so that it
sits level with the label.
Going from empty to filled snaps the arrow back up, matching the
label's behavior.
To test/compare the different appearances I added another card
to the demo-app with all of them.
@seritools seritools force-pushed the select-standard-arrow-fix branch from 6362302 to 4df3243 Compare July 21, 2018 10:51
@seritools
Copy link
Contributor Author

Heh, rebased onto current master again to trigger a new CI run, now circleci passes but travis failed. Could you look into it once again @mmalerba?

@mmalerba
Copy link
Contributor

failure looks like a flake, I restarted it

@jelbourn jelbourn merged commit 58f3c54 into angular:master Aug 23, 2018
@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 9, 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 target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mat-Select with appearance="standard": Arrow too high
5 participants