Label4.0
Labels provide accessible text for form controls and other interactive elements.
Ads by Tryg Careers
Installation
npm i @tryg/vue-ui-libraryUsage
Install the component library as a Vue plugin. This globally registers all Anchor components.
import { createApp } from 'vue';
import { ComponentLibrary } from '@tryg/vue-ui-library';
import App from './App.vue';
const app = createApp(App);
app.use(ComponentLibrary);
app.mount('#app');<template>
<anchor-label>Label text</anchor-label>
</template>Import only the components you need for optimal bundle size.
<script setup>
import { AnchorLabel } from '@tryg/vue-ui-library';
</script>
<template>
<anchor-label>Label text</anchor-label>
</template>Associating with an input
Pass the for prop to associate the label with a form control. The value should match the id attribute of the target input element. If the input is nested inside the label, this prop can be omitted.
<template>
<anchor-label for="my-input">Associated label</anchor-label>
</template>Slots
- Default: The text content of the label.
Accessibility
- Properly associates form controls with their labels using the
forattribute. - When an input is nested inside the label, the association is implicit and no
forattribute is needed. - Screen readers announce the label text when users focus the associated control.
API
anchor-label
Properties
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
for | for | Match this with an input id to create a label + input pair. Leave this field empty or unset if the input field is nested inside the label | string | null |
Dependencies
Used by
- anchor-checkbox
- anchor-progress-bar
- anchor-progress-indicator
- anchor-progress-indicator-step
- anchor-quantity
- anchor-radio
- anchor-select
- anchor-textarea
- anchor-toggle
Graph
graph TD;
anchor-checkbox --> anchor-label
anchor-progress-bar --> anchor-label
anchor-progress-indicator --> anchor-label
anchor-progress-indicator-step --> anchor-label
anchor-quantity --> anchor-label
anchor-radio --> anchor-label
anchor-select --> anchor-label
anchor-textarea --> anchor-label
anchor-toggle --> anchor-label
style anchor-label fill:#f9f,stroke:#333,stroke-width:4pxBuilt with StencilJS
