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(input): Add pure-CSS floating label logic that will work on... #8491

Merged
merged 2 commits into from
Nov 28, 2017

Conversation

mmalerba
Copy link
Contributor

...server-side-rendered pages.

fixes #8247

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Nov 16, 2017
.mat-input-server:focus + .mat-form-field-placeholder-wrapper .mat-form-field-placeholder {
@include _mat-form-field-placeholder-floating(
$subscript-font-scale, $infix-padding, $infix-margin-top);
}
Copy link
Member

Choose a reason for hiding this comment

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

Can't this one be combined with the other one above?
(&.mat-form-field-should-float .mat-form-field-placeholder)

width: (100% / $font-scale) + 0.0001;
}

@mixin _mat-form-field-placeholder-float-nodedupe2($font-scale, $infix-padding, $infix-margin-top) {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of adding another mixin, I realized we could programatically change the rule each time it's stamped out, e.g.:

$uniqueId: 0;

@mixin cool-style() {
  content: 'Hello' + $uniqueId;
  $uniqueId: $uniqueId + 1 !global;
}


.one {
  @include cool-style(); // content: "Hello0";
}

.two {
  @include cool-style(); // content: "Hello1";
}

@@ -162,7 +168,8 @@ export class MatInput implements MatFormFieldControl<any>, OnChanges, OnDestroy,
@Optional() protected _parentForm: NgForm,
@Optional() protected _parentFormGroup: FormGroupDirective,
private _defaultErrorStateMatcher: ErrorStateMatcher,
@Optional() @Self() @Inject(MAT_INPUT_VALUE_ACCESSOR) inputValueAccessor: any) {
@Optional() @Self() @Inject(MAT_INPUT_VALUE_ACCESSOR) inputValueAccessor: any,
@Optional() @Inject(PLATFORM_ID) platformId?: Object) {
Copy link
Member

Choose a reason for hiding this comment

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

This class already injects Platform from cdk/platform, you could just use !this._platform.isBrowser

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Platform just checks if the document exists and has type object. This probably won't work now that universal gives us a domino document right?

We probably need to update the Platform.isBrowser logic, but I didn't want to do it in this PR.

Copy link
Member

Choose a reason for hiding this comment

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

I'd be hesitant to change it now because it could be a breaking change

Copy link
Contributor Author

@mmalerba mmalerba Nov 17, 2017

Choose a reason for hiding this comment

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

That's why I left it out of this PR, but I do think we have to change it in the future. We need to audit the places where we're using this and check which ones are using it as a way to check if the document is defined and which ones really care that we're on the server. The latter checks are now incorrect due to Angular's changes. (The one I added in this PR for example, would be broken if I depended on Platform.isBrowser)

edit: according to @crisbeto Universal doesn't actually simulate the global document variable, so Platform.isBrowser should still work. I'll change it to that, but I still think we should update Platform in the future to use the official method of checking, in case they ever do decide to simulate the document global.

@mmalerba
Copy link
Contributor Author

comments addressed

@mmalerba mmalerba added the P2 The issue is important to a large percentage of users, with a workaround label Nov 20, 2017
@mmalerba mmalerba added this to the 5.0 milestone Nov 20, 2017
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Nov 27, 2017
@tinayuangao tinayuangao merged commit 1a7a61a into angular:master Nov 28, 2017
tinayuangao pushed a commit to tinayuangao/material2 that referenced this pull request Nov 29, 2017
…ngular#8491)

* fix(input): Add pure-CSS floating label logic that will work on...

...server-side-rendered pages.

* address comments
@mmalerba mmalerba deleted the input-ssr branch July 31, 2018 21:55
@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 P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a better input experience with Server Side Rendering
4 participants