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

Commit c6c5d48

Browse files
crisbetoThomasBurleson
authored andcommitted
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. Closes #7761
1 parent 437f764 commit c6c5d48

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
@@ -289,6 +289,7 @@ function inputTextareaDirective($mdUtil, $window, $mdAria, $timeout, $mdGesture)
289289
var ngModelCtrl = ctrls[1] || $mdUtil.fakeNgModel();
290290
var isReadonly = angular.isDefined(attr.readonly);
291291
var mdNoAsterisk = $mdUtil.parseAttributeBoolean(attr.mdNoAsterisk);
292+
var tagName = element[0].tagName.toLowerCase();
292293

293294

294295
if (!containerCtrl) return;
@@ -315,7 +316,13 @@ function inputTextareaDirective($mdUtil, $window, $mdAria, $timeout, $mdGesture)
315316
element.attr('id', 'input_' + $mdUtil.nextUid());
316317
}
317318

318-
if (element[0].tagName.toLowerCase() === 'textarea') {
319+
// This works around a Webkit issue where number inputs, placed in a flexbox, that have
320+
// a `min` and `max` will collapse to about 1/3 of their proper width. Please check #7349
321+
// for more info. Also note that we don't override the `step` if the user has specified it,
322+
// in order to prevent some unexpected behaviour.
323+
if (tagName === 'input' && attr.type === 'number' && attr.min && attr.max && !attr.step) {
324+
element.attr('step', 'any');
325+
} else if (tagName === 'textarea') {
319326
setupTextarea();
320327
}
321328

src/components/input/input.spec.js

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

212+
it('should set the "step" attribute to "any" if "min" and "max" are specified', function() {
213+
// check #7349 for more info
214+
var el = setup('type="number" min="1" max="999"');
215+
expect(el.find('input').attr('step')).toBe('any');
216+
});
217+
212218
describe('md-no-asterisk', function() {
213219

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

0 commit comments

Comments
 (0)