Skip to content

Latest commit

 

History

History
85 lines (63 loc) · 4.06 KB

button.md

File metadata and controls

85 lines (63 loc) · 4.06 KB

Button

Button renders one immediate action as a native button or one explicit navigation action as an anchor. Vue and Vanilla templates produce the same significant DOM and consume the shared cm-button CSS contract.

CSS

Vue applications load the npm token and component styles:

import '@codemonster-ru/ui-tokens/tokens.css';
import '@codemonster-ru/ui-css/styles.css';

Vanilla applications load the shared styles in this order:

<link rel="stylesheet" href="/vendor/codemonster-ui/css/tokens/tokens.css" />
<link rel="stylesheet" href="/vendor/codemonster-ui/css/css/styles.css" />

Keep the imported files beside each entry. AssetPublisher publishes the complete integrity-checked graph.

Props

Prop Values Default Behavior
variant primary, secondary, success, info, warn, help, danger, contrast, ghost primary Visual action emphasis.
size sm, md, lg md Shared control height and spacing.
type button, submit, reset button Native button type; ignored in link mode.
href non-empty string or null null A non-empty value selects native anchor mode.
block boolean false Fills the available inline width.
disabled boolean false Prevents button or link activation.
loading boolean false Shows busy state and prevents activation.

Unknown safe attributes reach the semantic root. Consumer classes are appended after the stable contract classes and deduplicated. Component-owned type, href, disabled, busy, and link ARIA state cannot be overridden through the attribute bag.

Slots

The required default slot supplies the visible label and accessible name. Optional leading and trailing slots render inside fixed icon regions. Loading suppresses leading, shows an aria-hidden spinner in its place, and keeps the label unchanged. Consumers must apply aria-hidden="true" to decorative authored icons.

Vue

<script setup lang="ts">
import { ref } from 'vue';
import { CmButton } from '@codemonster-ru/ui-vue';

const saving = ref(false);
</script>

<template>
  <CmButton type="submit" variant="primary" :loading="saving" data-testid="save">
    <template #leading><SaveIcon aria-hidden="true" /></template>
    Save
  </CmButton>

  <CmButton href="/docs" variant="ghost">Documentation</CmButton>
</template>

Vue forwards native listeners to enabled roots. Disabled native buttons rely on browser behavior; disabled links omit href, expose role="link" and aria-disabled="true", and suppress the consumer click handler.

Vanilla HTML

Use the canonical HTML for button. Add cm-button--block to fill the available width.

Forms and accessibility

  • The default type="button" avoids accidental form submission; use submit explicitly.
  • name, value, form, and other valid native attributes are forwarded in button mode.
  • Loading uses native disabled plus aria-busy="true" and does not create a live region.
  • Disabled links have no navigable href and are removed from normal link keyboard activation.
  • Provide a non-empty visible label or a valid native accessible naming attribute.
  • Focus indication and forced-color behavior come from the shared stylesheets.