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

md-input with md-prefix and width:100% has weird rendering #1881

Closed
adarshaj opened this issue Nov 16, 2016 · 3 comments · Fixed by #2496
Closed

md-input with md-prefix and width:100% has weird rendering #1881

adarshaj opened this issue Nov 16, 2016 · 3 comments · Fixed by #2496
Assignees

Comments

@adarshaj
Copy link

Bug, feature request, or proposal:

Bug

What is the expected behavior?

The prefix on md-input should consume the space enough for the content within prefix.
I made a simple codepen of how it works in angularjs: https://codepen.io/anon/pen/VmKaNv (contrast with material2 impelmentation in plunkr below)

What is the current behavior?

there is a weird amount of space between the prefix and the placeholder text

What are the steps to reproduce?

Code to reproduce buggy behavior:

<md-input floatingPlaceholder="false" placeholder="Search" style="width:100%;">
   <span md-prefix><md-icon>search</md-icon>&nbsp;</span>
</md-input>

This Plunker has a simple search box with 100% width, see the preview in a large screen to be sure of behavior.
Plunker template: http://plnkr.co/edit/nCYNQGtfoZPQ04FUFy2L

What is the use-case or motivation for changing an existing behavior?

It looks ugly, also, it doesn't conform with other material design implementation (viz. in material design of angularjs)

Which versions of Angular, Material, OS, browsers are affected?

All.

Is there anything else we should know?

Nope.

@Drumarcco
Copy link

Apparently this happens because input is using table-cell as css display instead of flex, and table cell widths are distributed differently.

// We use a table layout to baseline align the prefix and suffix classes.
// The underline is outside of it so it can cover all of the elements under
// this table.
// Flex does not respect the baseline. What we really want is akin to a table
// as want an inline-block where elements don't wrap.
.md-input-table {
  display: inline-table;
  flex-flow: column;
  vertical-align: bottom;
  width: 100%;

  & > * {
    display: table-cell;
  }
}

I tried another approach using flex in the following way:

.md-input-table {
  display: flex;
  flex-flow: row;
  align-items: baseline;
  width: 100%;
}

.md-input-infix {
  position: relative;
  flex: 1;
}

And the result was better, but the vertical align feels a little odd:
image

I don't quite understand the baseline comment though, any references on why flex doesn't respect the baseline?

@yhaskell
Copy link

yhaskell commented Dec 11, 2016

Actually, it does respect baseline. Problem with md-icon is sorted by adding

.md-input-prefix md-icon, .md-input-suffix md-icon  { 
  vertical-align: text-bottom;
}

@mmalerba mmalerba self-assigned this Dec 14, 2016
@crisbeto crisbeto added the has pr label Jan 5, 2017
crisbeto added a commit to crisbeto/material2 that referenced this issue Jan 5, 2017
Prevents the input's suffix and prefix from stretching together with their parent node and leaving some weird spacing between themselves and the input. This was a side-effect of using `display: table-cell`.

Fixes angular#2493.
Fixes angular#1881.
Fixes angular#1421.
tinayuangao pushed a commit that referenced this issue Jan 12, 2017
…nt (#2496)

Prevents the input's suffix and prefix from stretching together with their parent node and leaving some weird spacing between themselves and the input. This was a side-effect of using `display: table-cell`.

Fixes #2493.
Fixes #1881.
Fixes #1421.
@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 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants