Skip to content

Commit

Permalink
fix: o-multi-select, use textContent rather than innerText (#1388)
Browse files Browse the repository at this point in the history
This is to improve compatibility with JSDOM for users' tests. It shouldn't change the functionality of o-multi-select. However, they're not equivalent APIs, and it would be reasonable to use `innerText` or other web API which depends on CSS layout. We recommend users test components in a real browser, and can't guarantee changes to support executing component code in JSDOM.
  • Loading branch information
kitkat119 authored Jan 4, 2024
1 parent 53083f4 commit 33d32a4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions components/o-multi-select/src/js/multi-select-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function createOptionButton(option, index) {
button.setAttribute('aria-label', ` remove ${option.label} `);
button.className = 'o-multi-select__selected-options-button';
button.type = 'button';
button.innerText = option.label;
button.textContent = option.label;
const span = document.createElement('span');
span.classList = 'o-icons-icon o-icons-icon--cross';
button.appendChild(span);
Expand All @@ -134,7 +134,7 @@ export function createOption(idBase, option, index, selected) {
optionEl.id = `${idBase}-${index}`;
optionEl.className = 'o-multi-select-option';
optionEl.setAttribute('aria-selected', selected);
optionEl.innerText = option.label;
optionEl.textContent = option.label;
const tickSpan = document.createElement('span');
tickSpan.className = 'o-multi-select-option-tick';
optionEl.appendChild(tickSpan);
Expand Down
2 changes: 1 addition & 1 deletion components/o-multi-select/src/js/multi-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class MultiSelect {
_getCoreOptions() {
const options = this._coreWrapper.querySelectorAll('option');
this._coreOptions = options;
return [...options].map((option) => ({ label: option.innerText, value: option.value }));
return [...options].map((option) => ({ label: option.textContent, value: option.value }));
}

/**
Expand Down

0 comments on commit 33d32a4

Please sign in to comment.