Lewati ke konten
MarkasUI
Ketik untuk mencari

    Panduan

    MarkasUI

    Form

    Feedback

    Overlay

    Navigasi

    Data

    Section

    Animasi

    Latar

    Tombol

    Template

    Halaman

    Checkbox

    Kotak centang native dengan label dan deskripsi opsional, tampilan kustom tanpa JavaScript.

    You agree to our terms of service.

    You agree to our terms of service.

    You agree to our terms of service.

    At most one email per month.

    At most one email per month.

    Checkbox

    <x-markas.checkbox label="Accept terms and conditions" description="You agree to our terms of service." />
    import { Checkbox } from "@/components/markas/Checkbox";
    
    <Checkbox label="Accept terms and conditions" description="You agree to our terms of service." />
    import Checkbox from "@/components/markas/Checkbox.vue";
    
    <Checkbox label="Accept terms and conditions" description="You agree to our terms of service." />
    <script lang="ts">
      import Checkbox from "$lib/components/markas/Checkbox.svelte";
    </script>
    
    <div class="grid gap-4">
      <Checkbox name="terms" label="I agree to the terms of service" checked />
      <Checkbox
        name="updates"
        label="Send me product updates"
        description="At most one email per month."
      />
      <Checkbox name="archive" label="Archive automatically" disabled />
    </div>
    ---
    import Checkbox from "@/components/markas/Checkbox.astro";
    ---
    
    <div class="grid gap-4">
      <Checkbox name="terms" label="I agree to the terms of service" checked />
      <Checkbox
        name="updates"
        label="Send me product updates"
        description="At most one email per month."
      />
      <Checkbox name="archive" label="Archive automatically" disabled />
    </div>
    import { Component } from "@angular/core";
    import { Checkbox } from "./markas/checkbox.component";
    
    @Component({
      selector: "markas-example",
      imports: [Checkbox],
      template: `
        <div class="grid gap-4">
          <markas-checkbox
            name="terms"
            label="I agree to the terms of service"
            checked
          />
          <markas-checkbox
            name="updates"
            label="Send me product updates"
            description="At most one email per month."
          />
          <markas-checkbox name="archive" label="Archive automatically" disabled />
        </div>
      `,
    })
    export default class CheckboxExample {}

    Contoh

    Daftar dengan deskripsi

    Email me when

    Replies to your posts and threads you follow.

    Any message that includes your username.

    Includes invitations from outside your workspace.

    Email me when

    Replies to your posts and threads you follow.

    Any message that includes your username.

    Includes invitations from outside your workspace.

    Email me when

    Replies to your posts and threads you follow.

    Any message that includes your username.

    Includes invitations from outside your workspace.

    Email me when

    Replies to your posts and threads you follow.

    Any message that includes your username.

    Includes invitations from outside your workspace.

    Email me when

    Replies to your posts and threads you follow.

    Any message that includes your username.

    Includes invitations from outside your workspace.

    Kartu

    Add-ons

    Keep 30 days of snapshots. $5 per month.

    Replies within 4 hours on business days. $20 per month.

    Serve your site from your own domain. Free.

    Add-ons

    Keep 30 days of snapshots. $5 per month.

    Replies within 4 hours on business days. $20 per month.

    Serve your site from your own domain. Free.

    Add-ons

    Keep 30 days of snapshots. $5 per month.

    Replies within 4 hours on business days. $20 per month.

    Serve your site from your own domain. Free.

    Add-ons

    Keep 30 days of snapshots. $5 per month.

    Replies within 4 hours on business days. $20 per month.

    Serve your site from your own domain. Free.

    Add-ons

    Keep 30 days of snapshots. $5 per month.

    Replies within 4 hours on business days. $20 per month.

    Serve your site from your own domain. Free.

    Status

    Editor defaults are managed by your organization.

    Editor defaults are managed by your organization.

    Editor defaults are managed by your organization.

    Editor defaults are managed by your organization.

    Editor defaults are managed by your organization.

    Horizontal

    Notify me by
    Notify me by
    Notify me by
    Notify me by
    Notify me by

    Instalasi

    npx markasui@latest add checkbox

    Pemakaian

    <x-markas.checkbox name="syarat" label="Saya setuju dengan syarat layanan" required />
    <x-markas.checkbox name="kabar" label="Kirimi saya kabar terbaru" description="Paling banyak satu email per bulan." :checked="old('kabar')" />
    import { Checkbox } from "@/components/markas/Checkbox";
    
    <Checkbox name="syarat" label="Saya setuju dengan syarat layanan" required />
    <Checkbox
      name="kabar"
      label="Kirimi saya kabar terbaru"
      description="Paling banyak satu email per bulan."
      defaultChecked
    />
    <script setup lang="ts">
    import { ref } from "vue";
    import Checkbox from "@/components/markas/Checkbox.vue";
    
    const kabar = ref(false);
    </script>
    
    <template>
      <Checkbox
        v-model="kabar"
        name="kabar"
        label="Kirimi saya kabar terbaru"
        description="Paling banyak satu email per bulan."
      />
    </template>
    <script lang="ts">
      import Checkbox from "$lib/components/markas/Checkbox.svelte";
    
      let updates = $state(false);
    </script>
    
    <Checkbox
      bind:checked={updates}
      name="updates"
      label="Kirimi saya kabar produk"
      description="Paling banyak satu email per bulan."
    />
    ---
    import Checkbox from "@/components/markas/Checkbox.astro";
    ---
    
    <Checkbox name="terms" label="Saya setuju dengan ketentuan layanan" required />
    <Checkbox name="updates" label="Kirimi saya kabar produk" description="Paling banyak satu email per bulan." checked />

    Tanpa script klien: checkbox-nya input native.

    import { Component, signal } from "@angular/core";
    import { Checkbox } from "./markas/checkbox.component";
    
    @Component({
      selector: "app-preferences",
      imports: [Checkbox],
      template: `
        <markas-checkbox
          [(checked)]="updates"
          name="updates"
          label="Kirimi saya kabar produk"
          description="Paling banyak satu email per bulan."
        />
      `,
    })
    export class Preferences {
      readonly updates = signal(false);
    }
    • Atribut tambahan (name, value, required, class) diteruskan ke elemen <input>.
    • Tampilan tercentang memakai CSS :checked (varian checked: dan peer-checked:), bukan data-state, sehingga tetap benar tanpa JavaScript.
    • Komponen ini tidak punya teks bawaan. Cukup isi label dan description dalam Bahasa Indonesia.

    Props

    NamaTipeDefaultKeterangan
    labelstring-Teks label di samping kotak, terhubung lewat for/id.
    descriptionstring-Teks penjelas di bawah label, dihubungkan lewat aria-describedby.
    checked / defaultChecked / v-model / bind:checkedbooleanfalseStatus centang. Blade dan Astro memakai atribut checked, React checked atau defaultChecked, Vue v-model, Svelte bind:checked, Angular checked atau [(checked)].
    disabledbooleanfalseMenonaktifkan checkbox dan meredupkan label.
    idstringautoId input. Dibuat otomatis kalau kosong.
    checkedChangeoutput<boolean>-Khusus Angular. Memancarkan status baru setiap kali checkbox berubah.

    Aksesibilitas

    • Memakai input type checkbox native, jadi Spasi mencentang dan status dibacakan screen reader.
    • Label terhubung lewat for dan id sehingga mengklik label ikut mencentang.
    • Ikon centang hanya dekorasi (aria-hidden), status visual mengikuti :checked.

    Komponen terkait

    Komponen form lain dengan class yang sama di setiap framework.