Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /html/rendering/widgets/field-sizing-select-contain-size.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<style>
.disable-default {
field-sizing: content;
}
.contain {
contain: size;
}
</style>
<div id="container"></div>
<script>
const container = document.querySelector('#container');
const DISABLE = 'class="disable-default"';
// Tests for drop-down box ====================================================
test(() => {
const s = '<select class="contain">><option>1<option>quick brown<option>fox</select>';
container.innerHTML = s + s;
container.lastElementChild.style.fieldSizing = 'content';
const widthForContent1 = container.lastElementChild.offsetWidth;
assert_greater_than_equal(container.firstElementChild.offsetWidth,
widthForContent1);
container.lastElementChild.selectedIndex = 1;
const widthForContentQuickBrown = container.lastElementChild.offsetWidth;
assert_equals(widthForContentQuickBrown, widthForContent1);
}, 'dropdown: The width should not depend on the selected OPTION when contain:size is set');
// Tests for list box =========================================================
// Some platforms don't support list box rendering.
container.innerHTML = '<select></select><select multiple></select>';
if (container.firstElementChild.offsetHeight != container.lastElementChild.offsetHeight) {
test(() => {
container.innerHTML = `<select class="contain" multiple><option>fox</select>` +
`<select class="contain disable-default" multiple><option>fox</select>`;
const former = container.firstElementChild;
const latter = container.lastElementChild;
const widthForOneItem = latter.offsetWidth;
assert_equals(former.offsetWidth, widthForOneItem);
latter.add(new Option('quick brown'));
assert_equals(latter.offsetWidth, widthForOneItem);
}, 'listbox: The width should not depend on content when contain:size is set');
}
</script>
</body>