Pilihan dropdown memakai select native yang di-styling, lengkap dengan label, petunjuk, dan pesan error.
Choose your city.
Role is required.
Choose your city.
Role is required.
Choose your city.
Role is required.
Choose your city.
Role is required.
Choose your city.
Role is required.
<div class="grid gap-4">
<x-markas.select name="city" label="City" hint="Choose your city.">
<option value="jakarta">Jakarta</option>
<option value="bandung" selected>Bandung</option>
<option value="surabaya">Surabaya</option>
</x-markas.select>
<x-markas.select name="role" label="Role" error="Role is required.">
<option value="">Choose a role</option>
<option value="admin">Admin</option>
<option value="editor">Editor</option>
</x-markas.select>
<x-markas.select name="plan" label="Plan" disabled>
<option value="free">Free</option>
</x-markas.select>
</div>import { Select } from "@/components/markas/Select";
export default function SelectExample() {
return (
<div className="grid gap-4">
<Select
name="city"
label="City"
hint="Choose your city."
defaultValue="bandung"
>
<option value="jakarta">Jakarta</option>
<option value="bandung">Bandung</option>
<option value="surabaya">Surabaya</option>
</Select>
<Select name="role" label="Role" error="Role is required.">
<option value="">Choose a role</option>
<option value="admin">Admin</option>
<option value="editor">Editor</option>
</Select>
<Select name="plan" label="Plan" disabled>
<option value="free">Free</option>
</Select>
</div>
);
}<script setup lang="ts">
import { ref } from "vue";
import Select from "@/components/markas/Select.vue";
const city = ref("bandung");
const role = ref("");
const plan = ref("free");
</script>
<template>
<div class="grid gap-4">
<Select v-model="city" name="city" label="City" hint="Choose your city.">
<option value="jakarta">Jakarta</option>
<option value="bandung">Bandung</option>
<option value="surabaya">Surabaya</option>
</Select>
<Select v-model="role" name="role" label="Role" error="Role is required.">
<option value="">Choose a role</option>
<option value="admin">Admin</option>
<option value="editor">Editor</option>
</Select>
<Select v-model="plan" name="plan" label="Plan" disabled>
<option value="free">Free</option>
</Select>
</div>
</template><script lang="ts">
import Select from "$lib/components/markas/Select.svelte";
let city = $state("bandung");
let role = $state("");
let plan = $state("free");
</script>
<div class="grid gap-4">
<Select bind:value={city} name="city" label="City" hint="Choose your city.">
<option value="jakarta">Jakarta</option>
<option value="bandung">Bandung</option>
<option value="surabaya">Surabaya</option>
</Select>
<Select bind:value={role} name="role" label="Role" error="Role is required.">
<option value="">Choose a role</option>
<option value="admin">Admin</option>
<option value="editor">Editor</option>
</Select>
<Select bind:value={plan} name="plan" label="Plan" disabled>
<option value="free">Free</option>
</Select>
</div>---
import Select from "@/components/markas/Select.astro";
---
<div class="grid gap-4">
<Select name="city" label="City" hint="Choose your city.">
<option value="jakarta">Jakarta</option>
<option value="bandung" selected>Bandung</option>
<option value="surabaya">Surabaya</option>
</Select>
<Select name="role" label="Role" error="Role is required.">
<option value="">Choose a role</option>
<option value="admin">Admin</option>
<option value="editor">Editor</option>
</Select>
<Select name="plan" label="Plan" disabled>
<option value="free">Free</option>
</Select>
</div>import { Component, signal } from "@angular/core";
import { Select } from "./markas/select.component";
@Component({
selector: "markas-example",
imports: [Select],
template: `
<div class="grid gap-4">
<markas-select
[(value)]="city"
name="city"
label="City"
hint="Choose your city."
>
<option value="jakarta">Jakarta</option>
<option value="bandung">Bandung</option>
<option value="surabaya">Surabaya</option>
</markas-select>
<markas-select
[(value)]="role"
name="role"
label="Role"
error="Role is required."
>
<option value="">Choose a role</option>
<option value="admin">Admin</option>
<option value="editor">Editor</option>
</markas-select>
<markas-select [(value)]="plan" name="plan" label="Plan" disabled>
<option value="free">Free</option>
</markas-select>
</div>
`,
})
export default class SelectExample {
readonly city = signal("bandung");
readonly role = signal("");
readonly plan = signal("free");
}Contoh
Placeholder
Used to calculate tax on your invoices.
Choose the industry that fits best.
Used to calculate tax on your invoices.
Choose the industry that fits best.
Used to calculate tax on your invoices.
Choose the industry that fits best.
Used to calculate tax on your invoices.
Choose the industry that fits best.
Used to calculate tax on your invoices.
Choose the industry that fits best.
<div class="grid gap-4">
<x-markas.select name="country" label="Country" hint="Used to calculate tax on your invoices.">
<option value="" disabled selected>Select a country</option>
<option value="id">Indonesia</option>
<option value="my">Malaysia</option>
<option value="sg">Singapore</option>
</x-markas.select>
<x-markas.select name="industry" label="Industry" error="Choose the industry that fits best.">
<option value="" disabled selected>Select an industry</option>
<option value="education">Education</option>
<option value="finance">Finance</option>
<option value="retail">Retail</option>
</x-markas.select>
</div>import { Select } from "@/components/markas/Select";
export default function Example() {
return (
<div className="grid gap-4">
<Select
name="country"
label="Country"
hint="Used to calculate tax on your invoices."
defaultValue=""
>
<option value="" disabled>
Select a country
</option>
<option value="id">Indonesia</option>
<option value="my">Malaysia</option>
<option value="sg">Singapore</option>
</Select>
<Select
name="industry"
label="Industry"
error="Choose the industry that fits best."
defaultValue=""
>
<option value="" disabled>
Select an industry
</option>
<option value="education">Education</option>
<option value="finance">Finance</option>
<option value="retail">Retail</option>
</Select>
</div>
);
}<script setup lang="ts">
import { ref } from "vue";
import Select from "@/components/markas/Select.vue";
const country = ref("");
const industry = ref("");
</script>
<template>
<div class="grid gap-4">
<Select
v-model="country"
name="country"
label="Country"
hint="Used to calculate tax on your invoices."
>
<option value="" disabled>Select a country</option>
<option value="id">Indonesia</option>
<option value="my">Malaysia</option>
<option value="sg">Singapore</option>
</Select>
<Select
v-model="industry"
name="industry"
label="Industry"
error="Choose the industry that fits best."
>
<option value="" disabled>Select an industry</option>
<option value="education">Education</option>
<option value="finance">Finance</option>
<option value="retail">Retail</option>
</Select>
</div>
</template><script lang="ts">
import Select from "$lib/components/markas/Select.svelte";
let country = $state("");
let industry = $state("");
</script>
<div class="grid gap-4">
<Select
bind:value={country}
name="country"
label="Country"
hint="Used to calculate tax on your invoices."
>
<option value="" disabled>Select a country</option>
<option value="id">Indonesia</option>
<option value="my">Malaysia</option>
<option value="sg">Singapore</option>
</Select>
<Select
bind:value={industry}
name="industry"
label="Industry"
error="Choose the industry that fits best."
>
<option value="" disabled>Select an industry</option>
<option value="education">Education</option>
<option value="finance">Finance</option>
<option value="retail">Retail</option>
</Select>
</div>---
import Select from "@/components/markas/Select.astro";
---
<div class="grid gap-4">
<Select
name="country"
label="Country"
hint="Used to calculate tax on your invoices."
>
<option value="" disabled selected>Select a country</option>
<option value="id">Indonesia</option>
<option value="my">Malaysia</option>
<option value="sg">Singapore</option>
</Select>
<Select
name="industry"
label="Industry"
error="Choose the industry that fits best."
>
<option value="" disabled selected>Select an industry</option>
<option value="education">Education</option>
<option value="finance">Finance</option>
<option value="retail">Retail</option>
</Select>
</div>import { Component, signal } from "@angular/core";
import { Select } from "./markas/select.component";
@Component({
selector: "markas-example",
imports: [Select],
template: `
<div class="grid gap-4">
<markas-select
[(value)]="country"
name="country"
label="Country"
hint="Used to calculate tax on your invoices."
>
<option value="" disabled>Select a country</option>
<option value="id">Indonesia</option>
<option value="my">Malaysia</option>
<option value="sg">Singapore</option>
</markas-select>
<markas-select
[(value)]="industry"
name="industry"
label="Industry"
error="Choose the industry that fits best."
>
<option value="" disabled>Select an industry</option>
<option value="education">Education</option>
<option value="finance">Finance</option>
<option value="retail">Retail</option>
</markas-select>
</div>
`,
})
export default class SelectPlaceholderExample {
readonly country = signal("");
readonly industry = signal("");
}Grup opsi
Meeting times are shown in this time zone.
Meeting times are shown in this time zone.
Meeting times are shown in this time zone.
Meeting times are shown in this time zone.
Meeting times are shown in this time zone.
<x-markas.select name="timezone" label="Time zone" hint="Meeting times are shown in this time zone.">
<optgroup label="Asia">
<option value="asia-jakarta" selected>Jakarta (GMT+7)</option>
<option value="asia-singapore">Singapore (GMT+8)</option>
<option value="asia-tokyo">Tokyo (GMT+9)</option>
</optgroup>
<optgroup label="Europe">
<option value="europe-london">London (GMT+0)</option>
<option value="europe-berlin">Berlin (GMT+1)</option>
</optgroup>
<optgroup label="Americas">
<option value="america-new-york">New York (GMT-5)</option>
<option value="america-los-angeles">Los Angeles (GMT-8)</option>
</optgroup>
</x-markas.select>import { Select } from "@/components/markas/Select";
export default function Example() {
return (
<Select
name="timezone"
label="Time zone"
hint="Meeting times are shown in this time zone."
defaultValue="asia-jakarta"
>
<optgroup label="Asia">
<option value="asia-jakarta">Jakarta (GMT+7)</option>
<option value="asia-singapore">Singapore (GMT+8)</option>
<option value="asia-tokyo">Tokyo (GMT+9)</option>
</optgroup>
<optgroup label="Europe">
<option value="europe-london">London (GMT+0)</option>
<option value="europe-berlin">Berlin (GMT+1)</option>
</optgroup>
<optgroup label="Americas">
<option value="america-new-york">New York (GMT-5)</option>
<option value="america-los-angeles">Los Angeles (GMT-8)</option>
</optgroup>
</Select>
);
}<script setup lang="ts">
import { ref } from "vue";
import Select from "@/components/markas/Select.vue";
const timezone = ref("asia-jakarta");
</script>
<template>
<Select
v-model="timezone"
name="timezone"
label="Time zone"
hint="Meeting times are shown in this time zone."
>
<optgroup label="Asia">
<option value="asia-jakarta">Jakarta (GMT+7)</option>
<option value="asia-singapore">Singapore (GMT+8)</option>
<option value="asia-tokyo">Tokyo (GMT+9)</option>
</optgroup>
<optgroup label="Europe">
<option value="europe-london">London (GMT+0)</option>
<option value="europe-berlin">Berlin (GMT+1)</option>
</optgroup>
<optgroup label="Americas">
<option value="america-new-york">New York (GMT-5)</option>
<option value="america-los-angeles">Los Angeles (GMT-8)</option>
</optgroup>
</Select>
</template><script lang="ts">
import Select from "$lib/components/markas/Select.svelte";
let timezone = $state("asia-jakarta");
</script>
<Select
bind:value={timezone}
name="timezone"
label="Time zone"
hint="Meeting times are shown in this time zone."
>
<optgroup label="Asia">
<option value="asia-jakarta">Jakarta (GMT+7)</option>
<option value="asia-singapore">Singapore (GMT+8)</option>
<option value="asia-tokyo">Tokyo (GMT+9)</option>
</optgroup>
<optgroup label="Europe">
<option value="europe-london">London (GMT+0)</option>
<option value="europe-berlin">Berlin (GMT+1)</option>
</optgroup>
<optgroup label="Americas">
<option value="america-new-york">New York (GMT-5)</option>
<option value="america-los-angeles">Los Angeles (GMT-8)</option>
</optgroup>
</Select>---
import Select from "@/components/markas/Select.astro";
---
<Select
name="timezone"
label="Time zone"
hint="Meeting times are shown in this time zone."
>
<optgroup label="Asia">
<option value="asia-jakarta" selected>Jakarta (GMT+7)</option>
<option value="asia-singapore">Singapore (GMT+8)</option>
<option value="asia-tokyo">Tokyo (GMT+9)</option>
</optgroup>
<optgroup label="Europe">
<option value="europe-london">London (GMT+0)</option>
<option value="europe-berlin">Berlin (GMT+1)</option>
</optgroup>
<optgroup label="Americas">
<option value="america-new-york">New York (GMT-5)</option>
<option value="america-los-angeles">Los Angeles (GMT-8)</option>
</optgroup>
</Select>import { Component, signal } from "@angular/core";
import { Select } from "./markas/select.component";
@Component({
selector: "markas-example",
imports: [Select],
template: `
<markas-select
[(value)]="timezone"
name="timezone"
label="Time zone"
hint="Meeting times are shown in this time zone."
>
<optgroup label="Asia">
<option value="asia-jakarta">Jakarta (GMT+7)</option>
<option value="asia-singapore">Singapore (GMT+8)</option>
<option value="asia-tokyo">Tokyo (GMT+9)</option>
</optgroup>
<optgroup label="Europe">
<option value="europe-london">London (GMT+0)</option>
<option value="europe-berlin">Berlin (GMT+1)</option>
</optgroup>
<optgroup label="Americas">
<option value="america-new-york">New York (GMT-5)</option>
<option value="america-los-angeles">Los Angeles (GMT-8)</option>
</optgroup>
</markas-select>
`,
})
export default class SelectGroupsExample {
readonly timezone = signal("asia-jakarta");
}Dengan ikon
<div class="grid gap-4">
<div class="relative">
<x-markas.select name="language" label="Language" class="pl-9!">
<option value="en" selected>English</option>
<option value="id">Bahasa Indonesia</option>
<option value="ja">Japanese</option>
</x-markas.select>
<svg class="pointer-events-none absolute bottom-3 left-3 size-4 text-muted" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9" /><path d="M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18" /></svg>
</div>
<div class="relative">
<x-markas.select name="currency" label="Currency" class="pl-9!">
<option value="idr">IDR, Indonesian rupiah</option>
<option value="usd" selected>USD, US dollar</option>
<option value="eur">EUR, Euro</option>
</x-markas.select>
<svg class="pointer-events-none absolute bottom-3 left-3 size-4 text-muted" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="6" width="18" height="12" rx="2" /><circle cx="12" cy="12" r="2.5" /></svg>
</div>
</div>import { Select } from "@/components/markas/Select";
const icon = "pointer-events-none absolute bottom-3 left-3 size-4 text-muted";
export default function Example() {
return (
<div className="grid gap-4">
<div className="relative">
<Select
name="language"
label="Language"
defaultValue="en"
className="pl-9!"
>
<option value="en">English</option>
<option value="id">Bahasa Indonesia</option>
<option value="ja">Japanese</option>
</Select>
<svg
className={icon}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
>
<circle cx="12" cy="12" r="9" />
<path d="M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18" />
</svg>
</div>
<div className="relative">
<Select
name="currency"
label="Currency"
defaultValue="usd"
className="pl-9!"
>
<option value="idr">IDR, Indonesian rupiah</option>
<option value="usd">USD, US dollar</option>
<option value="eur">EUR, Euro</option>
</Select>
<svg
className={icon}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
>
<rect x="3" y="6" width="18" height="12" rx="2" />
<circle cx="12" cy="12" r="2.5" />
</svg>
</div>
</div>
);
}<script setup lang="ts">
import { ref } from "vue";
import Select from "@/components/markas/Select.vue";
const icon = "pointer-events-none absolute bottom-3 left-3 size-4 text-muted";
const language = ref("en");
const currency = ref("usd");
</script>
<template>
<div class="grid gap-4">
<div class="relative">
<Select v-model="language" name="language" label="Language" class="pl-9!">
<option value="en">English</option>
<option value="id">Bahasa Indonesia</option>
<option value="ja">Japanese</option>
</Select>
<svg
:class="icon"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<circle cx="12" cy="12" r="9" />
<path d="M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18" />
</svg>
</div>
<div class="relative">
<Select v-model="currency" name="currency" label="Currency" class="pl-9!">
<option value="idr">IDR, Indonesian rupiah</option>
<option value="usd">USD, US dollar</option>
<option value="eur">EUR, Euro</option>
</Select>
<svg
:class="icon"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<rect x="3" y="6" width="18" height="12" rx="2" />
<circle cx="12" cy="12" r="2.5" />
</svg>
</div>
</div>
</template><script lang="ts">
import Select from "$lib/components/markas/Select.svelte";
const icon = "pointer-events-none absolute bottom-3 left-3 size-4 text-muted";
let language = $state("en");
let currency = $state("usd");
</script>
<div class="grid gap-4">
<div class="relative">
<Select
bind:value={language}
name="language"
label="Language"
class="pl-9!"
>
<option value="en">English</option>
<option value="id">Bahasa Indonesia</option>
<option value="ja">Japanese</option>
</Select>
<svg
class={icon}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<circle cx="12" cy="12" r="9" />
<path d="M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18" />
</svg>
</div>
<div class="relative">
<Select
bind:value={currency}
name="currency"
label="Currency"
class="pl-9!"
>
<option value="idr">IDR, Indonesian rupiah</option>
<option value="usd">USD, US dollar</option>
<option value="eur">EUR, Euro</option>
</Select>
<svg
class={icon}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<rect x="3" y="6" width="18" height="12" rx="2" />
<circle cx="12" cy="12" r="2.5" />
</svg>
</div>
</div>---
import Select from "@/components/markas/Select.astro";
const icon = "pointer-events-none absolute bottom-3 left-3 size-4 text-muted";
---
<div class="grid gap-4">
<div class="relative">
<Select name="language" label="Language" class="pl-9!">
<option value="en" selected>English</option>
<option value="id">Bahasa Indonesia</option>
<option value="ja">Japanese</option>
</Select>
<svg
class={icon}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<circle cx="12" cy="12" r="9"></circle>
<path d="M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18"></path>
</svg>
</div>
<div class="relative">
<Select name="currency" label="Currency" class="pl-9!">
<option value="idr">IDR, Indonesian rupiah</option>
<option value="usd" selected>USD, US dollar</option>
<option value="eur">EUR, Euro</option>
</Select>
<svg
class={icon}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<rect x="3" y="6" width="18" height="12" rx="2"></rect>
<circle cx="12" cy="12" r="2.5"></circle>
</svg>
</div>
</div>import { Component, signal } from "@angular/core";
import { Select } from "./markas/select.component";
@Component({
selector: "markas-example",
imports: [Select],
template: `
<div class="grid gap-4">
<div class="relative">
<markas-select
[(value)]="language"
name="language"
label="Language"
class="pl-9!"
>
<option value="en">English</option>
<option value="id">Bahasa Indonesia</option>
<option value="ja">Japanese</option>
</markas-select>
<svg
[class]="icon"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<circle cx="12" cy="12" r="9" />
<path d="M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18" />
</svg>
</div>
<div class="relative">
<markas-select
[(value)]="currency"
name="currency"
label="Currency"
class="pl-9!"
>
<option value="idr">IDR, Indonesian rupiah</option>
<option value="usd">USD, US dollar</option>
<option value="eur">EUR, Euro</option>
</markas-select>
<svg
[class]="icon"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<rect x="3" y="6" width="18" height="12" rx="2" />
<circle cx="12" cy="12" r="2.5" />
</svg>
</div>
</div>
`,
})
export default class SelectIconExample {
protected readonly icon =
"pointer-events-none absolute bottom-3 left-3 size-4 text-muted";
readonly language = signal("en");
readonly currency = signal("usd");
}Berdampingan
<fieldset class="min-w-0">
<legend class="mb-1.5 text-sm font-medium text-ink">Date of birth</legend>
<div class="grid grid-cols-[1fr_2fr_1fr] gap-3">
<x-markas.select name="birth_day" aria-label="Day">
<option value="14">14</option>
<option value="15" selected>15</option>
<option value="16">16</option>
</x-markas.select>
<x-markas.select name="birth_month" aria-label="Month">
<option value="2">February</option>
<option value="3" selected>March</option>
<option value="4">April</option>
</x-markas.select>
<x-markas.select name="birth_year" aria-label="Year">
<option value="1994">1994</option>
<option value="1995" selected>1995</option>
<option value="1996">1996</option>
</x-markas.select>
</div>
</fieldset>import { Select } from "@/components/markas/Select";
export default function Example() {
return (
<fieldset className="min-w-0">
<legend className="mb-1.5 text-sm font-medium text-ink">
Date of birth
</legend>
<div className="grid grid-cols-[1fr_2fr_1fr] gap-3">
<Select name="birth_day" aria-label="Day" defaultValue="15">
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
</Select>
<Select name="birth_month" aria-label="Month" defaultValue="3">
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
</Select>
<Select name="birth_year" aria-label="Year" defaultValue="1995">
<option value="1994">1994</option>
<option value="1995">1995</option>
<option value="1996">1996</option>
</Select>
</div>
</fieldset>
);
}<script setup lang="ts">
import { ref } from "vue";
import Select from "@/components/markas/Select.vue";
const day = ref("15");
const month = ref("3");
const year = ref("1995");
</script>
<template>
<fieldset class="min-w-0">
<legend class="mb-1.5 text-sm font-medium text-ink">Date of birth</legend>
<div class="grid grid-cols-[1fr_2fr_1fr] gap-3">
<Select v-model="day" name="birth_day" aria-label="Day">
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
</Select>
<Select v-model="month" name="birth_month" aria-label="Month">
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
</Select>
<Select v-model="year" name="birth_year" aria-label="Year">
<option value="1994">1994</option>
<option value="1995">1995</option>
<option value="1996">1996</option>
</Select>
</div>
</fieldset>
</template><script lang="ts">
import Select from "$lib/components/markas/Select.svelte";
let day = $state("15");
let month = $state("3");
let year = $state("1995");
</script>
<fieldset class="min-w-0">
<legend class="mb-1.5 text-sm font-medium text-ink">Date of birth</legend>
<div class="grid grid-cols-[1fr_2fr_1fr] gap-3">
<Select bind:value={day} name="birth_day" aria-label="Day">
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
</Select>
<Select bind:value={month} name="birth_month" aria-label="Month">
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
</Select>
<Select bind:value={year} name="birth_year" aria-label="Year">
<option value="1994">1994</option>
<option value="1995">1995</option>
<option value="1996">1996</option>
</Select>
</div>
</fieldset>---
import Select from "@/components/markas/Select.astro";
---
<fieldset class="min-w-0">
<legend class="mb-1.5 text-sm font-medium text-ink">Date of birth</legend>
<div class="grid grid-cols-[1fr_2fr_1fr] gap-3">
<Select name="birth_day" aria-label="Day">
<option value="14">14</option>
<option value="15" selected>15</option>
<option value="16">16</option>
</Select>
<Select name="birth_month" aria-label="Month">
<option value="2">February</option>
<option value="3" selected>March</option>
<option value="4">April</option>
</Select>
<Select name="birth_year" aria-label="Year">
<option value="1994">1994</option>
<option value="1995" selected>1995</option>
<option value="1996">1996</option>
</Select>
</div>
</fieldset>import { Component, signal } from "@angular/core";
import { Select } from "./markas/select.component";
@Component({
selector: "markas-example",
imports: [Select],
template: `
<fieldset class="min-w-0">
<legend class="mb-1.5 text-sm font-medium text-ink">Date of birth</legend>
<div class="grid grid-cols-[1fr_2fr_1fr] gap-3">
<markas-select [(value)]="day" name="birth_day" aria-label="Day">
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
</markas-select>
<markas-select [(value)]="month" name="birth_month" aria-label="Month">
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
</markas-select>
<markas-select [(value)]="year" name="birth_year" aria-label="Year">
<option value="1994">1994</option>
<option value="1995">1995</option>
<option value="1996">1996</option>
</markas-select>
</div>
</fieldset>
`,
})
export default class SelectInlineExample {
readonly day = signal("15");
readonly month = signal("3");
readonly year = signal("1995");
}Instalasi
npx markasui@latest add selectpnpm dlx markasui@latest add selectyarn dlx markasui@latest add selectbunx --bun markasui@latest add select- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
resources/views/components/markas/select.blade.php.
@props([
'label' => null,
'hint' => null,
'error' => null,
])
@php
$wrapper = 'grid gap-1.5';
$labelClass = 'text-sm font-medium text-ink';
$control = 'relative';
$field = 'h-10 w-full cursor-pointer appearance-none rounded-md border border-line bg-surface pr-9 pl-3 text-sm text-ink transition-colors duration-150 ease-out focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-danger motion-reduce:transition-none';
$icon = 'pointer-events-none absolute top-1/2 right-3 size-4 -translate-y-1/2 text-muted';
$hintClass = 'text-sm text-muted';
$errorClass = 'text-sm text-danger';
// Same id on every render, so Livewire's morph (which matches elements by id) keeps the element. Pass `id` to set it.
$idKey = 'markas-select|'.(isset($this) && $this instanceof \Livewire\Component ? $this->getId() : '').'|'.($attributes->get('wire:key') ?? $attributes->whereStartsWith('wire:model')->first() ?? $attributes->get('name')).'|';
for ($idIndex = 0; $__env->hasRenderedOnce($idKey.$idIndex); $idIndex++);
$__env->markAsRenderedOnce($idKey.$idIndex);
$id = $attributes->get('id') ?? 'markas-select-'.hash('xxh32', $idKey.$idIndex);
$describedBy = $error ? $id.'-error' : ($hint ? $id.'-hint' : null);
@endphp
<div class="{{ $wrapper }}">
@if ($label)
<label for="{{ $id }}" class="{{ $labelClass }}">{{ $label }}</label>
@endif
<div class="{{ $control }}">
<select {{ $attributes->merge(['id' => $id, 'aria-invalid' => $error ? 'true' : null, 'aria-describedby' => $describedBy])->class([$field]) }}>
{{ $slot }}
</select>
<svg class="{{ $icon }}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 9 6 6 6-6" /></svg>
</div>
@if ($error)
<p id="{{ $id }}-error" class="{{ $errorClass }}">{{ $error }}</p>
@elseif ($hint)
<p id="{{ $id }}-hint" class="{{ $hintClass }}">{{ $hint }}</p>
@endif
</div>- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
src/components/markas/Select.tsx.
import { useId, type ComponentProps, type ReactNode } from "react";
const wrapper = "grid gap-1.5";
const labelClass = "text-sm font-medium text-ink";
const control = "relative";
const field =
"h-10 w-full cursor-pointer appearance-none rounded-md border border-line bg-surface pr-9 pl-3 text-sm text-ink transition-colors duration-150 ease-out focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-danger motion-reduce:transition-none";
const icon =
"pointer-events-none absolute top-1/2 right-3 size-4 -translate-y-1/2 text-muted";
const hintClass = "text-sm text-muted";
const errorClass = "text-sm text-danger";
const cx = (...c: (string | false | null | undefined)[]) =>
c.filter(Boolean).join(" ");
export type SelectProps = ComponentProps<"select"> & {
label?: ReactNode;
hint?: ReactNode;
error?: ReactNode;
};
export function Select({
label,
hint,
error,
id,
className,
children,
...props
}: SelectProps) {
const generatedId = useId();
const selectId = id ?? generatedId;
const describedBy = error
? `${selectId}-error`
: hint
? `${selectId}-hint`
: undefined;
return (
<div className={wrapper}>
{label && (
<label htmlFor={selectId} className={labelClass}>
{label}
</label>
)}
<div className={control}>
<select
id={selectId}
aria-invalid={error ? true : undefined}
aria-describedby={describedBy}
className={cx(field, className)}
{...props}
>
{children}
</select>
<svg
className={icon}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
>
<path d="m6 9 6 6 6-6" />
</svg>
</div>
{error ? (
<p id={`${selectId}-error`} className={errorClass}>
{error}
</p>
) : hint ? (
<p id={`${selectId}-hint`} className={hintClass}>
{hint}
</p>
) : null}
</div>
);
}- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
src/components/markas/Select.vue.
<script setup lang="ts">
import { computed, onMounted, useId, useTemplateRef } from "vue";
defineOptions({ inheritAttrs: false });
const props = defineProps<{
label?: string;
hint?: string;
error?: string;
id?: string;
}>();
const model = defineModel<string>();
const wrapper = "grid gap-1.5";
const labelClass = "text-sm font-medium text-ink";
const control = "relative";
const field =
"h-10 w-full cursor-pointer appearance-none rounded-md border border-line bg-surface pr-9 pl-3 text-sm text-ink transition-colors duration-150 ease-out focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-danger motion-reduce:transition-none";
const icon =
"pointer-events-none absolute top-1/2 right-3 size-4 -translate-y-1/2 text-muted";
const hintClass = "text-sm text-muted";
const errorClass = "text-sm text-danger";
const generatedId = useId();
const selectId = computed(() => props.id ?? generatedId);
// Tanpa v-model, Vue mengosongkan <select>. Samakan dengan Blade dan React:
// pakai opsi yang ditandai selected, atau opsi pertama, seperti perilaku native.
const select = useTemplateRef<HTMLSelectElement>("select");
onMounted(() => {
if (model.value !== undefined || !select.value) return;
const options = [...select.value.options];
const initial =
options.find((option) => option.defaultSelected) ?? options[0];
if (initial) model.value = initial.value;
});
const describedBy = computed(() =>
props.error
? `${selectId.value}-error`
: props.hint
? `${selectId.value}-hint`
: undefined,
);
</script>
<template>
<div :class="wrapper">
<label v-if="props.label" :for="selectId" :class="labelClass">{{
props.label
}}</label>
<div :class="control">
<select
:id="selectId"
ref="select"
v-model="model"
:aria-invalid="props.error ? 'true' : undefined"
:aria-describedby="describedBy"
:class="field"
v-bind="$attrs"
>
<slot />
</select>
<svg
:class="icon"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="m6 9 6 6 6-6" />
</svg>
</div>
<p v-if="props.error" :id="`${selectId}-error`" :class="errorClass">
{{ props.error }}
</p>
<p v-else-if="props.hint" :id="`${selectId}-hint`" :class="hintClass">
{{ props.hint }}
</p>
</div>
</template>- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
src/lib/components/markas/Select.svelte.
<script lang="ts">
import type { Snippet } from "svelte";
import type { HTMLSelectAttributes } from "svelte/elements";
const wrapper = "grid gap-1.5";
const labelClass = "text-sm font-medium text-ink";
const control = "relative";
const field =
"h-10 w-full cursor-pointer appearance-none rounded-md border border-line bg-surface pr-9 pl-3 text-sm text-ink transition-colors duration-150 ease-out focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-danger motion-reduce:transition-none";
const icon =
"pointer-events-none absolute top-1/2 right-3 size-4 -translate-y-1/2 text-muted";
const hintClass = "text-sm text-muted";
const errorClass = "text-sm text-danger";
type Props = Omit<HTMLSelectAttributes, "value"> & {
label?: string;
hint?: string;
error?: string;
value?: string;
children?: Snippet;
};
let {
label,
hint,
error,
id,
value = $bindable(),
class: className,
children,
...rest
}: Props = $props();
const generatedId = $props.id();
const selectId = $derived(id ?? generatedId);
const describedBy = $derived(
error ? `${selectId}-error` : hint ? `${selectId}-hint` : undefined,
);
</script>
<div class={wrapper}>
{#if label}
<label for={selectId} class={labelClass}>{label}</label>
{/if}
<div class={control}>
<select
id={selectId}
bind:value
aria-invalid={error ? "true" : undefined}
aria-describedby={describedBy}
class={[field, className]}
{...rest}
>
{@render children?.()}
</select>
<svg
class={icon}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="m6 9 6 6 6-6" />
</svg>
</div>
{#if error}
<p id={`${selectId}-error`} class={errorClass}>{error}</p>
{:else if hint}
<p id={`${selectId}-hint`} class={hintClass}>{hint}</p>
{/if}
</div>- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
src/components/markas/Select.astro.
---
import type { HTMLAttributes } from "astro/types";
const wrapper = "grid gap-1.5";
const labelClass = "text-sm font-medium text-ink";
const control = "relative";
const field =
"h-10 w-full cursor-pointer appearance-none rounded-md border border-line bg-surface pr-9 pl-3 text-sm text-ink transition-colors duration-150 ease-out focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-danger motion-reduce:transition-none";
const icon =
"pointer-events-none absolute top-1/2 right-3 size-4 -translate-y-1/2 text-muted";
const hintClass = "text-sm text-muted";
const errorClass = "text-sm text-danger";
type Props = HTMLAttributes<"select"> & {
label?: string;
hint?: string;
error?: string;
};
const { label, hint, error, id, class: className, ...rest } = Astro.props;
const selectId = id ?? `markas-select-${crypto.randomUUID().slice(0, 8)}`;
const describedBy = error
? `${selectId}-error`
: hint
? `${selectId}-hint`
: undefined;
---
<div class={wrapper}>
{
label && (
<label for={selectId} class={labelClass}>
{label}
</label>
)
}
<div class={control}>
<select
id={selectId}
aria-invalid={error ? "true" : undefined}
aria-describedby={describedBy}
class:list={[field, className]}
{...rest}
>
<slot />
</select>
<svg
class={icon}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="m6 9 6 6 6-6"></path>
</svg>
</div>
{
error ? (
<p id={`${selectId}-error`} class={errorClass}>
{error}
</p>
) : hint ? (
<p id={`${selectId}-hint`} class={hintClass}>
{hint}
</p>
) : null
}
</div>- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
src/app/markas/select.component.ts.
import {
afterRenderEffect,
booleanAttribute,
ChangeDetectionStrategy,
Component,
computed,
type ElementRef,
input,
model,
viewChild,
} from "@angular/core";
const wrapper = "grid gap-1.5";
const labelClass = "text-sm font-medium text-ink";
const control = "relative";
const field =
"h-10 w-full cursor-pointer appearance-none rounded-md border border-line bg-surface pr-9 pl-3 text-sm text-ink transition-colors duration-150 ease-out focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-danger motion-reduce:transition-none";
const icon =
"pointer-events-none absolute top-1/2 right-3 size-4 -translate-y-1/2 text-muted";
const hintClass = "text-sm text-muted";
const errorClass = "text-sm text-danger";
let nextId = 0;
/**
* Projected option and optgroup elements fill the native select. Host stays out of layout;
* id, name, aria-label, and class move to the select, so the host attributes are cleared.
*/
@Component({
selector: "markas-select",
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
class: "contents",
"[attr.id]": "null",
"[attr.name]": "null",
"[attr.aria-label]": "null",
},
template: `
<div [class]="wrapper">
@if (label()) {
<label [for]="selectId()" [class]="labelClass">{{ label() }}</label>
}
<div [class]="control">
<select
#select
[id]="selectId()"
[disabled]="disabled()"
[required]="required()"
[attr.name]="name() ?? null"
[attr.aria-label]="ariaLabel() ?? null"
[attr.aria-invalid]="error() ? 'true' : null"
[attr.aria-describedby]="describedBy()"
[class]="fieldClass()"
(change)="value.set(select.value)"
>
<ng-content />
</select>
<svg
[class]="icon"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="m6 9 6 6 6-6" />
</svg>
</div>
@if (error()) {
<p [id]="selectId() + '-error'" [class]="errorClass">{{ error() }}</p>
} @else if (hint()) {
<p [id]="selectId() + '-hint'" [class]="hintClass">{{ hint() }}</p>
}
</div>
`,
})
export class Select {
readonly label = input<string>();
readonly hint = input<string>();
readonly error = input<string>();
readonly id = input<string>();
readonly name = input<string>();
readonly disabled = input(false, { transform: booleanAttribute });
readonly required = input(false, { transform: booleanAttribute });
readonly ariaLabel = input<string | undefined>(undefined, {
alias: "aria-label",
});
readonly userClass = input("", { alias: "class" });
/** Two-way bindable with [(value)]. Without it the option marked selected (or the first) wins. */
readonly value = model<string>();
protected readonly wrapper = wrapper;
protected readonly labelClass = labelClass;
protected readonly control = control;
protected readonly icon = icon;
protected readonly hintClass = hintClass;
protected readonly errorClass = errorClass;
private readonly generatedId = `markas-select-${nextId++}`;
protected readonly selectId = computed(() => this.id() ?? this.generatedId);
protected readonly describedBy = computed(() =>
this.error()
? `${this.selectId()}-error`
: this.hint()
? `${this.selectId()}-hint`
: null,
);
protected readonly fieldClass = computed(() =>
[field, this.userClass()].filter(Boolean).join(" "),
);
private readonly select =
viewChild.required<ElementRef<HTMLSelectElement>>("select");
constructor() {
// Projected options exist only after render, so the value is applied afterwards.
afterRenderEffect(() => {
const value = this.value();
if (value !== undefined) this.select().nativeElement.value = value;
});
}
}Pemakaian
<x-markas.select name="kota" label="Kota" hint="Pilih kota domisili.">
<option value="jakarta">Jakarta</option>
<option value="bandung" @selected(old('kota') === 'bandung')>Bandung</option>
</x-markas.select>import { Select } from "@/components/markas/Select";
<Select name="kota" label="Kota" defaultValue="bandung">
<option value="jakarta">Jakarta</option>
<option value="bandung">Bandung</option>
</Select>;<script setup lang="ts">
import { ref } from "vue";
import Select from "@/components/markas/Select.vue";
const kota = ref("bandung");
</script>
<template>
<Select v-model="kota" name="kota" label="Kota">
<option value="jakarta">Jakarta</option>
<option value="bandung">Bandung</option>
</Select>
</template><script lang="ts">
import Select from "$lib/components/markas/Select.svelte";
let kota = $state("bandung");
</script>
<Select bind:value={kota} name="kota" label="Kota">
<option value="jakarta">Jakarta</option>
<option value="bandung">Bandung</option>
</Select>---
import Select from "@/components/markas/Select.astro";
---
<Select name="kota" label="Kota">
<option value="jakarta">Jakarta</option>
<option value="bandung" selected>Bandung</option>
</Select>Tanpa script klien: select adalah elemen native.
import { Component, signal } from "@angular/core";
import { Select } from "./markas/select.component";
@Component({
selector: "app-alamat",
imports: [Select],
template: `
<markas-select [(value)]="kota" name="kota" label="Kota">
<option value="jakarta">Jakarta</option>
<option value="bandung">Bandung</option>
</markas-select>
`,
})
export class Alamat {
readonly kota = signal("bandung");
}- Atribut tambahan (
name,required,multiple,class) diteruskan ke elemen<select>. - Tanpa
v-model, versi Vue memilih option yang ditandaiselected, atau option pertama, sama seperti Blade dan React. - Komponen ini tidak punya teks bawaan. Semua teks berasal dari prop dan option, jadi cukup tulis dalam Bahasa Indonesia.
Props
| Nama | Tipe | Default | Keterangan |
|---|---|---|---|
label | string | - | Teks label yang terhubung ke select lewat for/id. |
hint | string | - | Teks petunjuk di bawah select. Disembunyikan saat ada error. |
error | string | - | Pesan error. Mengaktifkan aria-invalid dan border danger. |
slot / children | <option> | - | Daftar elemen option (dan optgroup) native. |
value / defaultValue / v-model / bind:value | string | - | Nilai terpilih. Blade dan Astro memakai atribut selected di option, React value atau defaultValue, Vue v-model, Svelte bind:value, Angular value atau [(value)]. |
id | string | auto | Id select. Dibuat otomatis kalau kosong. |
Aksesibilitas
- Memakai elemen select native, jadi keyboard dan screen reader bekerja tanpa JavaScript.
- Label terhubung lewat for dan id, petunjuk dan error lewat aria-describedby.
- Ikon panah disembunyikan dari screen reader dan tidak menangkap klik.
Komponen terkait
Komponen form lain dengan class yang sama di setiap framework.
- ButtonTombol dengan varian primary, secondary, ghost, dan danger.
- CheckboxKotak centang native dengan label dan deskripsi opsional, tampilan kustom tanpa JavaScript.
- ComboboxInput teks dengan daftar saran terfilter di popover, mengikuti pola WAI-ARIA Combobox dengan autocomplete list.
- InputKolom teks dengan label, petunjuk, dan pesan error yang terhubung lewat ARIA.
- Input OTPInput kode sekali pakai yang dipecah menjadi kotak satu digit, dengan maju otomatis, dukungan tempel, dan satu input tersembunyi untuk submit form.
- LabelLabel form dengan gaya konsisten serta penanda wajib atau opsional yang dibacakan screen reader dengan benar.