backport shoelace#1927

This commit is contained in:
Cory LaViska
2024-05-07 11:37:41 -04:00
parent 61c7329885
commit 80ce2088a0
3 changed files with 19 additions and 1 deletions

View File

@@ -26,6 +26,8 @@ New versions of Web Awesome are released as-needed and generally occur when a cr
- Added support for `contextElement` to `VirtualElements` in `<sl-popup>` [#1874]
- Added the `sync` property to `<wa-dropdown>` [#1935]
- Fixed a bug in `<sl-icon>` that did not properly apply mutators to spritesheets [#1927]
- Fixed a bug in `.sl-scroll-lock` causing layout shifts [#1895]
- Fixed a bug in `.sl-scroll-lock` causing layout shifts. [#1895]
- Fixed a bug in `<sl-rating>` that caused the rating to not reset in some circumstances [#1877]
- Fixed a bug in `<sl-select>` that caused the menu to not close when rendered in a shadow root [#1878]

View File

@@ -205,6 +205,10 @@ describe('<wa-icon>', () => {
const rect = use?.getBoundingClientRect();
expect(rect?.width).to.equal(0);
expect(rect?.width).to.equal(0);
// Make sure the mutator is applied.
// https://github.com/shoelace-style/shoelace/issues/1925
expect(svg?.getAttribute('fill')).to.equal('currentColor');
});
// TODO: <use> svg icons don't emit a "load" or "error" event...if we can figure out how to get the event to emit errors.

View File

@@ -44,9 +44,21 @@ export default class WaIcon extends WebAwesomeElement {
let fileData: Response;
if (library?.spriteSheet) {
return html`<svg part="svg">
this.svg = html`<svg part="svg">
<use part="use" href="${url}"></use>
</svg>`;
// Using a templateResult requires the SVG to be written to the DOM first before we can grab the SVGElement
// to be passed to the library's mutator function.
await this.updateComplete;
const svg = this.shadowRoot!.querySelector("[part='svg']")!;
if (typeof library.mutator === 'function') {
library.mutator(svg as SVGElement);
}
return this.svg;
}
try {