Zum Hauptinhalt springen Seitenleiste
Zum Inhaltsverzeichnis springen

    Switch

    <pc-switch> 0.1.0 experimental

    Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

    Switches allow the user to toggle an option on or off.

    <pc-switch>Switch</pc-switch>
    Code Edit

    This component works well with standard <form> elements. Please refer to the form controls page to learn more about form submission and client‐side validation.

    Demos#

    Checked#

    Use the checked attribute to set the switch’s state to enabled.

    Edit

    Disabled#

    Use the disabled attribute to disable the switch.

    Edit

    Sizes#

    Use the size attribute to change a switch’s size.

    Edit

    Hint#

    Add a descriptive hint to a switch with the hint attribute. For hints that contain HTML, use the hint slot instead.

    Edit

    Custom styles#

    Use the available custom properties to change how the switch is styled.

    Edit

    Eigenschaften#

    NameBeschreibungReflektiertStandard
    nameThe name of the switch, submitted as a name/value pair with form data.
    Typ: string
    ""
    valueThe current value of the switch, submitted as a name/value pair with form data.
    Typ: string
    sizeThe switch’s size.
    Typ: "small" | "medium" | "large"
    "medium"
    disabledDisables the switch.
    Typ: boolean
    false
    checkedEnables the switch.
    Typ: boolean
    false
    defaultCheckedThe default value of the switch. Primarily used for resetting the switch.
    Typ: boolean
    false
    formBy default, form controls are associated with the nearest containing <form> element. This attribute allows you to place the form control outside of a form and associate it with the form that has this id. The form must be in the same document or shadow root for this to work.
    Typ: string
    ""
    requiredMakes the switch a required field.
    Typ: boolean
    false
    hintThe switch’s hint. if you need to display HTML, use the hint slot instead.
    Typ: string
    ""
    validityGets the validity state object.
    validationMessageGets the validation message.
    updateComplete Ein schreibgeschütztes Promise, das erfüllt ist, sobald die Komponente fertig aktualisiert wurde.

    Erfahre mehr über Attribute und Eigenschaften.

    Slots#

    NameBeschreibung
    (default)The switch’s label.
    hintText that describes how to use the switch. Alternatively, you can use the hint attribute.

    Erfahre mehr über die Benutzung von Slots.

    Methoden#

    NameBeschreibungArgumente
    click()Simulates a click on the switch.
    focus()Focuses the switch.options: FocusOptions
    blur()Unfocuses/blurs the switch.
    checkValidity()Checks for validity but doesn’t show a validation message. Returns true when valid and false when invalid.
    getForm()Gets the associated form if one exists.
    reportValidity()Checks for validity and shows the browser’s validation message if the control is invalid.
    setCustomValidity()Sets a custom validation message. Pass an empty string to restore validity.message: string

    Erfahre mehr über Methoden.

    Events#

    NameBeschreibungEvent‐Detail
    pc-changeEmitted when the switch’s state changes.
    pc-focusEmitted when the switch gains focus.
    pc-blurEmitted when the switch loses focus (i.e., is blurred).
    pc-inputEmitted when the switch receives input.
    pc-invalidEmitted when the form control has been checked for validity and its constraints aren’t satisfied.

    Erfahre mehr über Events.

    Benutzerdefinierte Eigenschaften#

    NameBeschreibungStandard
    --widthThe width of the switch.calc(var(--height) * 1.75)
    --heightThe height of the switch.var(--pc-form-control-toggle-size)
    --thumb-sizeThe size of the thumb.0.75em

    Erfahre mehr über das Anpassen von benutzerdefinierten Eigenschaften.

    Parts#

    NameBeschreibung
    baseThe component’s base wrapper.
    controlThe control that houses the switch’s thumb.
    thumbThe switch’s thumb.
    labelThe switch’s label.
    hintThe hint’s wrapper.

    Erfahre mehr über das Anpassen von CSS‐Parts.

    Importieren#

    Wenn du den Autoloader oder den Standard‐Loader nutzt, kannst du diesen Abschnitt überspringen. Falls du „Cherry Picking“ betreibst, kannst du die folgenden Snippets verwenden, um diese Komponente zu importieren.

    CDN (Skript‐Tag)CDN (Import)npm (Import)

    Um diese Komponente manuell vom CDN zu importieren, kopiere dieses Code‐Snippet und füge es in dein HTML ein.

    <script type="module" src="https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.3/cdn/components/switch/switch.js"></script>

    Um diese Komponente manuell vom CDN zu importieren, kopiere dieses Code‐Snippet und füge es in deine JavaScript‐Datei ein.

    import "https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.3/cdn/components/switch/switch.js";

    Um diese Komponente manuell via npm zu importieren, kopiere dieses Code‐Snippet und füge es in deine JavaScript‐Datei ein.

    import "placer-toolkit/dist/components/switch/switch.js";

    Wir würden uns freuen, von dir zu hören. Bitte kontaktiere uns bei Fragen oder Anliegen, die du hast.

    Du kannst uns per E‐Mail unter placer.coc.reports+contact@gmail.com erreichen.

    Wir freuen uns darauf, von dir zu hören!

    Alles klar!
    Gefährliche Lande

    Ui! Du bist in die gefährlichen Lande von Placer Toolkit geraten. Version 0 ist veraltet und entspricht nicht den EU‐Datenschutzstandards, einschließlich DSGVO.

    Willst du die neuesten Kräfte, Sicherheit und Compliance? Bleib bei der aktuellen Version von Placer Toolkit!

    Ups! Aufladen!