Kit Select
UI8Kit 3 Select primitive (unstyled), from @ui8kit/registry
Install
npx ui8kit add kit-selectPulls in: utils
Preview
No static preview for this item: it needs content or a parent that this page cannot supply. The code is below.
Code
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework svelte --dir src --registry-url https://registry.buildy.tw/svelte --strict-cdnnpx ui8kit add kit-select<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
Select renders option children from Options, then manual children.
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
import type { SelectOptionItem } from "./select.shared";
export type SelectProps = {
value?: string;
multiple?: boolean;
required?: boolean;
disabled?: boolean;
options?: SelectOptionItem[];
class?: string;
children?: Snippet;
[key: string]: unknown;
};
</script>
<script lang="ts">
import { selectClasses } from "./select.shared";
import { eqStr, safeRest, syncValue } from "../../utils/expr";
let {
value,
multiple,
required,
disabled,
options,
class: className,
children,
...rawRest
}: SelectProps = $props();
const rest = $derived(safeRest(rawRest, { blank: ["id", "name", "aria-invalid", "aria-describedby"] }));
const cls = $derived(selectClasses({ className }));
</script>
<select {...(cls ? { class: cls } : {})} multiple={multiple || undefined} required={required || undefined} disabled={disabled || undefined} use:syncValue={value} {...rest}>
{#each options ?? [] as item}
<option value={(item.value) ?? ""} selected={eqStr(item.value, value) || undefined} disabled={item.disabled || undefined}>{item.label}</option>
{/each}
{@render children?.()}
</select>
<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
SelectOptGroup renders a native optgroup around option children.
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
export type SelectOptGroupProps = {
disabled?: boolean;
class?: string;
children?: Snippet;
[key: string]: unknown;
};
</script>
<script lang="ts">
import { safeRest } from "../../utils/expr";
let {
disabled,
class: className,
children,
...rawRest
}: SelectOptGroupProps = $props();
const rest = $derived(safeRest(rawRest, { blank: ["label"] }));
</script>
<optgroup disabled={disabled || undefined} {...rest}>
{@render children?.()}
</optgroup>
<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
SelectOption renders a native option.
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
export type SelectOptionProps = {
selected?: boolean;
disabled?: boolean;
class?: string;
children?: Snippet;
[key: string]: unknown;
};
</script>
<script lang="ts">
import { safeRest } from "../../utils/expr";
let {
selected,
disabled,
class: className,
children,
...rawRest
}: SelectOptionProps = $props();
const rest = $derived(safeRest(rawRest));
</script>
<option selected={selected || undefined} disabled={disabled || undefined} {...rest}>
{@render children?.()}
</option>
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.select — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
export type SelectOptionItem = {
value?: string;
label?: string;
disabled?: boolean;
};
/** Select renders option children from Options, then manual children. */
export type SelectBaseProps = {
value?: string;
multiple?: boolean;
required?: boolean;
disabled?: boolean;
options?: SelectOptionItem[];
};
export type SelectClassesInput = {
className?: string;
};
/** Compose Select classes without rendering — the cross-runtime `asChild` substitute. */
export function selectClasses(input: SelectClassesInput = {}): string {
return cn("pr-2", input.className);
}
/** SelectOption renders a native option. */
export type SelectOptionBaseProps = {
selected?: boolean;
disabled?: boolean;
};
/** SelectOptGroup renders a native optgroup around option children. */
export type SelectOptGroupBaseProps = {
disabled?: boolean;
};
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework react --dir src --registry-url https://registry.buildy.tw/react --strict-cdnnpx ui8kit add kit-select// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.select — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
export type SelectOptionItem = {
value?: string;
label?: string;
disabled?: boolean;
};
/** Select renders option children from Options, then manual children. */
export type SelectBaseProps = {
value?: string;
multiple?: boolean;
required?: boolean;
disabled?: boolean;
options?: SelectOptionItem[];
};
export type SelectClassesInput = {
className?: string;
};
/** Compose Select classes without rendering — the cross-runtime `asChild` substitute. */
export function selectClasses(input: SelectClassesInput = {}): string {
return cn("pr-2", input.className);
}
/** SelectOption renders a native option. */
export type SelectOptionBaseProps = {
selected?: boolean;
disabled?: boolean;
};
/** SelectOptGroup renders a native optgroup around option children. */
export type SelectOptGroupBaseProps = {
disabled?: boolean;
};
// Code generated by @ui8kit/codegen. DO NOT EDIT.
/**
* Select is a native dropdown. Flat options come from the Options list;
* SelectOption / SelectOptGroup children cover grouped or custom markup.
*/
import { forwardRef, type ReactNode, type OptgroupHTMLAttributes, type OptionHTMLAttributes, type SelectHTMLAttributes } from "react";
import { selectClasses, type SelectOptionItem } from "./select.shared";
import { safeRest } from "../../utils/expr";
/**
* Select renders option children from Options, then manual children.
*/
export type SelectProps = Omit<SelectHTMLAttributes<HTMLSelectElement>, "className" | "children" | "value" | "multiple" | "required" | "disabled" | "options"> & {
value?: string;
multiple?: boolean;
required?: boolean;
disabled?: boolean;
options?: SelectOptionItem[];
className?: string;
children?: ReactNode;
};
export const Select = forwardRef<HTMLSelectElement, SelectProps>(function Select(
{ value, multiple, required, disabled, options, className, children, ...rawRest },
ref
) {
const rest = safeRest(rawRest, { blank: ["id", "name", "aria-invalid", "aria-describedby"] });
const cls = selectClasses({ className });
return (
<select ref={ref} className={cls || undefined} multiple={multiple} required={required} disabled={disabled} {...(value === undefined ? {} : { [rest.onChange ? "value" : "defaultValue"]: multiple ? [value] : value })} {...rest}>
{(options ?? []).map((item, index) => (
<option key={index} value={(item.value) ?? ""} disabled={item.disabled}>
{item.label}
</option>
))}
{children}
</select>
);
});
Select.displayName = "Select";
/**
* SelectOption renders a native option.
*/
export type SelectOptionProps = Omit<OptionHTMLAttributes<HTMLOptionElement>, "className" | "children" | "selected" | "disabled"> & {
selected?: boolean;
disabled?: boolean;
className?: string;
children?: ReactNode;
};
export const SelectOption = forwardRef<HTMLOptionElement, SelectOptionProps>(function SelectOption(
{ selected, disabled, className, children, ...rawRest },
ref
) {
const rest = safeRest(rawRest);
return (
<option ref={ref} selected={selected} disabled={disabled} {...rest}>
{children}
</option>
);
});
SelectOption.displayName = "SelectOption";
/**
* SelectOptGroup renders a native optgroup around option children.
*/
export type SelectOptGroupProps = Omit<OptgroupHTMLAttributes<HTMLOptGroupElement>, "className" | "children" | "disabled"> & {
disabled?: boolean;
className?: string;
children?: ReactNode;
};
export const SelectOptGroup = forwardRef<HTMLOptGroupElement, SelectOptGroupProps>(function SelectOptGroup(
{ disabled, className, children, ...rawRest },
ref
) {
const rest = safeRest(rawRest, { blank: ["label"] });
return (
<optgroup ref={ref} disabled={disabled} {...rest}>
{children}
</optgroup>
);
});
SelectOptGroup.displayName = "SelectOptGroup";
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework vue --dir src --registry-url https://registry.buildy.tw/vue --strict-cdnnpx ui8kit add kit-select<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
Select renders option children from Options, then manual children.
-->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import { selectClasses, type SelectOptionItem } from "./select.shared";
import { eqStr, safeRest } from "../../utils/expr";
defineOptions({ name: "Select", inheritAttrs: false });
const props = defineProps<{
value?: string;
multiple?: boolean;
required?: boolean;
disabled?: boolean;
options?: SelectOptionItem[];
}>();
const attrs = useAttrs();
const callerClass = computed(() => attrs.class as string | undefined);
const restAttrs = computed(() => {
const { class: _class, ...restEntries } = attrs;
return safeRest(restEntries, { blank: ["id", "name", "aria-invalid", "aria-describedby"] });
});
const cls = computed(() => selectClasses({ className: callerClass.value }));
</script>
<template>
<select :class="cls || undefined" :multiple="props.multiple || undefined" :required="props.required || undefined" :disabled="props.disabled || undefined" v-bind="{ ...(props.value === undefined ? {} : { '.value': props.value }), ...restAttrs }">
<option v-for="(item, index) in (props.options ?? [])" :key="index" :value="(item.value) ?? ''" :selected="eqStr(item.value, props.value) || undefined" :disabled="item.disabled || undefined">
{{ item.label }}
</option>
<slot />
</select>
</template>
<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
SelectOptGroup renders a native optgroup around option children.
-->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import { safeRest } from "../../utils/expr";
defineOptions({ name: "SelectOptGroup", inheritAttrs: false });
const props = defineProps<{
disabled?: boolean;
}>();
const attrs = useAttrs();
const restAttrs = computed(() => {
const { class: _class, ...restEntries } = attrs;
return safeRest(restEntries, { blank: ["label"] });
});
</script>
<template>
<optgroup :disabled="props.disabled || undefined" v-bind="restAttrs">
<slot />
</optgroup>
</template>
<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
SelectOption renders a native option.
-->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import { safeRest } from "../../utils/expr";
defineOptions({ name: "SelectOption", inheritAttrs: false });
const props = defineProps<{
selected?: boolean;
disabled?: boolean;
}>();
const attrs = useAttrs();
const restAttrs = computed(() => {
const { class: _class, ...restEntries } = attrs;
return safeRest(restEntries);
});
</script>
<template>
<option :selected="props.selected || undefined" :disabled="props.disabled || undefined" v-bind="restAttrs">
<slot />
</option>
</template>
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.select — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
export type SelectOptionItem = {
value?: string;
label?: string;
disabled?: boolean;
};
/** Select renders option children from Options, then manual children. */
export type SelectBaseProps = {
value?: string;
multiple?: boolean;
required?: boolean;
disabled?: boolean;
options?: SelectOptionItem[];
};
export type SelectClassesInput = {
className?: string;
};
/** Compose Select classes without rendering — the cross-runtime `asChild` substitute. */
export function selectClasses(input: SelectClassesInput = {}): string {
return cn("pr-2", input.className);
}
/** SelectOption renders a native option. */
export type SelectOptionBaseProps = {
selected?: boolean;
disabled?: boolean;
};
/** SelectOptGroup renders a native optgroup around option children. */
export type SelectOptGroupBaseProps = {
disabled?: boolean;
};
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework solid --dir src --registry-url https://registry.buildy.tw/solid --strict-cdnnpx ui8kit add kit-select// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.select — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
export type SelectOptionItem = {
value?: string;
label?: string;
disabled?: boolean;
};
/** Select renders option children from Options, then manual children. */
export type SelectBaseProps = {
value?: string;
multiple?: boolean;
required?: boolean;
disabled?: boolean;
options?: SelectOptionItem[];
};
export type SelectClassesInput = {
className?: string;
};
/** Compose Select classes without rendering — the cross-runtime `asChild` substitute. */
export function selectClasses(input: SelectClassesInput = {}): string {
return cn("pr-2", input.className);
}
/** SelectOption renders a native option. */
export type SelectOptionBaseProps = {
selected?: boolean;
disabled?: boolean;
};
/** SelectOptGroup renders a native optgroup around option children. */
export type SelectOptGroupBaseProps = {
disabled?: boolean;
};
// Code generated by @ui8kit/codegen. DO NOT EDIT.
/**
* Select is a native dropdown. Flat options come from the Options list;
* SelectOption / SelectOptGroup children cover grouped or custom markup.
*/
import { createEffect, splitProps, type JSX, type Component } from "solid-js";
import { selectClasses, type SelectOptionItem } from "./select.shared";
import { eqStr, safeRest, syncValue } from "../../utils/expr";
/**
* Select renders option children from Options, then manual children.
*/
export type SelectProps = Omit<JSX.SelectHTMLAttributes<HTMLSelectElement>, "class" | "className" | "children" | "value" | "multiple" | "required" | "disabled" | "options"> & {
value?: string;
multiple?: boolean;
required?: boolean;
disabled?: boolean;
options?: SelectOptionItem[];
class?: string;
className?: string;
children?: JSX.Element;
};
export const Select: Component<SelectProps> = (props) => {
const [local, rest] = splitProps(props, ["value", "multiple", "required", "disabled", "options", "class", "className", "children"]);
const cls = () => selectClasses({ className: local.class ?? local.className });
return (
<select {...(cls() ? { class: cls() } : {})} multiple={local.multiple || undefined} required={local.required || undefined} disabled={local.disabled || undefined} ref={(el) => createEffect(() => syncValue(el, local.value))} {...safeRest(rest, { blank: ["id", "name", "aria-invalid", "aria-describedby"] })}>
{(local.options ?? []).map((item) => (
<option value={(item.value) ?? ""} selected={eqStr(item.value, local.value) || undefined} disabled={item.disabled || undefined}>
{item.label}
</option>
))}
{local.children}
</select>
);
};
/**
* SelectOption renders a native option.
*/
export type SelectOptionProps = Omit<JSX.OptionHTMLAttributes<HTMLOptionElement>, "class" | "className" | "children" | "selected" | "disabled"> & {
selected?: boolean;
disabled?: boolean;
class?: string;
className?: string;
children?: JSX.Element;
};
export const SelectOption: Component<SelectOptionProps> = (props) => {
const [local, rest] = splitProps(props, ["selected", "disabled", "class", "className", "children"]);
return (
<option selected={local.selected || undefined} disabled={local.disabled || undefined} {...safeRest(rest)}>
{local.children}
</option>
);
};
/**
* SelectOptGroup renders a native optgroup around option children.
*/
export type SelectOptGroupProps = Omit<JSX.OptgroupHTMLAttributes<HTMLOptGroupElement>, "class" | "className" | "children" | "disabled"> & {
disabled?: boolean;
class?: string;
className?: string;
children?: JSX.Element;
};
export const SelectOptGroup: Component<SelectOptGroupProps> = (props) => {
const [local, rest] = splitProps(props, ["disabled", "class", "className", "children"]);
return (
<optgroup disabled={local.disabled || undefined} {...safeRest(rest, { blank: ["label"] })}>
{local.children}
</optgroup>
);
};
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework templ --dir src --registry-url https://registry.buildy.tw/templ --strict-cdnnpx ui8kit add kit-select// Code generated by @ui8kit/codegen. DO NOT EDIT.
/*
Select is a native dropdown. Flat options come from the Options list;
SelectOption / SelectOptGroup children cover grouped or custom markup.
*/
package selectfield
import (
uiutils "github.com/ui8kit/codegen/generated/templ/utils"
)
// SelectOptionItem is one SelectOptionItem entry.
type SelectOptionItem struct {
Value string
Label string
Disabled bool
}
// SelectProps configures Select.
type SelectProps struct {
// Class — token class names supplied by the consumer
Class string
ID string
Name string
// Value — selected option value
Value string
Multiple bool
Required bool
Disabled bool
Options []SelectOptionItem
AriaInvalid string
AriaDescribedBy string
Attrs templ.Attributes
}
// SelectClasses composes Select classes without rendering —
// the server-composition escape hatch for custom root elements (no asChild in templ).
func SelectClasses(p SelectProps) string {
return uiutils.Cn("pr-2", p.Class)
}
// Select renders the Select contract.
templ Select(p SelectProps) {
<select
if SelectClasses(p) != "" {
class={ SelectClasses(p) }
}
if !uiutils.HasAttr(p.Attrs, "id") {
if uiutils.IsSetStr(p.ID) {
id={ p.ID }
}
}
if !uiutils.HasAttr(p.Attrs, "name") {
if uiutils.IsSetStr(p.Name) {
name={ p.Name }
}
}
if !uiutils.HasAttr(p.Attrs, "multiple") {
multiple?={ p.Multiple }
}
if !uiutils.HasAttr(p.Attrs, "required") {
required?={ p.Required }
}
if !uiutils.HasAttr(p.Attrs, "disabled") {
disabled?={ p.Disabled }
}
if !uiutils.HasAttr(p.Attrs, "aria-invalid") {
if uiutils.IsSetStr(p.AriaInvalid) {
aria-invalid={ p.AriaInvalid }
}
}
if !uiutils.HasAttr(p.Attrs, "aria-describedby") {
if uiutils.IsSetStr(p.AriaDescribedBy) {
aria-describedby={ p.AriaDescribedBy }
}
}
{ uiutils.RestAttrs(p.Attrs, false, "id", "name", "aria-invalid", "aria-describedby")... }
>
for _, item := range p.Options {
<option
value={ item.Value }
selected?={ (item.Value == p.Value) }
disabled?={ item.Disabled }
>
{ item.Label }
</option>
}
{ children... }
</select>
}
// SelectOptionProps configures SelectOption.
type SelectOptionProps struct {
Value *string
Selected bool
Disabled bool
Attrs templ.Attributes
}
// SelectOption renders the SelectOption contract.
templ SelectOption(p SelectOptionProps) {
<option
if !uiutils.HasAttr(p.Attrs, "value") {
if p.Value != nil {
value={ *p.Value }
}
}
if !uiutils.HasAttr(p.Attrs, "selected") {
selected?={ p.Selected }
}
if !uiutils.HasAttr(p.Attrs, "disabled") {
disabled?={ p.Disabled }
}
{ uiutils.RestAttrs(p.Attrs, false)... }
>
{ children... }
</option>
}
// SelectOptGroupProps configures SelectOptGroup.
type SelectOptGroupProps struct {
Label string
Disabled bool
Attrs templ.Attributes
}
// SelectOptGroup renders the SelectOptGroup contract.
templ SelectOptGroup(p SelectOptGroupProps) {
<optgroup
if !uiutils.HasAttr(p.Attrs, "label") {
if uiutils.IsSetStr(p.Label) {
label={ p.Label }
}
}
if !uiutils.HasAttr(p.Attrs, "disabled") {
disabled?={ p.Disabled }
}
{ uiutils.RestAttrs(p.Attrs, false, "label")... }
>
{ children... }
</optgroup>
}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework twig --dir src --registry-url https://registry.buildy.tw/twig --strict-cdnnpx ui8kit add kit-select{# Code generated by @ui8kit/codegen. DO NOT EDIT. #}
{# Select — Select renders option children from Options, then manual children. #}
{# @param class (string) #}
{# @param id (string) #}
{# @param name (string) #}
{# @param value (string) #}
{# @param multiple (bool) #}
{# @param required (bool) #}
{# @param disabled (bool) #}
{# @param options (items) #}
{# @param ariaInvalid (string) #}
{# @param ariaDescribedBy (string) #}
{# @param attrs (attrs) #}
{# @param children (children) #}
{% set class = class|default('') %}
{% set id = id ?? null %}
{% set name = name ?? null %}
{% set value = value|default('') %}
{% set multiple = multiple|default(false) %}
{% set required = required|default(false) %}
{% set disabled = disabled|default(false) %}
{% set options = options|default([]) %}
{% set ariaInvalid = ariaInvalid ?? null %}
{% set ariaDescribedBy = ariaDescribedBy ?? null %}
{% set attrs = attrs|default([]) %}
{% set children = children|default('') %}
<select{{ ui8kit_attrs({'class': ui8kit_or_null(ui8kit_classes('selectClasses', {'class': class, 'id': id, 'name': name, 'value': value, 'multiple': multiple, 'required': required, 'disabled': disabled, 'ariaInvalid': ariaInvalid, 'ariaDescribedBy': ariaDescribedBy})), 'id': ui8kit_or_null(id), 'name': ui8kit_or_null(name), 'multiple': multiple, 'required': required, 'disabled': disabled, 'aria-invalid': ui8kit_or_null(ariaInvalid), 'aria-describedby': ui8kit_or_null(ariaDescribedBy)}, attrs, false, ['id', 'name', 'aria-invalid', 'aria-describedby']) }}>{% for item in options %}<option{{ ui8kit_attrs({'value': (item.value ?? ''), 'selected': ((item.value ?? '') is same as(value)), 'disabled': (item.disabled ?? false)}) }}>{{ (item.label ?? '') }}</option>{% endfor %}{{ children|raw }}</select>
{# Code generated by @ui8kit/codegen. DO NOT EDIT. #}
{# SelectOptGroup — SelectOptGroup renders a native optgroup around option children. #}
{# @param label (string) #}
{# @param disabled (bool) #}
{# @param attrs (attrs) #}
{# @param children (children) #}
{% set label = label ?? null %}
{% set disabled = disabled|default(false) %}
{% set attrs = attrs|default([]) %}
{% set children = children|default('') %}
<optgroup{{ ui8kit_attrs({'label': ui8kit_or_null(label), 'disabled': disabled}, attrs, false, ['label']) }}>{{ children|raw }}</optgroup>
{# Code generated by @ui8kit/codegen. DO NOT EDIT. #}
{# SelectOption — SelectOption renders a native option. #}
{# @param value (string) #}
{# @param selected (bool) #}
{# @param disabled (bool) #}
{# @param attrs (attrs) #}
{# @param children (children) #}
{% set value = value ?? null %}
{% set selected = selected|default(false) %}
{% set disabled = disabled|default(false) %}
{% set attrs = attrs|default([]) %}
{% set children = children|default('') %}
<option{{ ui8kit_attrs({'value': value, 'selected': selected, 'disabled': disabled}, attrs) }}>{{ children|raw }}</option>
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework latte --dir src --registry-url https://registry.buildy.tw/latte --strict-cdnnpx ui8kit add kit-select{* Code generated by @ui8kit/codegen. DO NOT EDIT. *}
{* Select — Select renders option children from Options, then manual children. *}
{parameters
string $class = '',
?string $id = null,
?string $name = null,
string $value = '',
bool $multiple = false,
bool $required = false,
bool $disabled = false,
array $options = [],
?string $ariaInvalid = null,
?string $ariaDescribedBy = null,
array $attrs = [],
string $children = '',
}
<select n:attr="[
'class' => \UI8Kit\Latte\Rt::orNull(\UI8Kit\Latte\Classes::selectClasses(['class' => $class, 'id' => $id, 'name' => $name, 'value' => $value, 'multiple' => $multiple, 'required' => $required, 'disabled' => $disabled, 'ariaInvalid' => $ariaInvalid, 'ariaDescribedBy' => $ariaDescribedBy])),
'id' => \UI8Kit\Latte\Rt::orNull($id),
'name' => \UI8Kit\Latte\Rt::orNull($name),
'multiple' => $multiple,
'required' => $required,
'disabled' => $disabled,
'aria-invalid' => \UI8Kit\Latte\Rt::orNull($ariaInvalid),
'aria-describedby' => \UI8Kit\Latte\Rt::orNull($ariaDescribedBy),
...\UI8Kit\Latte\Rt::restAttrs($attrs, false, ['id', 'name', 'aria-invalid', 'aria-describedby']),
]">{foreach $options as $item}<option n:attr="[
'value' => ($item['value'] ?? ''),
'selected' => (($item['value'] ?? '') === $value),
'disabled' => ($item['disabled'] ?? false),
]">{=($item['label'] ?? '')}</option>{/foreach}{$children|noescape}</select>{* Code generated by @ui8kit/codegen. DO NOT EDIT. *}
{* SelectOptGroup — SelectOptGroup renders a native optgroup around option children. *}
{parameters
?string $label = null,
bool $disabled = false,
array $attrs = [],
string $children = '',
}
<optgroup n:attr="[
'label' => \UI8Kit\Latte\Rt::orNull($label),
'disabled' => $disabled,
...\UI8Kit\Latte\Rt::restAttrs($attrs, false, ['label']),
]">{$children|noescape}</optgroup>{* Code generated by @ui8kit/codegen. DO NOT EDIT. *}
{* SelectOption — SelectOption renders a native option. *}
{parameters
?string $value = null,
bool $selected = false,
bool $disabled = false,
array $attrs = [],
string $children = '',
}
<option n:attr="[
'value' => $value,
'selected' => $selected,
'disabled' => $disabled,
...\UI8Kit\Latte\Rt::restAttrs($attrs),
]">{$children|noescape}</option>Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework jinja2 --dir src --registry-url https://registry.buildy.tw/jinja2 --strict-cdnnpx ui8kit add kit-select{#- Code generated by @ui8kit/codegen. DO NOT EDIT.
SelectOptGroup: SelectOptGroup renders a native optgroup around option children.
Props (p): Label (string), Disabled (bool), Attrs (attrs), Children (children).
children: TRUSTED HTML printed with |safe — never pass unescaped user input.
-#}
<optgroup
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'label') %}{%- if ui_is_set_str(p['Label']) %} label="{{ p['Label'] }}"{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'disabled') %}{%- if ui_def(p['Disabled'], false) %} disabled{%- endif %}{%- endif %}
{{ ui_attr_html(ui_def(p['Attrs'], {}), false, ['label']) }}
>{{ children|default('', true)|safe }}</optgroup>
{#- Code generated by @ui8kit/codegen. DO NOT EDIT.
SelectOption: SelectOption renders a native option.
Props (p): Value (string), Selected (bool), Disabled (bool), Attrs (attrs), Children (children).
children: TRUSTED HTML printed with |safe — never pass unescaped user input.
-#}
<option
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'value') %}{%- if p['Value'] is defined and p['Value'] is not none %} value="{{ p['Value'] }}"{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'selected') %}{%- if ui_def(p['Selected'], false) %} selected{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'disabled') %}{%- if ui_def(p['Disabled'], false) %} disabled{%- endif %}{%- endif %}
{{ ui_attr_html(ui_def(p['Attrs'], {})) }}
>{{ children|default('', true)|safe }}</option>
{#- Code generated by @ui8kit/codegen. DO NOT EDIT.
Select: Select renders option children from Options, then manual children.
Props (p): Class (string), ID (string), Name (string), Value (string), Multiple (bool), Required (bool), Disabled (bool), Options (SelectOptionItem[]), AriaInvalid (string), AriaDescribedBy (string), Attrs (attrs), Children (children).
children: TRUSTED HTML printed with |safe — never pass unescaped user input.
Classes without rendering: select_classes(p) (no asChild in Jinja2). -#}
<select
{%- with cls = select_classes(p) %}{%- if cls %} class="{{ cls }}"{%- endif %}{%- endwith %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'id') %}{%- if ui_is_set_str(p['ID']) %} id="{{ p['ID'] }}"{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'name') %}{%- if ui_is_set_str(p['Name']) %} name="{{ p['Name'] }}"{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'multiple') %}{%- if ui_def(p['Multiple'], false) %} multiple{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'required') %}{%- if ui_def(p['Required'], false) %} required{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'disabled') %}{%- if ui_def(p['Disabled'], false) %} disabled{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-invalid') %}{%- if ui_is_set_str(p['AriaInvalid']) %} aria-invalid="{{ p['AriaInvalid'] }}"{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-describedby') %}{%- if ui_is_set_str(p['AriaDescribedBy']) %} aria-describedby="{{ p['AriaDescribedBy'] }}"{%- endif %}{%- endif %}
{{ ui_attr_html(ui_def(p['Attrs'], {}), false, ['id', 'name', 'aria-invalid', 'aria-describedby']) }}
>{%- for item in ui_def(p['Options'], []) %}<option
value="{{ ui_field(item, 'Value', '') }}"
{%- if ui_eq(ui_field(item, 'Value', ''), ui_def(p['Value'], '')) %} selected{%- endif %}
{%- if ui_truthy(ui_field(item, 'Disabled', false)) %} disabled{%- endif %}
>{{ ui_field(item, 'Label', '') }}</option>{%- endfor %}{{ children|default('', true)|safe }}</select>
Props
Names and types come from the xgen specs of the source. Standard HTML attributes (id, role, tabIndex, aria-*) pass through to the root element; the class prop is className in React.
No props data for this item.