Skip to content

df-actions Component ​

df-actions renders a row of actions as buttons or text links, with render options per screen-size breakpoint.

Basic Example ​

A row of actions:

Current breakpoint: xs (Extra Small)

Features ​

  • Renders actions as buttons or text links
  • Supports responsive display based on screen size
  • Icon and label shown per showIcon / showLabel; a button that does not show its label is named by it
  • Grouped button layouts
  • Simple mode: one native button per action, the smallest DOM for many actions on a page
  • Renders @dynamicforms/vue-forms actions
  • defaultConfirm / defaultReject actions are coloured primary / secondary

Props ​

PropTypeDefaultDescription
actionsAction[] or Ref<Action[]>requiredArray of Action objects to render - this library's Action, or a bare @dynamicforms/vue-forms one
buttonSizestring or number'default'Size of buttons (see Vuetify's v-btn size prop)
buttonDensity'default' | 'comfortable' | 'compact''default'Forwarded to each button's density (see Vuetify's v-btn density prop)
showAsGroup'no' | 'grouped' | 'grouped-no-borders''no'Controls how buttons are grouped
simplebooleanfalseRenders each action as one native <button> instead of a v-btn, for the smallest DOM and the fastest render; see Simple mode

Action Object ​

The component expects an array of Action objects created with new Action() with the following structure:

typescript
interface ActionBreakpointOptions {
  name?: string;
  label?: MaybeRefOrGetter<string>;
  icon?: string;
  renderAs?: ActionDisplayStyle;
  showIcon?: boolean;
  showLabel?: boolean;
  defaultConfirm?: boolean;
  defaultReject?: boolean;
  passthroughAttrs?: Record<string, any>;
  xs?: ActionBreakpointRenderOptions;
  sm?: ActionBreakpointRenderOptions;
  md?: ActionBreakpointRenderOptions;
  lg?: ActionBreakpointRenderOptions;
  xl?: ActionBreakpointRenderOptions;
}

The members are described in Action Value Configuration, the breakpoints xs to xl in Responsive Breakpoints.

A breakpoint sets how the action is rendered at that width: renderAs, label, icon, showLabel, showIcon and passthroughAttrs. name, defaultConfirm and defaultReject do not depend on the screen width and are set only in the base options; ActionBreakpointRenderOptions is ActionRenderOptions without them.

passthroughAttrs merges key by key: a breakpoint that sets color keeps the density of the smaller breakpoint.

This library's Action extends the Action class of @dynamicforms/vue-forms with the render options above.

Actions declared in @dynamicforms/vue-forms ​

The component reads its render options from the action's value, not through this subclass's accessors. An Action of @dynamicforms/vue-forms, whose value holds only a label and an icon, therefore renders as a button showing the ones it has. Options the value does not hold take their defaults. A label that is a ref or a function is read while the action renders. A label or icon that is not a string after that is not rendered.

typescript
import { Action } from '@dynamicforms/vue-forms';

const cancel = new Action({ value: { label: 'Cancel' }, actions: [cancelHandler] });

The subclass is needed for breakpoint options, the text-link style and the confirm / reject colours; they are members of ActionRenderOptions, which only it declares.

getRenderOptionsForBreakpoint(value, breakpoint) returns the ResolvedActionRenderOptions a value renders as at one breakpoint: ActionRenderOptions with the label read, defaults filled in and label / icon filtered by their flags. Its accessibleLabel is the plain text of the label whether showLabel is set or not, and undefined where the label is missing or empty. Action.getBreakpointValue(breakpointRef) is a computed() over the same call.

Creating Actions ​

Actions are created with the Action constructor:

typescript
import { Action } from '@dynamicforms/vuetify-inputs';
import { ExecuteAction } from '@dynamicforms/vue-forms';

const saveAction = new Action({
  value: {
    name: 'save',
    label: 'Save',
    icon: 'ion-save-outline',
    renderAs: 'button',
    showIcon: true,
    showLabel: true
  },
  actions: [saveFormAction] // ExecuteAction handlers that run when the action is executed
});

Action Value Configuration ​

The value object defines the visual appearance and behaviour:

PropertyTypeDescription
namestringUnique identifier for the action
labelMaybeRefOrGetter<string>Display text. A ref or a function is read while the action renders, so () => t('Save') follows the locale
iconstringIcon name, resolved by vue-cached-icon; both ion- and mdi- prefixed names work
renderAsActionDisplayStyleHow to render: 'button' or 'text'
showIconbooleanWhether to display the icon
showLabelbooleanWhether to display the label. A button that does not display it has the label's plain text as its aria-label and title
defaultConfirmbooleanMarks this as the "confirm" action of the set; colours the v-btn primary in <df-actions> (unless overridden via passthroughAttrs.color); no colour in simple mode
defaultRejectbooleanMarks this as the "reject/dismiss" action of the set; colours the v-btn secondary in <df-actions> (unless overridden via passthroughAttrs.color); no colour in simple mode
passthroughAttrsRecord<string, any>Extra props/attrs forwarded to the rendered <v-btn> (e.g. color, density, rounded, block, prependIcon), overriding <df-actions>'s own computed props; in simple mode HTML attributes of the <button> (e.g. class, style, aria-describedby), where v-btn props have no effect

icon is an accessor of @dynamicforms/vue-forms: it reads the member of the same name from the value, and a write to it is a value change. label is this subclass's accessor over the same member: it returns the string the member gives now, reading a ref or calling a function, and a write to it is a value change. defaultConfirm and defaultReject are read-only accessors of vue-forms: each reads the member of the same name from the value and returns false where it is unset. renderedLabel and renderedIcon are this subclass's: the text where showLabel is true, the icon name where showIcon is true, and undefined otherwise. showLabel and showIcon return false where the label or icon is missing or empty, regardless of the value. The breakpoint-resolved options <df-actions> renders from are filtered the same way; the component reads none of these accessors.

access, busy and visibility aren't part of ActionRenderOptions - they're standard Action/Field members of @dynamicforms/vue-forms (access and visibility are set at the top level of the new Action() parameters or through action.access / action.visibility; busy is read-only). <df-actions> applies them:

  • the button binds executable (<v-btn :disabled="!action.executable">). It is disabled where access is other than 'editable' on the action or a container above it, while busy is true, and while any ExecuteAction handler of the action returns false from canExecute() - a SubmitAction does while its target is invalid or a validation is running.
  • busy renders the button loading until every run of the action has settled.
  • visibility: 'invisible' keeps the button in the layout with an invisible class (visibility: hidden).
  • visibility: 'hidden' keeps the button in the DOM with a d-none class.
  • visibility: 'suppress' removes the button from the rendered list entirely.

ActionDisplayStyle ​

ActionDisplayStyle is 'button' | 'text':

  • 'button': a Vuetify button with a background (the default, defaultDisplayStyle)
  • 'text': a text link without a background

Any other renderAs throws an Error naming the value when the action is rendered. isActionDisplayStyle(value) returns whether a value is one of the two, and actionDisplayStyles lists them.

Responsive Breakpoints ​

A breakpoint key holds the options that differ at that screen width:

typescript
const saveAction = new Action({
  value: {
    name: 'save',
    label: 'Save',
    icon: 'ion-save-outline',
    renderAs: 'button',
    showIcon: true,
    showLabel: false,
    md: { showLabel: true, showIcon: false },
    lg: { showIcon: true },
  },
  actions: [formSaveAction],
});

With this configuration:

  • xs and sm: only the icon is shown
  • md: only the label is shown
  • lg and xl: the icon and the label are shown

A breakpoint inherits the options it does not set from the smaller ones; see How a breakpoint is resolved.

The current breakpoint is Vuetify's display breakpoint (useDisplay()), so the widths are the application's display.thresholds. With Vuetify's default thresholds, sm starts at 600 px, md at 840 px, lg at 1145 px and xl at 1545 px. Vuetify's xxl renders the xl options.

Action Execution ​

Actions are executed through the actions array, which holds FieldActionBase handlers from @dynamicforms/vue-forms; the one that runs on execution is ExecuteAction:

typescript
import { ExecuteAction } from '@dynamicforms/vue-forms';

// Create the execution logic
const saveFormAction = new ExecuteAction(async (action, supr, params) => {
  await saveDocument();
  return supr(action, params); // continue with the next handler in the chain
});

// Attach to Action
const saveAction = new Action({
  value: { /* visual config */ },
  actions: [saveFormAction]
});

Awaiting a run ​

action.execute(params?) runs the ExecuteAction chain and returns a promise of the chain's result. The chain is entered synchronously: a handler has run by the time execute() returns. A handler that throws rejects the promise; execute() itself does not throw:

typescript
try {
  await saveAction.execute();
  showSuccessMessage('Document saved successfully');
} catch (error) {
  showErrorMessage('Failed to save document');
}

A call that neither awaits the promise nor attaches a .catch() leaves the rejection unhandled; the action records nothing of it. <df-actions> calls execute(event) from a template event handler, and Vue catches the promise such a handler returns, so the rejection goes to Vue's error handling. To show the user what failed, catch it in the ExecuteAction handler.

See handling a failed run for the whole contract.

Reporting a run in flight ​

action.busy is true from the call to execute() until the run settles, whether it resolves or rejects; overlapping runs are counted, so it stays true until the last of them settles. <df-actions> binds it: the button is disabled and rendered loading while it is true, so a click cannot start a second run.

execute() does not read executable, so only the click is prevented: a programmatic execute() runs regardless, and an action that refuses an overlapping run does so in its own handler.

Default Confirm / Reject Actions ​

defaultConfirm and defaultReject mark the "confirm" action of a set (e.g. Save, Yes, OK) and the "reject/dismiss" one (e.g. Cancel, No). <df-actions> colours them primary and secondary by default:

typescript
const yes = new Action({ value: { name: 'yes', label: 'Yes', defaultConfirm: true } }); // coloured primary
const no = new Action({ value: { name: 'no', label: 'No', defaultReject: true } });     // coloured secondary

// A single close action can be both
const close = new Action({ value: { name: 'close', label: 'Close', defaultConfirm: true, defaultReject: true } });

At most one action in a given set should set defaultConfirm, and at most one should set defaultReject.

<df-modal> of @dynamicforms/vuetify-modal-form-kit reads the same flags from the actions in its actions prop to select the actions of Enter and Escape. Its actions slot renders through <df-actions>, so the keyboard shortcut and the button colour are set by the same flag.

Passthrough Attributes ​

passthroughAttrs passes props to the rendered <v-btn> and takes precedence over <df-actions>'s computed props (variant, color, disabled, loading, and the aria-label and title of a button that does not show its label). It covers any <v-btn> prop that ActionRenderOptions does not:

typescript
const deleteAction = new Action({
  value: {
    name: 'delete',
    label: 'Delete',
    icon: 'ion-trash-outline',
    renderAs: 'button',
    showIcon: true,
    showLabel: true,
    passthroughAttrs: { color: 'error', variant: 'flat' },
  },
  actions: [deleteFormAction],
});

Complete Example ​

typescript
import { Action } from '@dynamicforms/vuetify-inputs';
import { ExecuteAction } from '@dynamicforms/vue-forms';

// Business logic
const submitFormAction = new ExecuteAction(async (action, supr, params) => {
  await api.submitForm(form.value);
  router.push('/success');
  return supr(action, params);
});

// Presentation
const submitAction = new Action({
  value: {
    name: 'submit',
    label: 'Submit Form',
    icon: 'ion-checkmark-outline',
    renderAs: 'button',
    showIcon: true,
    showLabel: true,
  },
  actions: [submitFormAction]
});

form here is a Group: value is what it sends, and fullValue what it holds, disabled members included. Each member's access sets what value contains for it; visibility affects neither.

Button Grouping ​

showAsGroup sets the grouping of buttons:

  • 'no': Buttons are displayed as separate elements
  • 'grouped': Buttons are grouped with borders
  • 'grouped-no-borders': Buttons are grouped without borders

Simple mode ​

Simple mode exists for render speed: it keeps the DOM of each action as small as possible. Each action is one native <button type="button"> holding the icon and the label, with no Vuetify component; a v-btn is a component instance with overlay, underlay and content elements around the same icon and label. Use it where many actions render at once, such as an action column in a grid.

The button is inline, without background or border, in the colour and font of the surrounding text, with a :focus-visible outline.

vue
<df-actions :actions="actions" simple />

The same as in the Vuetify mode:

  • the icon and the label are shown per showIcon / showLabel at the current breakpoint;
  • a button that does not show its label has the label's plain text as its aria-label and title;
  • passthroughAttrs are bound to the <button> and override the attributes <df-actions> sets (disabled, aria-busy, aria-label, title), so they take HTML attributes here, not v-btn props;
  • the button is disabled where the action is not executable, which includes a run in flight, and carries aria-busy="true" during the run;
  • a click calls execute(event);
  • visibility applies the same classes, and 'suppress' removes the button.

Different from the Vuetify mode:

  • a run in flight shows no spinner;
  • renderAs, the defaultConfirm / defaultReject colours, buttonSize and buttonDensity do not apply.

showAsGroup applies in simple mode as well: 'grouped' and 'grouped-no-borders' join the buttons without gaps inside a container with rounded corners, and 'grouped' draws a border in the text colour around the container and between the buttons.

Usage with DynamicForms ​

vue
<template>
  <df-actions :actions="actions" button-size="small" />
</template>

<script setup>
  import { ExecuteAction } from '@dynamicforms/vue-forms';
  import { Action } from '@dynamicforms/vuetify-inputs';

  // Create form action
  const saveFormAction = new ExecuteAction((action, supr, params) => {
    // Your save logic here
    console.log('Save action executed');
    return supr(action, params);
  });

  // Create actions for the component
  const actions = ref([
    new Action({
      value: {
        name: 'save',
        label: 'Save',
        icon: 'ion-save-outline',
        renderAs: 'button',
        showIcon: true,
        showLabel: true
      },
      actions: [saveFormAction]
    }),

    new Action({
      value: {
        name: 'cancel',
        label: 'Cancel',
        icon: 'ion-close-outline',
        renderAs: 'button',
        showIcon: true,
        showLabel: true
      }
    })
  ]);
</script>

Released under the MIT License.