Skip to content

Commit 4d82380

Browse files
authored
Merge pull request #1244 from Choices-js/fix-html-comments-in-option
Fix HTML comments were copied from backing `<option>` value and were rendered as text
2 parents 75601d7 + 6be7b73 commit 4d82380

File tree

5 files changed

+7
-5
lines changed

5 files changed

+7
-5
lines changed

public/test/select-multiple/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ <h2>Select multiple inputs</h2>
6666
id="choices-basic"
6767
multiple
6868
>
69-
<option value="Choice 1">Choice 1</option>
69+
<option value="Choice 1"><!-- html comment -->Choice 1</option>
7070
<option value="Choice 2">Choice 2</option>
7171
<option value="Find me">Choice 3</option>
7272
<option value="Choice 4">Choice 4</option>
7373
</select>
7474
<script>
7575
document.addEventListener('DOMContentLoaded', function() {
7676
const choicesBasic = new Choices('#choices-basic', {
77-
allowHTML: true,
77+
allowHTML: false,
7878
});
7979
document
8080
.querySelector('button.disable')

public/test/select-one/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ <h2>Select one inputs</h2>
6161
<button class="disable push-bottom">Disable</button>
6262
<button class="enable push-bottom">Enable</button>
6363
<select class="form-control" name="choices-basic" id="choices-basic">
64-
<option value="Choice 1">Choice 1</option>
64+
<option value="Choice 1"><!-- html comment -->Choice 1</option>
6565
<option value="Choice 2">Choice 2</option>
6666
<option value="Find me">Choice 3</option>
6767
<option value="Choice 4">Choice 4</option>
6868
</select>
6969
<script>
7070
document.addEventListener('DOMContentLoaded', function() {
7171
const choicesBasic = new Choices('#choices-basic', {
72-
allowHTML: true,
72+
allowHTML: false,
7373
});
7474
document
7575
.querySelector('button.disable')

src/scripts/components/wrapped-select.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default class WrappedSelect extends WrappedElement<HTMLSelectElement> {
8181
score: 0,
8282
rank: 0,
8383
value: option.value,
84-
label: option.innerHTML,
84+
label: option.innerText, // HTML options do not support most html tags, but innerHtml will extract html comments...
8585
element: option,
8686
active: true,
8787
// this returns true if nothing is selected on initial load, which will break placeholder support

test-e2e/tests/select-multiple.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ describe(`Choices - select multiple`, () => {
4545

4646
await suite.choices.first().click();
4747
await expect(suite.items.last()).toHaveText(selectedChoiceText);
48+
await expect(suite.items.last()).not.toHaveText('!--');
4849
});
4950

5051
test('remove selected choice from dropdown list', async ({ page, bundle }) => {

test-e2e/tests/select-one.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ describe(`Choices - select one`, () => {
4545

4646
await suite.choices.first().click();
4747
await expect(suite.items.last()).toHaveText(selectedChoiceText);
48+
await expect(suite.items.last()).not.toHaveText('!--');
4849
});
4950

5051
test('does not remove selected choice from dropdown list', async ({ page, bundle }) => {

0 commit comments

Comments
 (0)