Fieldset
Group related form controls under a shared label.
Demos
Usage
vue
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'
const items = [
{ value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>
<template>
<Accordion :items="items" />
</template>
Grouped controls
Wrap related fields in a Fieldset. The legend names the group, while descriptions explain what the fields have in common. Disabling the fieldset disables its nested controls.
Disable the fieldset
vue
<AppLayout :viewport="false" scroll="page">
<template #header>Workspace</template>
<template #left><ProjectNavigation /></template>
<ProjectList />
<template #footer>2 projects</template>
</AppLayout>
Installation
Complete the shared installation. Copy Fieldset.vue and index.ts into app/components/ui/fieldset/.
app/components/ui/fieldset/Fieldset.vue
<script setup lang="ts">
import { Accordion as Primitive } from 'akaza-ui'
import { computed, useAttrs } from 'vue'
import { cn } from '../../../utils/ui'
import uiConfig from '../ui.config'
import {
accordionVariants,
resolveAccordionVariants,
type AccordionProps,
type AccordionSlots,
} from './index'
defineOptions({ inheritAttrs: false })
// Preserve Akaza defaults when optional props, including Boolean aliases, are omitted.
const props = withDefaults(defineProps<AccordionProps>(), {
valueKey: undefined,
labelKey: undefined,
contentKey: undefined,
disabledKey: undefined,
type: undefined,
collapsible: true,
disabled: undefined,
orientation: undefined,
unmountOnHide: undefined,
as: undefined,
ui: undefined,
modelValue: undefined,
})
defineSlots<AccordionSlots>()
const attrs = useAttrs()
const styles = computed(() => accordionVariants(resolveAccordionVariants(props, uiConfig)))
const mergedUi = computed(() => {
const overrides = props.ui as Record<string, string | undefined> | undefined
return Object.fromEntries(
Object.entries(styles.value).map(([part, style]) => [
part,
cn(style(), overrides?.[part], part === 'root' ? props.class : undefined),
]),
)
})
const primitiveProps = computed(() => {
const { class: _class, ui: _ui, size: _size, ...native } = props
return native
})
</script>
<template>
<component :is="Primitive" v-bind="{ ...primitiveProps, ...attrs }" :ui="mergedUi">
<template v-for="(_, name) in $slots" #[name]="scope"
><slot :name="name as keyof AccordionSlots" v-bind="scope ?? {}"
/></template>
</component>
</template>
API
Props
| Prop | Type | Default | Description |
|---|---|---|---|
legend | string | โ | Fieldset legend. |
description | string | โ | Help text linked with aria-describedby. |
disabled | boolean | false | Disables grouped controls via native fieldset behavior. |
invalid | boolean | false | Sets invalid state attributes. |
ui | FieldsetUi | โ | Classes for root, legend, description, content. |
Slots
| Slot | Description |
|---|---|
default | Grouped controls. |
legend | Custom legend content. |
description | Custom description content. |