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

feature(md-input): refactor MdInput as an attribute #1858

Closed
wants to merge 4 commits into from

Conversation

hansl
Copy link
Contributor

@hansl hansl commented Nov 14, 2016

using Projection.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Nov 14, 2016
@hansl hansl force-pushed the md-input-refactor branch 2 times, most recently from 20a1787 to 3cc8ddd Compare November 14, 2016 20:06
@jelbourn
Copy link
Member

@hansl seems to be some CI failures.

@hansl
Copy link
Contributor Author

hansl commented Nov 14, 2016

Seems like it. Looking.

[class]="_cssClass"
[attr.style]="_safeCssStyle"
[class.md-end]="align == 'end'"
[class.md-input-wrapper]="true">
Copy link
Member

Choose a reason for hiding this comment

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

I think you could simplify the classes to

<div (click)="focus()"
    class="md-input-wrapper"
    [class.md-end]="align == 'end'"
    [ngClass]="_cssClass"
    [attr.style]="_safeCssStyle"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -57,7 +57,7 @@ md-input, md-textarea {
}

// The Input element proper.
.md-input-element {
input[md-input], textarea[md-textarea] {
Copy link
Member

Choose a reason for hiding this comment

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

Could we keep the single class in order to keep specificity low?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

}
@Component({template: `
<input md-input [placeholder]="p">
<template #p>template placeholder</template>
Copy link
Member

Choose a reason for hiding this comment

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

Include an element inside the placeholder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@Input('class') _cssClass: string = '';
@Input('style') _cssStyle: string = '';
get _safeCssStyle(): SafeStyle {
return this._dom.bypassSecurityTrustStyle(this._cssStyle || '');
Copy link
Member

Choose a reason for hiding this comment

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

I think we should only bypassSecurityTrustStyle if we know that the style was set by a static value and not by binding, though I'm not sure there's a way to know for sure (since you could have something like style="width: {{w}}px").

If we always call bypassSecurityTrustStyle, we're effectively creating a hole in the SCE checks; a binding on style should fail if the user doesn't explicitly trust the value themselves.

@mprobst any thoughts on this? TL;DR forwarding style from one element to another.

}
get inputId(): string { return `${this.id}-input`; }
@HostBinding('attr.class') get _attrClass(): any { return null; }
@HostBinding('attr.style') get _attrStyle(): any { return null; }
Copy link
Member

Choose a reason for hiding this comment

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

I also just thought about the fact that ngClass, ngStyle, [class.whatever], and [style.whatever] will all potentially be a problem here. We should chat about dealing with these (potentially with Tobias)

@@ -0,0 +1,12 @@
<label class="md-placeholder"
Copy link
Member

Choose a reason for hiding this comment

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

It might be a problem if the placeholder is always the label for the input. I can see cases where you would want to provide a more specific label than what's in the placeholder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We tested it with the old interface, and there wasn't a problem.

import {coerceBooleanProperty} from '../core/coersion/boolean-property';


export const MD_PLACEHOLDER_HOST_TOKEN = new OpaqueToken('mdPlaceholderHost');
Copy link
Member

Choose a reason for hiding this comment

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

These don't normally have _TOKEN at the end (e.g., NG_VALIDATORS).

Add description comment for the token.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

The goal is to simplify the MdInput interface and allow it to evolve and
collaborate with other directives on an <input>. For example, Chips
could be a directive on the `<input>` as well.

The next steps are going to be adding back MdPlaceholder as such a
directive that collaborates with MdInput.
@hansl hansl force-pushed the md-input-refactor branch 3 times, most recently from 2a1ef5a to 2319aab Compare November 18, 2016 23:23
@hansl
Copy link
Contributor Author

hansl commented Nov 25, 2016

@jelbourn PTAL.

@jelbourn
Copy link
Member

jelbourn commented Dec 2, 2016

Closing in favor of #2052

@jelbourn jelbourn closed this Dec 2, 2016
@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
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.

3 participants