diff --git a/docs/resources/changelog.md b/docs/resources/changelog.md index 3e9e9a4ec..f61dbcfe7 100644 --- a/docs/resources/changelog.md +++ b/docs/resources/changelog.md @@ -12,6 +12,7 @@ _During the beta period, these restrictions may be relaxed in the event of a mis - 🚨 BREAKING: Removed the `fieldset` property from `` (use CSS parts if you want to keep the border) [#965](https://github.com/shoelace-style/shoelace/issues/965) - 🚨 BREAKING: Removed `base` and `label` parts from `` (use `form-control` and `form-control__label` instead) [#965](https://github.com/shoelace-style/shoelace/issues/965) +- 🚨 BREAKING: Removed the `base` part from `` (style the host element instead) - Added `button--checked` to `` and `control--checked` to `` to style just the checked state [#933](https://github.com/shoelace-style/shoelace/pull/933) - Added tests for `` and `` [#935](https://github.com/shoelace-style/shoelace/pull/935) - Added translations for Turkish, English (United Kingdom) and German (Austria) [#989](https://github.com/shoelace-style/shoelace/pull/989) diff --git a/src/components/icon/icon.styles.ts b/src/components/icon/icon.styles.ts index eea476906..d6eea2a2b 100644 --- a/src/components/icon/icon.styles.ts +++ b/src/components/icon/icon.styles.ts @@ -12,7 +12,6 @@ export default css` box-sizing: content-box !important; } - .icon, svg { display: block; height: 100%; diff --git a/src/components/icon/icon.ts b/src/components/icon/icon.ts index 4e36f39fc..de4739a27 100644 --- a/src/components/icon/icon.ts +++ b/src/components/icon/icon.ts @@ -1,6 +1,5 @@ import { html } from 'lit'; import { customElement, property, state } from 'lit/decorators.js'; -import { ifDefined } from 'lit/directives/if-defined.js'; import { unsafeSVG } from 'lit/directives/unsafe-svg.js'; import ShoelaceElement from '../../internal/shoelace-element'; import { watch } from '../../internal/watch'; @@ -19,8 +18,6 @@ let parser: DOMParser; * * @event sl-load - Emitted when the icon has loaded. * @event sl-error - Emitted when the icon fails to load due to an error. - * - * @csspart base - The component's internal wrapper. */ @customElement('sl-icon') export default class SlIcon extends ShoelaceElement { @@ -71,6 +68,21 @@ export default class SlIcon extends ShoelaceElement { this.setIcon(); } + @watch('label') + handleLabelChange() { + const hasLabel = typeof this.label === 'string' && this.label.length > 0; + + if (hasLabel) { + this.setAttribute('role', 'img'); + this.setAttribute('aria-label', this.label); + this.removeAttribute('aria-hidden'); + } else { + this.removeAttribute('role'); + this.removeAttribute('aria-label'); + this.setAttribute('aria-hidden', 'true'); + } + } + @watch('name') @watch('src') @watch('library') @@ -120,17 +132,7 @@ export default class SlIcon extends ShoelaceElement { } render() { - const hasLabel = typeof this.label === 'string' && this.label.length > 0; - - return html`
- ${unsafeSVG(this.svg)} -
`; + return html` ${unsafeSVG(this.svg)} `; } }