Skip to content

Commit ed82d16

Browse files
committed
Support <option> label attribute
1 parent c2970f0 commit ed82d16

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

public/test/select-multiple/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ <h2>Select multiple inputs</h2>
6767
multiple
6868
>
6969
<option value="Choice 1"><!-- html comment -->Choice 1</option>
70-
<option value="Choice 2">Choice 2</option>
70+
<option value="Choice 2" label="Choice 2" />
7171
<option value="Find me">Choice 3</option>
7272
<option value="Choice 4">Choice 4</option>
7373
</select>

public/test/select-one/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ <h2>Select one inputs</h2>
6262
<button class="enable push-bottom">Enable</button>
6363
<select class="form-control" name="choices-basic" id="choices-basic">
6464
<option value="Choice 1"><!-- html comment -->Choice 1</option>
65-
<option value="Choice 2">Choice 2</option>
65+
<option value="Choice 2" label="Choice 2" />
6666
<option value="Find me">Choice 3</option>
6767
<option value="Choice 4">Choice 4</option>
6868
</select>

src/scripts/components/wrapped-select.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ export default class WrappedSelect extends WrappedElement<HTMLSelectElement> {
8181
score: 0,
8282
rank: 0,
8383
value: option.value,
84-
label: option.innerText, // HTML options do not support most html tags, but innerHtml will extract html comments...
84+
label:
85+
// HTML options do not support most html tags, but innerHtml will extract html comments...
86+
// <option label="..." /> innerText is full of whitespace
87+
!option.innerText.trim() && option.hasAttribute('label')
88+
? option.getAttribute('label') || ''
89+
: option.innerText,
8590
element: option,
8691
active: true,
8792
// this returns true if nothing is selected on initial load, which will break placeholder support

0 commit comments

Comments
 (0)