Skip to content

Commit

Permalink
refactor: update option-type elements to all utilize textContent as t…
Browse files Browse the repository at this point in the history
…heir label
  • Loading branch information
GeekyEggo committed Nov 7, 2024
1 parent 7c37047 commit 9ca8d48
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/ui/components/switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { ifDefined } from "lit/directives/if-defined.js";
import { ref } from "lit/directives/ref.js";

import { Input } from "../mixins/input";
import { Labeled } from "../mixins/labeled";
import { type HTMLInputEvent, preventDoubleClickSelection } from "../utils";

/**
* Element that offers persisting a `boolean` via a toggle switch.
*/
@customElement("sd-switch")
export class SDSwitchElement extends Input<boolean>(LitElement) {
export class SDSwitchElement extends Labeled(Input<boolean>(LitElement)) {
/**
* @inheritdoc
*/
Expand Down Expand Up @@ -149,6 +150,7 @@ export class SDSwitchElement extends Input<boolean>(LitElement) {
return html`
<label
tabindex=${ifDefined(this.disabled ? undefined : 0)}
@mousedown=${preventDoubleClickSelection}
@keydown=${(ev: KeyboardEvent): void => {
// Toggle switch on space bar key.
if (ev.code === "Space") {
Expand All @@ -172,9 +174,7 @@ export class SDSwitchElement extends Input<boolean>(LitElement) {
<div class="thumb"></div>
</div>
${this.textContent &&
html`<span class="text" @mousedown=${preventDoubleClickSelection}>${this.textContent}</span>`}
<slot hidden @slotchange=${(): void => this.requestUpdate()}></slot>
${this.label && html`<span class="text">${this.label}</span>`}
</label>
`;
}
Expand Down

0 comments on commit 9ca8d48

Please sign in to comment.