Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove html from getTextLabel() #1840

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/pages/resources/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Components with the <sl-badge variant="warning" pill>Experimental</sl-badge> bad

New versions of Shoelace are released as-needed and generally occur when a critical mass of changes have accumulated. At any time, you can see what's coming in the next release by visiting [next.shoelace.style](https://next.shoelace.style).

## Next

- Fixed a bug in `<sl-option>` that caused HTML tags to be included in `getTextLabel()`

## 2.13.1

- Fixed a bug where the safe triangle was always visible when selecting nested `<sl-menu>` elements [#1835]
Expand Down
2 changes: 1 addition & 1 deletion src/components/option/option.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default class SlOption extends ShoelaceElement {
[...nodes].forEach(node => {
if (node.nodeType === Node.ELEMENT_NODE) {
if (!(node as HTMLElement).hasAttribute('slot')) {
label += (node as HTMLElement).outerHTML;
label += (node as HTMLElement).textContent;
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/components/option/option.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ describe('<sl-option>', () => {

expect(el.value).to.equal('10');
});

it('should escape HTML when calling getTextLabel()', async () => {
const el = await fixture<SlOption>(html` <sl-option><strong>Option</strong></sl-option> `);
expect(el.getTextLabel()).to.equal('Option');
});
});
Loading