Primitive

Compose Akar's functionality onto alternative element types or your own Vue components.

Primitive

Compose Akar's functionality onto alternative element types or your own Vue components.

When you are building a component, in some cases you might want to allow user to compose some functionalities onto the underlying element, or alternative element. This is where Primitive comes in handy as it expose this capability to the user.

API Reference

Prop Default Type
asdivstring | Component

The element or component the current element should render as. Can be overwrite by asChild

asChildboolean

Change the default rendered element for the one passed as a child, merging their props and behavior.

Read our Composition guide for more details.

Usage

Changing as value

If you want to change the default element or component being render, you can set the default as when defining the props.

<script setup lang="ts">
import type { APrimitiveProps } from 'akar';
import { APrimitive } from 'akar';

const props = withDefaults(defineProps<APrimitiveProps>(), {
  as: 'span'
});
</script>

<template>
  <!-- Now this element will be rendered as `span` by default -->
  <APrimitive v-bind="props">
    ...
  </APrimitive>
</template>

Render asChild

Change the default rendered element for the one passed as a child, merging their props and behavior.

Read our Composition guide for more details.