WlRadio

Radio button; value is the option value and v-model is the selection.
Components / Inputs v0.1.0

States

Full example
<script setup lang="ts">
import { WlRadio } from "legato-ui";
import { useWlId } from "legato-ui/composables";
import { ref } from "vue";
const value = ref<string>("team");
const name = `example-access-${useWlId()}`;
</script>

<template>
  <div class="wl-stack" data-space="md">
    <WlRadio
      v-model="value"
      value="team"
      :name="name"
      size="sm"
      
    >{{ "Entire team" }}</WlRadio><WlRadio
      v-model="value"
      value="private"
      :name="name"
      size="sm"
      
    >{{ "Only me" }}</WlRadio>
  </div>
</template>

Size and density

Full example
<script setup lang="ts">
import { WlRadio } from "legato-ui";
import { useWlId } from "legato-ui/composables";
import { ref } from "vue";
const value = ref<string>("team");
const name = `example-access-${useWlId()}`;
</script>

<template>
  <div class="wl-stack" data-space="md">
    <WlRadio
      v-model="value"
      value="team"
      :name="name"
      size="sm"
      
    >{{ "Entire team" }}</WlRadio><WlRadio
      v-model="value"
      value="private"
      :name="name"
      size="sm"
      
    >{{ "Only me" }}</WlRadio>
  </div>
</template>

Selection groups

Two groups with a shared name within each, slot labels, required selection, invalid and an unavailable option.

One value for the entire group

A shared name groups native radio inputs. Arrow keys change the selection within the group; Space selects the focused item.

Required selection and invalid

Access: team. Format: not selected.

Full example
<script setup lang="ts">
import { WlButton, WlRadio } from "legato-ui";
import { ref } from "vue";
const visibility = ref<string>("team");
const format = ref<string | null>(null);
</script>

<template>
  <div class="wl-stack" data-space="xl" data-input-example="WlRadio">
    <fieldset class="docs-radio-group wl-stack" data-space="md">
      <legend class="wl-text-subheading">{{ "One value for the entire group" }}</legend>
      <WlRadio v-model="visibility" name="docs-input-visibility" value="personal">{{ "Only me" }}</WlRadio>
      <WlRadio v-model="visibility" name="docs-input-visibility" value="team">{{ "Team" }}</WlRadio>
      <WlRadio
        v-model="visibility"
        name="docs-input-visibility"
        value="public"
        disabled
      >{{ "Everyone — temporarily unavailable" }}</WlRadio>
      <p class="wl-text-small wl-text-muted">{{ "A shared name groups native radio inputs. Arrow keys change the selection within the group; Space selects the focused item." }}</p>
    </fieldset>
    <fieldset class="docs-radio-group wl-stack" data-space="md" :aria-describedby="format == null ? 'docs-radio-error' : undefined">
      <legend class="wl-text-subheading">{{ "Required selection and invalid" }}</legend>
      <WlRadio
        v-model="format"
        name="docs-input-format"
        value="pdf"
        :invalid="format == null"
        :aria-describedby="format == null ? 'docs-radio-error' : undefined"
        required
      >{{ "PDF document" }}</WlRadio>
      <WlRadio
        v-model="format"
        name="docs-input-format"
        value="text"
        :invalid="format == null"
        :aria-describedby="format == null ? 'docs-radio-error' : undefined"
        required
      >{{ "Text file" }}</WlRadio>
      <p
        v-if="format == null"
        id="docs-radio-error"
        class="wl-text-small"
        role="alert"
      >{{ "Choose an export format." }}</p>
    </fieldset>
    <WlButton size="sm" @click="visibility = 'team'; format = null">{{ "Reset groups" }}</WlButton>
    <p class="wl-text-small" role="status">{{
      "Access:"
    }} {{
      visibility
    }}{{
      ". Format:"
    }} {{
      format ?? "not selected"
    }}.</p>
  </div>
</template>

<style scoped>
.docs-radio-group { min-width: 0; margin: 0; padding: 0; border: 0; }
.docs-radio-group legend { margin-bottom: var(--wl-space-md); }
</style>