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): set select value to trigger height and center text #3021

Merged
merged 4 commits into from
Feb 10, 2017

Conversation

andrewseguin
Copy link
Contributor

Issue was that the text div was actually being calculated as 29px, not 30px, because the trigger had a border bottom of 1px. This made the following code incorrect since the option value height was actually 29px:

/**
 * Must adjust for the difference in height between the option and the trigger,
 * so the text will align on the y axis.
 * (SELECT_OPTION_HEIGHT (48) - SELECT_TRIGGER_HEIGHT (30)) / 2 = 9
 */
export const SELECT_OPTION_HEIGHT_ADJUSTMENT = 9;

This change forces the option value to be 30px and centers the text using flex. Tested on Linux Chrome, Linux FF, Windows IE11 & Edge, Mac Chrome, and Mac FF.

Closes #2977

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

crisbeto commented Feb 9, 2017

Great catch @andrewseguin! I was struggling with reproducing this one.

top: 6px;
height: $mat-select-trigger-height;

display: flex;
Copy link
Member

@crisbeto crisbeto Feb 9, 2017

Choose a reason for hiding this comment

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

Can you check if long values get ellipsis with this? I had a fix a while ago that removed it, because it didn't seem to work with flexbox.

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 checked, there's an issue with ellipsis. I believe this can be solved by giving the text itself a span of its own that will have the overflow hidden property. I'll add that to the PR shortly

@kara kara added the in progress This issue is currently in progress label Feb 9, 2017
@andrewseguin
Copy link
Contributor Author

So I added a bit more changes to make it a little more explicit and future-proof. Children of an element with a border end up with different sizes for height: 100% depending on the browser. In our case, value was getting something like 30px on Chrome and Safari and 29px on FF.

I took border-bottom out and just made a new span to handle the look of a border. That way the option element is for sure 30px on all browsers.

I added an inner span to take care of our truncation as well, thanks for the heads up on that.

@crisbeto
Copy link
Member

crisbeto commented Feb 9, 2017

Instead of creating something completely new, couldn't the .mat-select-border share the styles from the .mat-input-underline from input container? Alternatively, it could be pseudo element so we don't have an extra span in the DOM.

@kara kara added pr: needs review and removed in progress This issue is currently in progress labels Feb 9, 2017
Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

Nits

position: absolute;
bottom: 0;
left: 0;
right: 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a mixin for these 4 lines in core called mat-fill. Use that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Almost, I want to have it sink to the bottom of the container so it's missing the top: 0

Copy link
Contributor

Choose a reason for hiding this comment

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

Ha, I can't read. Ignore me!


[aria-disabled='true'] & {
@include mat-control-disabled-underline();
border-bottom: transparent;
background-position: 0 bottom;
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you moved this line. Still necessary to keep up 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.

Missed that one, will remove

@andrewseguin
Copy link
Contributor Author

I tried getting a mixin to work with both select and input underlines but since they have different structures its hard to get a good common ground. Select needs to position bottom but this messes up on input. If we can find a way to structure them similarly then I think its worth finding a commons style, but perhaps in another PR.

As for using ::after, I felt that it was a little more complex for users to figure out what they need to override to change the stylings (e.g. underline size, color). By having a separate span, it makes it very easy for them to understand.

Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

LGTM

@andrewseguin andrewseguin added the action: merge The PR is ready for merge by the caretaker label Feb 10, 2017
@kara kara removed the action: merge The PR is ready for merge by the caretaker label Feb 10, 2017
@kara kara added action: merge The PR is ready for merge by the caretaker and removed pr: needs rebase labels Feb 10, 2017
@tinayuangao tinayuangao merged commit ac9c090 into angular:master Feb 10, 2017
@andrewseguin andrewseguin deleted the retina-issue branch February 23, 2017 20:58
@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 6, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Select offset 1px off in Chrome
5 participants