material icon indicating copy to clipboard operation
material copied to clipboard

md-autocomplete: md-no-float support

Open jgoux opened this issue 11 years ago • 12 comments

Would it be possible to support md-no-float attribute when using md-autocomplete with md-floating-label option ? So the autocomplete integrates great with other inputs in forms, and we have the option to make it "placeholder only".

jgoux avatar Jun 11 '15 09:06 jgoux

+1

johnSowingo avatar Aug 21 '15 13:08 johnSowingo

+1

san4ik avatar Aug 27 '15 10:08 san4ik

+1

ghost avatar Aug 28 '15 17:08 ghost

CSS workaround to selectively hide the label and keep correct alignment with other md-no-float elements (based on the workaround by @lkaragol):

md-autocomplete.no-label > md-autocomplete-wrap > md-input-container > label {
  display: none;
}

Then apply the class no-label to the autocomplete in question.

It would be really nice to have an official solution to this that preserves placeholder labels.

ghost avatar Aug 28 '15 17:08 ghost

I have seen that solution but the issue still exists because I need a placeholder.

johnSowingo avatar Aug 28 '15 17:08 johnSowingo

Indeed

ghost avatar Aug 28 '15 18:08 ghost

Here's a workaround that actually shows the labels, with a couple of caveats: (We couldn't wait)

// Workaround lack of md-autocomplete: md-no-float support: https://github.com/angular/material/issues/3219.
// Apply no-float class to md-autocomplete with md-floating-label. Drawbacks:
//  - Clears label when focused, not just when has-value, to avoid clearing the scaling
//  - Font weight appears stronger than for input placeholders
//  - It's a hack
md-autocomplete.no-float > md-autocomplete-wrap > md-input-container {
    > label {
        transform: none;
        transition-property: none;
        color: #BDBDBD;  // input placeholder gray
        position: absolute;
        top: 10px;
    }
    &.md-input-focused > label {
        color: transparent;
    }
    &.md-input-has-value > label {
        color: transparent;
    }
}

ghost avatar Sep 02 '15 17:09 ghost

+1 would be great!

dohomi avatar Sep 23 '15 16:09 dohomi

@bluebirdtech, your workaround is awesome, thanks for sharing! Unfortunately it broke for me in RC7, so I hope they get to this not long after 1.0 is released.

mattdanna avatar Dec 13 '15 06:12 mattdanna

@mattdanna Thanks for the update - I haven't updated for a while so didn't spot that. If this hasn't been fixed when I next take an update I'll see if there's a workaround for the workaround. ;)

ghost avatar Dec 14 '15 10:12 ghost

Just updated to 1.0.5. The updated workaround is shorter and produces better results, as the placeholder remains visible when the input has focus.

// Workaround lack of md-autocomplete: md-no-float support: https://github.com/angular/material/issues/3219.
// Apply no-float class to md-autocomplete with md-floating-label.
md-autocomplete.no-float > md-autocomplete-wrap > md-input-container {
    margin-top: 0px;
    > label {
        -webkit-transform: translate3d(1px,28px,0) scale(1) !important;
        transform: translate3d(1px,28px,0) scale(1) !important;
        color: #BDBDBD;  // input placeholder gray
    }
    &.md-input-has-value > label {
        display: none !important;
    }
}

ghost avatar Feb 18 '16 11:02 ghost

+1

EmmanuelPREVOST avatar Mar 15 '16 09:03 EmmanuelPREVOST