Button group ​

Basic usage ​

WButtonGroup is a segmented control bound with v-model. list takes plain values; for objects, also pass valueGetter to pick the model value out of each item.

Options have no default label: render each one through the option slot, or pass an optionComponent that receives option and selected.

Selected: week

vue
<template>
  <WButtonGroup
    v-model="period"
    :list="periods"
    title="Period"
  >
    <template #option="{option}">
      {{ option }}
    </template>
  </WButtonGroup>

  <p class="mt-2 text-sm text-description">
    Selected: {{ period }}
  </p>
</template>

<script lang="ts" setup>
import {ref} from 'vue'

import WButtonGroup from 'eco-vue-js/dist/components/Button/WButtonGroup.vue'

const periods = ['day', 'week', 'month'] as const

const period = ref<typeof periods[number]>('week')
</script>

API ​

WButtonGroup ​

ts
import WButtonGroup from 'eco-vue-js/dist/components/Button/WButtonGroup.vue'

Props ​

PropTypeDefaultDescription
listEntity[] | readonly Model[]requiredOptions, each passed to the option slot. A primitive is its own value, an object needs valueGetter.
valueGetterValueGetter | ((value: Entity) => Model)—Value of an option. Needed when list holds objects.
optionComponentButtonGroupOptionComponent<Entity> | ButtonGroupOptionComponent<Model>—Renders an option's content. The option slot replaces it.
modelValueModelrequiredValue of the pressed option.
wrapboolean—Wraps the options onto new lines instead of overflowing.
colboolean—Stacks the options vertically.
semanticTypeSemanticTypeSemanticType.PRIMARYColor scheme of the pressed option.
loadingboolean—Shows a spinner in the last clicked option and disables the others, while its change is saved.
stretchboolean—Stretches the group to the full width, sharing it equally between the options.
allowClearboolean—A click on the pressed option emits null.
disabledItemsModel[]—Values of the options to disable.
Inherited from src/components/FieldWrapper/types.ts (23)
PropTypeDefaultDescription
titlestring—Label above the field; the title slot replaces it.
titleIconSVGComponent—Icon before the title text.
descriptionstring—Secondary text under the field.
errorMessagestring—Validation message under the field, which also colors the changes marker.
tooltipTextstring—Tooltip on hover over the whole field. Not shown while readonly or loading as a skeleton.
maxLengthnumber—Shows a length / maxLength counter under the field while it is focused.
monoboolean—Monospace font for the value.
hasChangesboolean—Shows a dot in the field's corner, marking an unsaved change.
skeletonboolean—Renders skeleton placeholders for the title, field and description. When unset, inherits the skeleton state provided by a parent.
disabledboolean—Blocks input and dims the field. When unset, inherits the disabled state provided by a parent.
readonlyboolean—Shows the value without allowing changes. When unset, inherits the readonly state provided by a parent.
requiredboolean—Adds an asterisk to the title.
noMarginboolean—Drops the default bottom margin.
allowCopyboolean—Adds a button that copies the value.
leftErrorboolean—Aligns the error message to the left instead of the right.
filterFieldstring—Route query key for a filter button next to the title — clicking it toggles filterField=<value> in the URL.
filterValueunknown—Value the filter button puts in the query. Defaults to modelValue.
subgridboolean—Lays the field out on the parent grid's columns, with the title in the first column, so titles and fields line up across rows.
seamlessboolean—Hides the title and drops the field's own chrome until it is hovered or focused, for inline editing.
topTextboolean—Moves the counter and messages above the field instead of below it.
allowDropFileboolean—Accepts files dropped onto the field.
hideTitleboolean—Hides the title while keeping the rest of the layout.
embeddedboolean—For a field placed inside another component, such as a dropdown: no title, no margin, and horizontal padding.

Events ​

EventPayloadDescription
update:model-value(Model)Value of the clicked option, or null when the pressed one is clicked with allowClear.

Slots ​

SlotPropsDescription
title—Replaces the title text.
subtitle—Content between the title and the options.
option{ option: ValueGetter extends undefined ? Model : Entity; selected: boolean; }Content of an option's button. While readonly, only the pressed option is shown.
right—Content to the right of the options.