sterling-svelte  2.0.7
A modern, accessible, lightweight UI component library for Svelte.

Label

A caption naming or describing a form element.

Code
<script lang="ts">
  import { Label } from '@geoffcox/sterling-svelte';
</script>

<Label vertical="undefined">sterling-svelte</Label>

Members

Property NameTypeDefaultComment
formValidationbooleanfalseIf true, then the message will be set using form validation on the child component. The required indicator will be displayed if the child component is required.
forwardClickstringfalseIf true, clicking the label invokes a click on the content. Typically used when for/id pairs are not present.
onValidationLabelValidationCallback | undefinedundefinedRaised when form validation is checked. Provides control over the validation message and class.
messagestring | Snippet''The status message to display.
requiredstringfalseWhen true, the label will indicate a value is required.
requiredIndicatorstring | Snippet''The indicator to display when required. Defaults to '*'
requiredReasonstring | Snippet''The reason a value is required.
textstring | Snippet''The text to display in the label.

Types

Type NameDefinitionComment
LabelValidationCallback(validity: ValidityState,validationMessage: string) => LabelValidationResult | undefinedThe validity and validation message are provided by form validaiton on the child component.
LabelValidationResult{valid: boolean; validationClass?: string; validationMessage?: Snippet | string;}The validation class will be applied to the label. The validation message will be displayed as the message.

Considerations

  • An optional message and status can provide information to the user about their value.
  • The required property and requiredReason indicate the user must fill in a value and why.
  • Includes HTMLLabelElement props, events, and methods.

Anatomy

<label class="sterling-label">
  <div class="text">
    {@render text()}
  </div>
  <div class="content">
    {@render children()}
  </div>
  <div class="message">
    {@render message()}
  </div>
  <Tooltip>
    <div class="required">
      {@render requiredIndicator()}
    </div>
    {#snippet tip()}
      {@render requiredReason()}
    {/snippet}
  </ToolTip>
</label>