List â
Basic â
AList
is fully customizable and provides easy to use API to render list. It support ATypography
props to render text quickly.
You can also use default
slot to render your custom content if you don't want to use typography props.
Donut jujubes
Sesame snaps
I love jelly
Cake gummi
Customization
AList
is highly customizable component. It uses CSS variables for its spacing so you can have full control over high it look. You can update this CSS variables via UnoCSS classes to change the appearance.
<template>
<AList class="[--a-list-gap:1rem]"></AList>
</template>
WARNING
When you override the list item via CSS variable, it's up to you to handle --a-spacing
CSS var. For example, you are overriding list gap and don't want to consider the --a-spacing
variable then you can simply override it via [--a-spacing:1]
. However, if you want to allow spacing modification then write [--a-spacing:calc(1*var(--a-spacing))]
For in library example you can check .a-list-items-pill
class styles.
Make list items clickable
If you want to make list item clickable (have cursor pointer), You can pass value
property other than undefined
.
const items = [
{ text: 'Donut jujubes', value: null }, // value other than `undefined`
{ text: 'Sesame snaps' },
{ text: 'I love jelly' },
{ text: 'Cake gummi' },
]
With above items, first item will be clickable (have cursor pointer) and rest of the items will have default pointer.
In case if you want to make all the items clickable without adding value
property to each item, you can use :model-value="null"
prop to AList
.
<script lang="ts" setup>
const items = [
{ text: 'Donut jujubes' },
{ text: 'Sesame snaps' },
{ text: 'I love jelly' },
{ text: 'Cake gummi' },
]
</script>
<template>
<ACard>
<AList
:model-value="null"
:items="items"
/>
</ACard>
</template>
Slots â
Use before
& after
slot to add custom content before and after list items. There's also prepend
& append
slot for list item to append & prepend custom content.
- â 1
Donut jujubes
- â 2
Sesame snaps
- â 3
I love jelly
- â 4
Cake gummi
4 items found
INFO
Default theme preset provides helpful class .kbd
to render keyboard keys just like kbd
element.
Avatar â
You can also pass avatar props like src
or icon
to list item under $avatar
property to render the desired avatar without writing extra markup.
You can also use avatar-append
prop to render the avatar at the end instead of start.
Electronics
Mobile, Earbuds, TV
Fashion
T-shirt, Jeans, Shoes
Decor
Fine Art, Dining
Sports
Football, Cricket Kit
Taking flexibility to next level đ
AList
supports rendering avatar & icon at the same time on desired location to improve the DX and reduce the markup.
If pass $avatar
property and icon
property at the same time, icon
property will get precedence and AList
will render icon.
Just like avatar-append
, you can also use icon-append
to render the action buttons for your list.
v-model
Support â
AList
also support v-model
. Use any value other than undefined
to enable the v-model
support.
If you are using AListItem
in default slot of AList
you can use handleListItemClick
slot prop function to select the item value. handleListItemClick
accepts option item as parameter.
Donut jujubes
Sesame snaps
I love jelly
Cake gummi
Selected: null
Donut jujubes
Sesame snaps
I love jelly
Cake gummi
Selected: null
TIP
For selection, AList
uses useSelection
. Hence, you can also use the multi
prop to allow multiple selection.
Variants â
AList
also accepts layer props like variant
, color
& states
to change the appearance of list.
Donut jujubes
Sesame snaps
I love jelly
Cake gummi
TIP
Use a-list-items-pill
to create pill shaped list items. It just modifies some CSS to achieve the pill UI.
CSS Variables â
AList
comes with various CSS variables to customize the UI according to your need. You can check them in this section.
API â
Items to render in list
Enable selecting multiple list items
Emit whole object when item is select instead of item.value
Bind v-model value to selected list item
Layer variant
Mark list item disabled
Tag to use for title of the component
Tag to use for subtitle of the component
Tag to use for text rendered via text
prop
Render icon at the end instead of starting of list item
Render avatar at the end instead of starting of list item
Mark list item as active
Typography text content
List item icon
Layer color
Typography title
Typography subtitle
List item value, makes list item clickable.
Props for rendering avatar.