Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
feat(input): allow skip hidden inputs
Browse files Browse the repository at this point in the history
BREAKING CHANGE: inputs with type `hidden` will be skipped by the `input-container`

Fixes #2153

Closes #6425
  • Loading branch information
devversion authored and ThomasBurleson committed Apr 1, 2016
1 parent d86a4ff commit e7c51e3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/components/input/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ angular.module('material.components.input', [
* Input and textarea elements will not behave properly unless the md-input-container
* parent is provided.
*
* A single `<md-input-container>` should contain only one `<input>` element, otherwise it will throw an error.
*
* <b>Exception:</b> Hidden inputs (`<input type="hidden" />`) are ignored and will not throw an error, so
* you may combine these with other inputs.
*
* @param md-is-error {expression=} When the given expression evaluates to true, the input container
* will go into error state. Defaults to erroring if the input has been touched and is invalid.
* @param md-no-float {boolean=} When present, `placeholder` attributes on the input will not be converted to floating
Expand Down Expand Up @@ -247,7 +252,10 @@ function inputTextareaDirective($mdUtil, $window, $mdAria) {
var isReadonly = angular.isDefined(attr.readonly);

if (!containerCtrl) return;
if (containerCtrl.input) {
if (attr.type === 'hidden') {
element.attr('aria-hidden', 'true');
return;
} else if (containerCtrl.input) {
throw new Error("<md-input-container> can only have *one* <input>, <textarea> or <md-select> child element!");
}
containerCtrl.input = element;
Expand Down
14 changes: 14 additions & 0 deletions src/components/input/input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ describe('md-input-container directive', function() {
expect(el).not.toHaveClass('md-input-focused');
});

it('should skip a hidden input', function() {
var container = setup('type="hidden"');
var controller = container.controller('mdInputContainer');
var textInput = angular.element('<input type="text">');

expect(controller.input).toBeUndefined();

container.append(textInput);
$compile(textInput)(pageScope);

expect(controller.input[0]).toBe(textInput[0]);
});


it('should set has-value class on container for non-ng-model input', function() {
var el = setup();
expect(el).not.toHaveClass('md-input-has-value');
Expand Down

0 comments on commit e7c51e3

Please sign in to comment.