-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
feat(select): make select work inside form-field #6488
Conversation
@mmalerba Great work! I played around the demo. It seems mostly good, but one thing I noticed is that sometimes you can click on the trigger without actually opening the panel. It floats the label, but the panel stays closed. If you try to click closer to the underline or the floating label, you can reproduce. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code-wise LGTM, but I'm not too sure about the API.
<md-select placeholder="Select"> | ||
<md-option value="option">Option</md-option> | ||
</md-select> | ||
<md-form-field> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API-wise, do we really want people to have to wrap every select in a form field? E.g. if you were using option groups, you'd have to write 4 levels of HTML. Aside from having to proxy a few @Input
-s, what are the cons of having the form field be consumed by md-select
internally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the past we've preferred composition style APIs since they're more flexible, even if they are a bit more verbose. I think the extra typing is worth it, but it's a fair point. @jelbourn do you have an opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do like the consistency of having both select
and input
inside the same form-field
; it makes it clear that the prefix, suffix, hint, and error belong to the form field. Very explicit, no magic. It's also more maintainable for us, since we don't have to forward along every form-field
API through select over time.
I don't feel incredibly strongly about it, though. @mmalerba up to you if you think it would be the same amount of work to do it the other way around; it would certainly make the migration easier
src/lib/select/select.ts
Outdated
@@ -890,31 +893,29 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On | |||
|
|||
/** Calculates the scroll position and x- and y-offsets of the overlay panel. */ | |||
private _calculateOverlayPosition(): void { | |||
this._triggerHeight = this.trigger.nativeElement.getBoundingClientRect().height; | |||
this._triggerFontSize = this._measureFontSizeEl.nativeElement.getBoundingClientRect().height; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that this would be completely accurate. Why not use getComputedStyle
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know if getComputedStyle
is guaranteed to give me a px
value for font-size
(as opposed to em
, %
, etc)? That was my main motivation for not doinggetComputedStyle
. Also, I assume getComputedStyle
is no worse from a performance perspective?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure that you'll get a pixel value no matter what. Should be pretty easy to verify. As for performance, it should be pretty close to the getBoundingClientRect
call.
@kara good catch, I fixed the focus and click behavior and also corrected the 1px error in placement of the multi-select dropdown |
96cdb5e
to
b9bef76
Compare
@@ -515,36 +516,36 @@ describe('MdInput without forms', function () { | |||
fixture.detectChanges(); | |||
|
|||
let inputEl = fixture.debugElement.query(By.css('input')).nativeElement; | |||
let labelEl = fixture.debugElement.query(By.css('label')).nativeElement; | |||
let formFieldEl = fixture.debugElement.query(By.css('.mat-form-field')).nativeElement; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mmalerba Taking advantage of the fact that you're working on it, would you be able to replace, let
by const
when possible? It seems that (almost) all the variables here (in whole test file) aren't being reassigned and still are declared as let
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like something we should do as part o a separate cleanup pass of the whole project, I'm sure there are tools that can analyze and fix this for us
5411bf7
to
c1af22d
Compare
22e1182
to
218c98b
Compare
…rlapping the trigger arrow
TODO(mmalerba): is currently broken in components with preserveWhitespace: false, so we | ||
evaluate it as a JS string binding instead. Change back to once it works again. | ||
--> | ||
<ng-container *ngIf="empty">{{'\xa0'}}</ng-container> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't appear to work with AOT.
@mmalerba The Demos are great. Can you be able to provide example code of this? |
Awesome! |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Demos:
https://mmalerba-demo3.firebaseapp.com/baseline
https://mmalerba-demo3.firebaseapp.com/select
BREAKING CHANGES:
md-select
must now be wrapped in anmd-form-field
MdFormFieldControl
now has 2 new properties:controlType
,shouldPlaceholderFloat
and 1 new method:onContainerClick