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

Commit c12d1e2

Browse files
committed
fix(input): number input width in webkit
Fixes an issue in Webkit browsers where number inputs would collapse to about 1/3 of their proper size, if they're placed in a flexbox and have `min` and `max` attributes. Fiddle with a simplified example of the issue: https://jsfiddle.net/crisbeto/phm2nuar/3/ Closes #7349.
1 parent 0b89a87 commit c12d1e2

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/components/input/input.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ function inputTextareaDirective($mdUtil, $window, $mdAria, $timeout) {
264264
var ngModelCtrl = ctrls[1] || $mdUtil.fakeNgModel();
265265
var isReadonly = angular.isDefined(attr.readonly);
266266
var mdNoAsterisk = $mdUtil.parseAttributeBoolean(attr.mdNoAsterisk);
267+
var tagName = element[0].tagName.toLowerCase();
267268

268269

269270
if (!containerCtrl) return;
@@ -287,7 +288,13 @@ function inputTextareaDirective($mdUtil, $window, $mdAria, $timeout) {
287288
element.attr('id', 'input_' + $mdUtil.nextUid());
288289
}
289290

290-
if (element[0].tagName.toLowerCase() === 'textarea') {
291+
// This works around a Webkit issue where number inputs, placed in a flexbox, that have
292+
// a `min` and `max` will collapse to about 1/3 of their proper width. Please check #7349
293+
// for more info. Also note that we don't override the `step` if the user has specified it,
294+
// in order to prevent some unexpected behaviour.
295+
if (tagName === 'input' && attr.type === 'number' && attr.min && attr.max && !attr.step) {
296+
element.attr('step', 'any');
297+
} else if (tagName === 'textarea') {
291298
setupTextarea();
292299
}
293300

src/components/input/input.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ describe('md-input-container directive', function() {
195195
expect(el.find('label').attr('for')).toBe(el.find('input').attr('id'));
196196
});
197197

198+
it('should set the "step" attribute to "any" if "min" and "max" are specified', function() {
199+
// check #7349 for more info
200+
var el = setup('type="number" min="1" max="999"');
201+
expect(el.find('input').attr('step')).toBe('any');
202+
});
203+
198204
describe('md-no-asterisk', function() {
199205

200206
it('should not show asterisk on required label if disabled', function() {

0 commit comments

Comments
 (0)