Dogfalo/materialize · error · Error
noUiSlider: 'padding' option must be a positive number.
Error message
noUiSlider: 'padding' option must be a positive number.
What it means
Thrown by testPadding when parsed.padding < 0, after getMargin converted the input to a percentage. padding must shrink the selectable region, so a negative input (which would expand it) is rejected. This check runs only after the linear-range check passes, so it is reached solely on linear sliders with a numeric padding.
Source
Thrown at extras/noUiSlider/nouislider.js:641
function testPadding ( parsed, entry ) {
if ( !isNumeric(entry) ){
throw new Error("noUiSlider: 'padding' option must be numeric.");
}
if ( entry === 0 ) {
return;
}
parsed.padding = parsed.spectrum.getMargin(entry);
if ( !parsed.padding ) {
throw new Error("noUiSlider: 'padding' option is only supported on linear sliders.");
}
if ( parsed.padding < 0 ) {
throw new Error("noUiSlider: 'padding' option must be a positive number.");
}
if ( parsed.padding >= 50 ) {
throw new Error("noUiSlider: 'padding' option must be less than half the range.");
}
}
function testDirection ( parsed, entry ) {
// Set direction as a numerical value for easy parsing.
// Invert connection for RTL sliders, so that the proper
// handles get the connect/background classes.
switch ( entry ) {
case 'ltr':
parsed.dir = 0;
break;
case 'rtl':
parsed.dir = 1;View on GitHub (pinned to 824e78248b)
Solutions
- Pass a non-negative number: padding: 10.
- Clamp the computed value: Math.max(0, value).
- Use 0 (or omit padding) to disable.
Example fix
// before padding: -5 // after padding: Math.max(0, p)
Defensive patterns
Strategy: validation
Validate before calling
if (opts.padding != null && opts.padding < 0) {
throw new Error('padding must be non-negative');
}
// or clamp: opts.padding = Math.max(0, Number(opts.padding)); Try / catch
try { noUiSlider.create(el, opts); }
catch (e) { if (/padding' option must be a positive number/.test(e.message)) { opts.padding = Math.abs(opts.padding); /* retry */ } else throw e; } Prevention
- Clamp computed padding with Math.max(0, value) before passing it in.
- Validate sign at the config boundary, especially for derived values.
- Treat negative padding as a bug in the upstream calculation, not a feature.
When it happens
Trigger: padding: -10, a computed padding that goes negative, or padding: -0.0001 from rounding error.
Common situations: Subtracting a margin from a base value and going negative, a sign error in computation, or feeding an unclamped user input straight through.
Related errors
- noUiSlider: 'limit', 'margin' and 'padding' must be divisibl
- noUiSlider: 'padding' option must be numeric.
- noUiSlider: 'padding' option is only supported on linear sli
- noUiSlider: 'range' contains invalid value.
- noUiSlider: 'range' value isn't numeric.
AI-assisted analysis of Dogfalo/materialize@824e78248b (2026-08-13).
Data as JSON: /api/errors/f18cfc5328ffa7ad.
Report an issue: GitHub.