Chip
MChip gives a short label a place in a collection: static, selectable, removable, or both selectable and removable.
Next alpha
Available in 0.1.0-alpha.4.
Usage
<script setup lang="ts">
import { ref } from 'vue'
const design = ref(true)
const tags = ref(['Vue', 'NativeScript'])
</script>
<template>
<m-chip v-model="design" selectable label="Design" icon="palette" />
<m-row gap="sm" wrap>
<m-chip
v-for="tag in tags"
:key="tag"
:label="tag"
removable
:removeLabel="`Remove ${tag}`"
@remove="tags = tags.filter((value) => value !== tag)"
/>
</m-row>
</template>Props
| Prop | Type | Default | Behavior |
|---|---|---|---|
label | string | required | Nonempty visible text and selection action name. |
icon | IconName | — | Decorative icon; a check replaces it when selected. |
selectable | boolean | false | Makes the label a toggle button. |
modelValue | boolean | false | Controlled selection; only used when selectable. |
removable | boolean | false | Adds a separate removal button. |
removeLabel | string | — | Required and nonempty when removable, such as Remove Vue. |
tone | primary / accent | primary | Selection and focus color. |
disabled | boolean | false | Blocks both actions, preserving supplied selection. |
width / grow / shrink | dimension / number / number | auto / 0 / context | Layout participation. |
id / accessibilityHidden | string / boolean | — / false | Identifier and accessibility exclusion. |
Missing/blank labels throw TypeError, including a missing removal label when removable is true.
State and actions
update:modelValue requests the opposite boolean. The parent must accept the request to change the selection. remove has no payload: it neither toggles selection nor removes the component. Both actions are sibling targets, with separate names, and disabled chips emit neither event. Static labels have no interactive focus stop.
Use a wrapping Row for groups. Text can wrap within a constrained width; no fixed content height is imposed. A Chip does not manage a collection, enforce exclusive selection, navigate or expose a focus handle. The app owns focus recovery when deleting a focused chip; use an appropriate remaining control. Prefer Badge for short status text and SegmentedControl for a single choice in one group.
Keyboard and motion
Web selection uses a button with aria-pressed; removal is a second button. Tab visits each enabled action, Enter/Space activates it, and keyboard focus is visible. Native composes Row, Text and Icon with a button role and selected/disabled semantics, with disabled taking precedence in NativeScript's single accessibility state. Platform settings determine spoken feedback.
Pressing a chip gives visual feedback and respects reduced motion.
Selecting a chip pops its check in with a short spring. Clearing it lets the check shrink and fade before it is hidden; a chip with its own icon pops that icon back instead. The space for the mark is always reserved, so a row of filters never reflows when a choice changes. The selection itself is never delayed: aria-pressed and the selected state update at once.
Removal stays with the parent. remove fires immediately and the chip does not hold itself on screen. To let it leave gracefully, wrap the collection in a list region and make the change through it; the departing chip fades out while its neighbours close the gap:
const toolbox = useMavisListMotion({ size: false, enter: true, exit: { opacity: 0, scale: 0.8 } })
const remove = (tag: string) =>
toolbox.update(() => {
tags.value = tags.value.filter((value) => value !== tag)
})<m-row gap="sm" wrap :motionRegion="toolbox.region">
<m-chip v-for="tag in tags" :key="tag" :label="tag" removable
:removeLabel="`Remove ${tag}`" @remove="remove(tag)" />
</m-row>Library uses chips to filter topics and EmptyState to recover from an empty search.
Desktop
On the Mac and on Windows a selectable chip is a native button and its remove action is a separate button with its own name. Selection is shown by the colour and the check mark. On the Mac a selectable chip is read as a toggle button that is on or off; Windows does not report the state yet (#489). See Desktop components.
Full example
View source
<script setup lang="ts">
import { useCatalogLocale } from '../locale'
import { computed, ref } from 'vue'
import { useMavisListMotion, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
const { t, locale } = useCatalogLocale(() => props.lang)
const props = withDefaults(defineProps<{ lang?: 'en' | 'pt' }>(), { lang: undefined })
const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const { theme } = useMavisTheme()
const design = ref(true)
const code = ref(false)
const count = computed(() => Number(design.value) + Number(code.value))
const tags = ref(['Vue', 'NativeScript', 'Web'])
// Removal stays with the app: the list region lets the chip leave while its neighbours close in.
const toolbox = useMavisListMotion({
size: false,
enter: true,
exit: { opacity: 0, scale: 0.8 },
})
const remove = (tag: string) =>
toolbox.update(() => {
tags.value = tags.value.filter((value) => value !== tag)
})
const restore = () =>
toolbox.update(() => {
tags.value = ['Vue', 'NativeScript', 'Web']
})
</script>
<template>
<m-column gap="lg">
<m-column padding="lg" gap="lg" radius="lg" :backgroundColor="theme.colors.primarySoft">
<m-text variant="overline" tone="primary">{{
t(pt ? 'SIGA SUA CURIOSIDADE' : 'FOLLOW YOUR CURIOSITY')
}}</m-text>
<m-text variant="title">{{ t(pt ? 'O que move você?' : 'What moves you?') }}</m-text>
<m-text tone="muted">{{
t(
pt
? 'Escolha os assuntos que merecem um lugar no seu dia.'
: 'Make room for the subjects that brighten your day.',
)
}}</m-text>
<m-row gap="sm" wrap>
<m-chip v-model="design" selectable :label="t('Design')" icon="palette" />
<m-chip
v-model="code"
selectable
:label="t(pt ? 'Código' : 'Code')"
icon="code"
tone="accent"
/>
</m-row>
<m-text variant="caption" tone="muted">{{
t(
pt
? `${count} ${count === 1 ? 'assunto selecionado' : 'assuntos selecionados'}`
: `${count} ${count === 1 ? 'topic' : 'topics'} selected`,
)
}}</m-text>
</m-column>
<m-card gap="md">
<m-text variant="overline" tone="muted">{{
t(pt ? 'SUA CAIXA DE FERRAMENTAS' : 'YOUR TOOLBOX')
}}</m-text>
<m-row gap="sm" wrap :motionRegion="toolbox.region">
<m-chip
v-for="tag in tags"
:key="tag"
:label="t(tag)"
removable
:removeLabel="pt ? `Remover ${tag}` : `Remove ${tag}`"
@remove="remove(tag)"
/>
</m-row>
<m-text v-if="!tags.length" tone="muted">{{
t(pt ? 'Espaço para novas ideias.' : 'Room for new ideas.')
}}</m-text>
<m-button variant="ghost" size="sm" @click="restore">{{
t(pt ? 'Restaurar tags' : 'Restore tags')
}}</m-button>
</m-card>
<m-card gap="md">
<m-text variant="overline" tone="muted">{{
t(pt ? 'DETALHES QUE CONTAM' : 'DETAILS THAT MATTER')
}}</m-text>
<m-row gap="sm" wrap>
<m-chip :label="t('Editorial')" icon="book-open" />
<m-chip
:label="t(pt ? 'Em breve' : 'Coming soon')"
selectable
:modelValue="true"
disabled
tone="accent"
/>
</m-row>
</m-card>
</m-column>
</template>