Collapsible
Bearbeiten
Verwenden Sie einen Button oder eine andere Komponente im Standard-Slot des Collapsible.
Verwenden Sie dann den #content-Steckplatz, um den Inhalt hinzuzufügen, der angezeigt wird, wenn der Collapsible geöffnet ist.
<template>
<UCollapsible class="flex flex-col gap-2 w-48">
<UButton
label="Open"
color="neutral"
variant="subtle"
trailing-icon="i-lucide-chevron-down"
block
/>
<template #content>
<Placeholder class="h-48" />
</template>
</UCollapsible>
</template>Unmount nicht verfügbar
Verwenden Sie die unmount-on-hide-Prop, um zu verhindern, dass der Inhalt nicht mehr eingehängt wird, wenn das Collapsible zusammengeklappt wird. Standardmäßig ist true.
<template>
<UCollapsible :unmount-on-hide="false" class="flex flex-col gap-2 w-48">
<UButton
label="Open"
color="neutral"
variant="subtle"
trailing-icon="i-lucide-chevron-down"
block
/>
<template #content>
<Placeholder class="h-48" />
</template>
</UCollapsible>
</template>Disabled (nicht verfügbar)
Verwenden Sie die disabled-Prop, um das Collapsible zu deaktivieren.
<template>
<UCollapsible class="flex flex-col gap-2 w-48" disabled>
<UButton
label="Open"
color="neutral"
variant="subtle"
trailing-icon="i-lucide-chevron-down"
block
/>
<template #content>
<Placeholder class="h-48" />
</template>
</UCollapsible>
</template>Examples Bearbeiten
Control im offenen Zustand
Sie können den offenen Zustand mithilfe der Direktive default-open prop oder der Direktive v-model:open steuern.
<script setup lang="ts">
const open = ref(true)
defineShortcuts({
o: () => open.value = !open.value
})
</script>
<template>
<UCollapsible v-model:open="open" class="flex flex-col gap-2 w-48">
<UButton
label="Open"
color="neutral"
variant="subtle"
trailing-icon="i-lucide-chevron-down"
block
/>
<template #content>
<Placeholder class="h-48" />
</template>
</UCollapsible>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const open = ref(true)
defineShortcuts({
o: () => open.value = !open.value
})
</script>
<template>
<UCollapsible v-model:open="open" class="flex flex-col gap-2 w-48">
<UButton
label="Open"
color="neutral"
variant="subtle"
trailing-icon="i-lucide-chevron-down"
block
/>
<template #content>
<Placeholder class="h-48" />
</template>
</UCollapsible>
</template>
defineShortcuts das Kollapsible durch Drücken von: kbd{value="O"} umschalten.Mit rotierendem Symbol
Hier ist ein Beispiel mit einem rotierenden Symbol im Button, das den offenen Zustand des Collapsible anzeigt.
<template>
<UCollapsible class="flex flex-col gap-2 w-48">
<UButton
class="group"
label="Open"
color="neutral"
variant="subtle"
trailing-icon="i-lucide-chevron-down"
:ui="{
trailingIcon: 'group-data-[state=open]:rotate-180 transition-transform duration-200'
}"
block
/>
<template #content>
<Placeholder class="h-48" />
</template>
</UCollapsible>
</template>
API (Englisch)
Props Bearbeiten
| Prop | Default | Type |
|---|---|---|
as | 'div' | anyThe element or component this component should render as. |
disabled | boolean When | |
defaultOpen | boolean The open state of the collapsible when it is initially rendered. | |
open | boolean The controlled open state of the collapsible. Can be binded with | |
unmountOnHide | true | boolean When |
ui | { root?: SlotClass; content?: SlotClass; } |
Slots Bearbeiten
| Slot | Type |
|---|---|
default | { open: boolean; } |
content | {} |
Emits (nicht)
| Event | Type |
|---|---|
update:open | [value: boolean] |
Theme Bearbeiten
export default defineAppConfig({
ui: {
collapsible: {
slots: {
root: '',
content: 'data-[state=open]:animate-[collapsible-down_200ms_var(--ease-out)] data-[state=closed]:animate-[collapsible-up_200ms_var(--ease-out)] data-[state=closed]:overflow-hidden'
}
}
}
})import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
collapsible: {
slots: {
root: '',
content: 'data-[state=open]:animate-[collapsible-down_200ms_var(--ease-out)] data-[state=closed]:animate-[collapsible-up_200ms_var(--ease-out)] data-[state=closed]:overflow-hidden'
}
}
}
})
]
})