KSelect
Renders a select input. Under the hood, it wraps a <select>
element.
type State = 'neutral' | 'success' | 'error'
type HintPosition = 'top' | 'bottom'
type KInputSize = 'small' | 'regular' | 'large'
interface KSelectOption {
label: string
value: any
disabled?: boolean
}
interface KSelectProps {
modelValue: any
options?: KSelectOption[]
label?: string
disabled?: boolean
state?: State
rounded?: boolean
size?: KInputSize
light?: boolean
placeholder?: string
hint?: string
hintPosition?: HintPosition
required?: boolean
allowEmpty?: boolean
multiple?: boolean
}
Basic Usage
const options = ref([
{ label: 'Option 1', value: 'option1' },
{ label: 'Option 2', value: 'option2' },
{ label: 'Option 3', value: 'option3' },
])
const selectedOption = ref(options.value[0])
<KSelect v-model="selectedOption" :options="options" />
Props
modelValue
The selected value. Used with v-model for two-way binding. It contains the value
field of the selected option.
options
An array of options to display in the select dropdown.
interface KSelectOption {
label: string // Display text
value: any // Value when selected
disabled?: boolean // Whether the option is selectable
}
label
Label text displayed above the select input.
disabled
When true, prevents user interaction with the select.
state
Applies visual styling to indicate validation state. Possible values are 'neutral'
, 'success'
and 'error'
:
<KSelect ... state="success" />
rounded
Applies rounded corners to the select input.
<KSelect v-model="selectedOption" :options="options" rounded />
size
Controls the size of the select input. Possible values are 'small'
, 'regular'
and 'large'
:
<KSelect ... size="small" />
light
Applies light theme styling for dark backgrounds.
<KSelect ... light />
placeholder
Placeholder text when no option is selected.
<KSelect ... placeholder="Select an option" />
hint
Helper text displayed below the select input.
<KSelect ... hint="Helper text" />
hintPosition
Controls the position of the hint text. Possible values are 'top'
and 'bottom'
(default):
<KSelect ... hintPosition="bottom" />
required
Marks the select as a required field.
<KSelect ... required />
allowEmpty
When true, adds an empty option to clear the selection.
<KSelect ... allowEmpty />
Events
update:modelValue
Emitted when the selection changes.
const emit = defineEmits<{
(e: 'update:modelValue', value: any): void
}>()
change
Emitted when the selection changes. Provides the new selected value(s).
const emit = defineEmits<{
(e: 'change', value: any): void
}>()