Skip to content

Commit

Permalink
remove base from icons
Browse files Browse the repository at this point in the history
  • Loading branch information
claviska committed Nov 10, 2022
1 parent ed45f52 commit c6a43ba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions docs/resources/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<sl-radio-group>` (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 `<sl-radio-group>` (use `form-control` and `form-control__label` instead) [#965](https://github.com/shoelace-style/shoelace/issues/965)
- 馃毃 BREAKING: Removed the `base` part from `<sl-icon>` (style the host element instead)
- Added `button--checked` to `<sl-radio-button>` and `control--checked` to `<sl-radio>` to style just the checked state [#933](https://github.com/shoelace-style/shoelace/pull/933)
- Added tests for `<sl-menu-item>` and `<sl-menu-label>` [#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)
Expand Down
1 change: 0 additions & 1 deletion src/components/icon/icon.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default css`
box-sizing: content-box !important;
}
.icon,
svg {
display: block;
height: 100%;
Expand Down
30 changes: 16 additions & 14 deletions src/components/icon/icon.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 {
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -120,17 +132,7 @@ export default class SlIcon extends ShoelaceElement {
}

render() {
const hasLabel = typeof this.label === 'string' && this.label.length > 0;

return html` <div
part="base"
class="icon"
role=${ifDefined(hasLabel ? 'img' : undefined)}
aria-label=${ifDefined(hasLabel ? this.label : undefined)}
aria-hidden=${ifDefined(hasLabel ? undefined : 'true')}
>
${unsafeSVG(this.svg)}
</div>`;
return html` ${unsafeSVG(this.svg)} `;
}
}

Expand Down

0 comments on commit c6a43ba

Please sign in to comment.