🌐 AI搜索 & 代理 主页
Skip to content

Commit e743cbd

Browse files
authored
Dimensions: fix computing outerWidth on SVGs
Fixes gh-3964 Closes gh-4096
1 parent 0645099 commit e743cbd

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

src/css.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ function boxModelAdjustment( elem, dimension, box, isBorderBox, styles, computed
107107
delta -
108108
extra -
109109
0.5
110-
) );
110+
111+
// If offsetWidth/offsetHeight is unknown, then we can't determine content-box scroll gutter
112+
// Use an explicit zero to avoid NaN (gh-3964)
113+
) ) || 0;
111114
}
112115

113116
return delta;

test/unit/dimensions.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,66 @@ QUnit.test( "table dimensions", function( assert ) {
352352
assert.equal( colElem.width(), 300, "col elements have width(), see #12243" );
353353
} );
354354

355+
QUnit.test( "SVG dimensions (basic content-box)", function( assert ) {
356+
assert.expect( 8 );
357+
358+
var svg = jQuery( "<svg width='100' height='100'></svg>" ).appendTo( "#qunit-fixture" );
359+
360+
assert.equal( svg.width(), 100 );
361+
assert.equal( svg.height(), 100 );
362+
363+
assert.equal( svg.innerWidth(), 100 );
364+
assert.equal( svg.innerHeight(), 100 );
365+
366+
assert.equal( svg.outerWidth(), 100 );
367+
assert.equal( svg.outerHeight(), 100 );
368+
369+
assert.equal( svg.outerWidth( true ), 100 );
370+
assert.equal( svg.outerHeight( true ), 100 );
371+
372+
svg.remove();
373+
} );
374+
375+
QUnit.test( "SVG dimensions (content-box)", function( assert ) {
376+
assert.expect( 8 );
377+
378+
var svg = jQuery( "<svg width='100' height='100' style='box-sizing: content-box; border: 1px solid white; padding: 2px; margin: 3px'></svg>" ).appendTo( "#qunit-fixture" );
379+
380+
assert.equal( svg.width(), 100 );
381+
assert.equal( svg.height(), 100 );
382+
383+
assert.equal( svg.innerWidth(), 104 );
384+
assert.equal( svg.innerHeight(), 104 );
385+
386+
assert.equal( svg.outerWidth(), 106 );
387+
assert.equal( svg.outerHeight(), 106 );
388+
389+
assert.equal( svg.outerWidth( true ), 112 );
390+
assert.equal( svg.outerHeight( true ), 112 );
391+
392+
svg.remove();
393+
} );
394+
395+
QUnit.test( "SVG dimensions (border-box)", function( assert ) {
396+
assert.expect( 8 );
397+
398+
var svg = jQuery( "<svg width='100' height='100' style='box-sizing: border-box; border: 1px solid white; padding: 2px; margin: 3px'></svg>" ).appendTo( "#qunit-fixture" );
399+
400+
assert.equal( svg.width(), 94 );
401+
assert.equal( svg.height(), 94 );
402+
403+
assert.equal( svg.innerWidth(), 98 );
404+
assert.equal( svg.innerHeight(), 98 );
405+
406+
assert.equal( svg.outerWidth(), 100 );
407+
assert.equal( svg.outerHeight(), 100 );
408+
409+
assert.equal( svg.outerWidth( true ), 106 );
410+
assert.equal( svg.outerHeight( true ), 106 );
411+
412+
svg.remove();
413+
} );
414+
355415
QUnit.test( "box-sizing:border-box child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #10413", function( assert ) {
356416
assert.expect( 16 );
357417

0 commit comments

Comments
 (0)