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

Errors when using a native select inside a mat-form-field #14101

Closed
jjreynoldsMatric opened this issue Nov 12, 2018 · 1 comment · Fixed by #14102
Closed

Errors when using a native select inside a mat-form-field #14101

jjreynoldsMatric opened this issue Nov 12, 2018 · 1 comment · Fixed by #14102
Assignees
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@jjreynoldsMatric
Copy link

jjreynoldsMatric commented Nov 12, 2018

Bug, feature request, or proposal:

When you place a native select inside a mat-form-field, many TypeErrors occur.

ERROR TypeError: Cannot read property 'label' of undefined
at MatInput.get [as shouldLabelFloat] (input.es5.js:590)
at MatFormField.push../node_modules/@angular/material/esm5/form-field.es5.js.MatFormField._shouldLabelFloat (form-field.es5.js:535)
at Object.eval [as updateRenderer] (FormComponent.html:10)
at Object.debugUpdateRenderer [as updateRenderer] (core.js:20458)
at checkAndUpdateView (core.js:19833)
at callViewAction (core.js:20069)
at execComponentViewsAction (core.js:20011)
at checkAndUpdateView (core.js:19834)
at callViewAction (core.js:20069)
at execComponentViewsAction (core.js:20011)

What is the expected behavior?

No errors should occur. The field's placeholder should be on the same line as the select's arrow until the select is clicked. Its should then float into a label, similar to how inputs react with the matInput directive.

What is the current behavior?

Getting TypeErrors. The placeholder is always floating, even when no option is chosen.

What are the steps to reproduce?

StackBlitz was giving me problems, so I created a sample repo showcasing the error: https://github.com/jjreynoldsMatric/native-select-error-angular-material

To reproduce: Create a form with a native select inside a mat-form-field with a matNativeControl directive on it. As far as I've seen, this is all it takes.

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

To allow support for native select lists

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

This occurs in both Chrome and Edge.
Angular CLI: 7.0.5
Node: 10.13.0
OS: win32 x64
Angular: 7.0.3
... animations, cdk, common, compiler, compiler-cli, core, forms
... http, language-service, material, platform-browser
... platform-browser-dynamic, platform-server, router

Package Version

@angular-devkit/architect 0.10.5
@angular-devkit/build-angular 0.10.5
@angular-devkit/build-optimizer 0.10.5
@angular-devkit/build-webpack 0.10.5
@angular-devkit/core 7.0.5
@angular-devkit/schematics 7.0.5
@angular/cli 7.0.5
@ngtools/webpack 7.0.5
@schematics/angular 7.0.5
@schematics/update 0.10.5
rxjs 6.3.3
typescript 3.1.6
webpack 4.25.1

Is there anything else we should know?

This interferes with the validity of the form. In a project that is not the git repo I provided, the select is a required field. The errors allow the form to be submitted with no data selected and in an invalid state.

@crisbeto crisbeto self-assigned this Nov 12, 2018
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent has pr labels Nov 12, 2018
crisbeto added a commit to crisbeto/material2 that referenced this issue Nov 12, 2018
Fixes an error being thrown when there's a native `select` without any options inside a `mat-form-field`.

Fixes angular#14101.
jelbourn pushed a commit that referenced this issue Nov 27, 2018
Fixes an error being thrown when there's a native `select` without any options inside a `mat-form-field`.

Fixes #14101.
jelbourn pushed a commit that referenced this issue Dec 3, 2018
Fixes an error being thrown when there's a native `select` without any options inside a `mat-form-field`.

Fixes #14101.
josephperrott pushed a commit to josephperrott/components that referenced this issue Jan 14, 2019
Fixes an error being thrown when there's a native `select` without any options inside a `mat-form-field`.

Fixes angular#14101.
@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 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants