Skip to content

Commit b1f0a57

Browse files
josepharharsadym-chromium
authored andcommitted
Only update first appended <selectedcontent> element
Since we are only planning to support one <selectedcontent> element in <select>, this patch only performs a clone into the first <selectedcontent> in tree order. This is in response to feedback here: whatwg/html#10633 (comment) This patch also removes the logic which clears <selectedcontent> elements when they are removed/disconnected. Change-Id: I1580ec9f12df463d1f5134905e3e527cfefa694d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6043186 Reviewed-by: David Baron <[email protected]> Commit-Queue: Joey Arhar <[email protected]> Cr-Commit-Position: refs/heads/main@{#1399301}
1 parent ab4431b commit b1f0a57

File tree

1 file changed

+77
-2
lines changed

1 file changed

+77
-2
lines changed

html/semantics/forms/the-select-element/customizable-select/selectedcontent.tentative.html

+77-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@
8080
'Clicking on an option element should update the <selectedcontent>.');
8181

8282
selectedcontent.remove();
83-
assert_equals(selectedcontent.innerHTML, '',
84-
'Removing the <selectedcontent> from the <select> should make it clear its contents.');
83+
assert_equals(selectedcontent.innerHTML, optionTwo.innerHTML,
84+
'Removing the <selectedcontent> from the <select> should not make it clear its contents.');
8585
button.appendChild(selectedcontent);
8686
assert_equals(selectedcontent.innerHTML, optionTwo.innerHTML,
8787
'Re-inserting the <selectedcontent> should make it update its contents.');
@@ -96,3 +96,78 @@
9696
// TODO(crbug.com/336844298): Add tests for mutation records during parsing
9797
}, 'The <selectedcontent> element should reflect the HTML contents of the selected <option>.');
9898
</script>
99+
100+
<select id=select2>
101+
<button>
102+
<selectedcontent></selectedcontent>
103+
</button>
104+
<option class=one>one</option>
105+
<option class=two>two</option>
106+
<option class=three>three</option>
107+
</select>
108+
109+
<script>
110+
promise_test(async () => {
111+
const select = document.getElementById('select2');
112+
const button = select.querySelector('button');
113+
const selectedcontent = select.querySelector('selectedcontent');
114+
assert_equals(selectedcontent.textContent, 'one',
115+
'selectedcontent should initially be one.');
116+
117+
const selectedcontent2 = document.createElement('selectedcontent');
118+
button.appendChild(selectedcontent2);
119+
select.value = 'two';
120+
assert_equals(selectedcontent.textContent, 'two',
121+
'First selectedcontent should be kept up to date.');
122+
assert_equals(selectedcontent2.textContent, '',
123+
'Second selectedcontent should not be kept up to date.');
124+
125+
button.insertBefore(selectedcontent2, selectedcontent);
126+
select.value = 'one';
127+
assert_equals(selectedcontent.textContent, '',
128+
'Second selectedcontent in tree order should be cleared after another is inserted.');
129+
assert_equals(selectedcontent2.textContent, 'one',
130+
'First selectedcontent in tree order should be kept up to date.');
131+
132+
selectedcontent.textContent = 'two';
133+
selectedcontent.remove();
134+
assert_equals(selectedcontent.textContent, 'two',
135+
'selectedcontent should not have its children modified after removal.');
136+
137+
select.value = 'three';
138+
assert_equals(selectedcontent2.textContent, 'three',
139+
'Remaining selectedcontent should be kept up to date.');
140+
assert_equals(selectedcontent.textContent, 'two',
141+
'Removed selectedcontent should not be kept up to date.');
142+
143+
button.insertBefore(selectedcontent, selectedcontent2);
144+
assert_equals(selectedcontent.textContent, 'three',
145+
'Inserted selectedcontent should be updated if it is the first in tree order.');
146+
assert_equals(selectedcontent2.textContent, '',
147+
'Second selectedcontent in tree order should be cleared when another is inserted.');
148+
149+
selectedcontent.remove();
150+
assert_equals(selectedcontent2.textContent, 'three',
151+
'Remaining selectedcontent should be updated when first in tree order is removed.');
152+
}, 'When there are multiple <selectedcontent> elements, only the one in tree order should be kept up to date.');
153+
154+
promise_test(async () => {
155+
const select = document.createElement('select');
156+
select.innerHTML = '<option>one</option><option>two</option>';
157+
const button = document.createElement('button');
158+
select.appendChild(button);
159+
160+
const selectedcontent = document.createElement('selectedcontent');
161+
button.appendChild(selectedcontent);
162+
assert_equals(selectedcontent.textContent, '',
163+
'<selectedcontent> should not be updated when appending to a disconnected select.');
164+
165+
select.value = 'two';
166+
assert_equals(selectedcontent.textContent, '',
167+
'<selectedcontent> should not be updated when changing value of a disconnected select.');
168+
169+
document.body.appendChild(select);
170+
assert_equals(selectedcontent.textContent, 'two',
171+
'<selectedcontent> should be updated when <select> is connected to the document.');
172+
}, '<seletedcontent> behavior in disconnected <select>.');
173+
</script>

0 commit comments

Comments
 (0)