display-contents-blockify-dynamic.html (3477B)
1 <!doctype html> 2 <link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1561283"> 3 <link rel="help" href="https://drafts.csswg.org/css-display/#valdef-display-contents"> 4 <link rel="help" href="https://drafts.csswg.org/css-grid/#grid-item-display"> 5 <link rel="author" href="https://mozilla.org" title="Mozilla"> 6 <link rel="author" href="mailto:emilio@crisal.io" title="Emilio Cobos Álvarez"> 7 <link rel="author" href="mailto:obrufau@igalia.com" title="Oriol Brufau"> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <style> 11 .grid { display: grid } 12 </style> 13 <div style="display: grid"> 14 <span id="grid-child"> 15 <span></span> 16 </div> 17 </div> 18 <div id="grid-to-block" style="display: grid"> 19 <div style="display: contents"> 20 <div style="display: contents"> 21 <button>button1</button> 22 <button id="deblockified">button2</button> 23 </div> 24 </div> 25 </div> 26 <div id="block-to-grid" style="display: block"> 27 <div style="display: contents"> 28 <div style="display: contents"> 29 <button>button1</button> 30 <button id="blockified">button2</button> 31 </div> 32 </div> 33 </div> 34 <script> 35 function display(el) { 36 return getComputedStyle(el).display; 37 } 38 test(function() { 39 let child = document.getElementById("grid-child"); 40 let grandChild = child.firstElementChild; 41 assert_equals(display(child), "block", "Grid child should get blockified"); 42 assert_equals(display(grandChild), "inline", "Grid grand-child should not get initially blockified"); 43 child.style.display = "contents"; 44 assert_equals(display(child), "contents", "No reason for it not to become display: contents"); 45 assert_equals(display(grandChild), "block", "Grid grand-child with display: contents parent should get blockified"); 46 child.style.display = ""; 47 assert_equals(display(child), "block", "Grid child should get blockified"); 48 assert_equals(display(grandChild), "inline", "Grid grand-child should get un-blockified when its parent's display stops being `contents`"); 49 }, "Dynamic changes to `display` causing blockification of children are handled correctly"); 50 51 test(() => { 52 let gridToBlock = document.getElementById("grid-to-block"); 53 let itemGrandChild = document.getElementById("deblockified"); 54 55 assert_equals(display(gridToBlock), "grid", "Container should be a grid"); 56 assert_equals(display(itemGrandChild), "block", "Item should have been blockified"); 57 gridToBlock.style.display = "block"; 58 assert_equals(display(gridToBlock), "block", "Container should become a block"); 59 assert_equals(display(itemGrandChild), "inline-block", "Item should get de-blockified"); 60 }, "Dynamic changes to `display` from `grid` to `block` should cause children to get de-blockified despite being children of `display: contents` elements"); 61 62 test(() => { 63 let blockToGrid = document.getElementById("block-to-grid"); 64 let itemGrandChild = document.getElementById("blockified"); 65 66 assert_equals(display(blockToGrid), "block", "Container should be a block"); 67 assert_equals(display(itemGrandChild), "inline-block", "Item should not have been blockified"); 68 blockToGrid.style.display = "grid"; 69 assert_equals(display(blockToGrid), "grid", "Container should become a grid"); 70 assert_equals(display(itemGrandChild), "block", "Item should get blockified"); 71 }, "Dynamic changes to `display` from `block` to `grid` should cause children to get blockified despite being children of `display: contents` elements") 72 </script>