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

Commit a2ac9a3

Browse files
devversionThomasBurleson
authored andcommitted
feat(input): allow skip hidden inputs
BREAKING CHANGE: inputs with type `hidden` will be skipped by the `input-container` Fixes #2153 Closes #6425
1 parent fd9d162 commit a2ac9a3

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/components/input/input.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ angular.module('material.components.input', [
3434
* Input and textarea elements will not behave properly unless the md-input-container
3535
* parent is provided.
3636
*
37+
* A single `<md-input-container>` should contain only one `<input>` element, otherwise it will throw an error.
38+
*
39+
* <b>Exception:</b> Hidden inputs (`<input type="hidden" />`) are ignored and will not throw an error, so
40+
* you may combine these with other inputs.
41+
*
3742
* @param md-is-error {expression=} When the given expression evaluates to true, the input container
3843
* will go into error state. Defaults to erroring if the input has been touched and is invalid.
3944
* @param md-no-float {boolean=} When present, `placeholder` attributes on the input will not be converted to floating
@@ -269,7 +274,10 @@ function inputTextareaDirective($mdUtil, $window, $mdAria, $timeout) {
269274

270275

271276
if (!containerCtrl) return;
272-
if (containerCtrl.input) {
277+
if (attr.type === 'hidden') {
278+
element.attr('aria-hidden', 'true');
279+
return;
280+
} else if (containerCtrl.input) {
273281
throw new Error("<md-input-container> can only have *one* <input>, <textarea> or <md-select> child element!");
274282
}
275283
containerCtrl.input = element;

src/components/input/input.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,20 @@ describe('md-input-container directive', function() {
160160
expect(el).not.toHaveClass('md-input-focused');
161161
});
162162

163+
it('should skip a hidden input', function() {
164+
var container = setup('type="hidden"');
165+
var controller = container.controller('mdInputContainer');
166+
var textInput = angular.element('<input type="text">');
167+
168+
expect(controller.input).toBeUndefined();
169+
170+
container.append(textInput);
171+
$compile(textInput)(pageScope);
172+
173+
expect(controller.input[0]).toBe(textInput[0]);
174+
});
175+
176+
163177
it('should set has-value class on container for non-ng-model input', function() {
164178
var el = setup();
165179
expect(el).not.toHaveClass('md-input-has-value');

0 commit comments

Comments
 (0)