← Blog
24 Nov 2026VueDropdown PickerForm StateAccessibility

Dropdown Picker in Vue: Labels, Values, and Form State

Build a dropdown picker in Vue 3 with stable labels and values, v-model, form submission, resets, async option handling, and keyboard checks.

Dropdown Picker in Vue: Labels, Values, and Form State

TL;DR

To build a dependable dropdown picker in Vue, give every option a stable value and a readable label, bind the selected value with v-model, and submit the value rather than the label. Define clear rules for initial selection, clearing, resetting, and refreshed options. Start with a native select when it fits the task, then verify the data and keyboard behavior before introducing a custom control.

A dropdown can display “Design system” while the application stores design. Keeping those two things separate is the foundation of this guide. The interesting failures happen later: an edit form loads an old ID, a reset changes only the visible field, or a refreshed list no longer contains the selected option.

We will build a single-selection Vue example that makes those transitions explicit. The emphasis is the selection’s lifecycle, not recreating a component library’s API or implementing a searchable combobox from scratch.

Table of contents

Before you start

You need a Vue 3 project that compiles Single-File Components and supports <script setup>, plus basic familiarity with reactive state and templates. The example uses native HTML controls and Vue, with no additional component package.

Our inputs are a complete list of options with unique, nonempty string values and an initial selected ID. We reserve the empty string for “no selection.” The form prepares a local payload preview; it does not send a network request.

Use this as a single-instance page example. When extracting a reusable field, supply unique control and description IDs for each instance. API integration, application styling, and server-side error presentation remain application-specific.

1. Choose the right selection control

For this example, a native <select> is enough: users choose one workspace from a known list. Its option values and field name map directly to ordinary HTML form data. The HTML select reference explains that relationship.

Choose the interaction before choosing the surface appearance:

User need Starting point What to verify
Choose one plain option with platform-managed interaction Native select Label, selected value, required state, and submitted field
Compare visible choices with descriptions or other presentation Custom listbox Focus movement, selected state, accessible naming, and form integration
Type to narrow a set of choices Editable combobox Query state, result filtering, selection, and popup behavior

A listbox is not automatically a dropdown. It may remain visible, and its keyboard focus can differ from its selected value. W3C’s listbox pattern documents that distinction and warns against putting interactive buttons or links inside options.

Check: describe what the user needs to do without referring to a chevron or a visual mockup. If typing is not part of the task, do not add search state just to make the field look more sophisticated. If users need interactive actions within each row, reconsider whether a listbox is the correct pattern.

2. Separate option labels from stable values

Define the data contract before binding the control:

Visible label Stored value
Design system design
Marketing site marketing
Internal tools tools

The label answers “What should the person read?” The value answers “Which record or enum does the application mean?” We keep them separate so a wording change does not require rewriting saved selections.

Option data maps the label Design system to the visible field and the value design to the workspaceId form payload.

Use a stable record ID or an explicitly defined enum value, not the option’s current array position. Reordering a list should not change the meaning of an existing selection. Similarly, two options may have similar display names without being the same record.

For this implementation, use strings consistently across the option data, initial ID, and submitted field. A numeric ID received from an API should be normalized deliberately at the data boundary rather than compared inconsistently with a string elsewhere.

Expected result: changing the label from “Design system” to “Design workspace” leaves the stored value design unchanged.

If the field looks empty despite having a selected ID, first compare that ID with the actual option values. Vue’s form binding documentation notes that an unmatched initial value leaves the select unselected. An index, a label, or a mismatched value type is a data problem, not a styling problem.

3. Bind and submit a complete Vue dropdown picker

Place the following component in App.vue in your existing Vue project. It includes the field, a payload preview, explicit clear and reset actions, and a simulated authoritative refresh that removes the initial workspace.

The implementation uses Vue’s documented reactive refs, computed properties, event handlers, and keyed list rendering. It is intentionally unstyled so the state behavior remains easy to inspect.

<script setup>
import { computed, ref } from 'vue';

const initialId = 'design';
const makeInitialOptions = () => [
  { value: 'design', label: 'Design system' },
  { value: 'marketing', label: 'Marketing site' },
  { value: 'tools', label: 'Internal tools' },
];

const options = ref(makeInitialOptions());
const selectedId = ref(initialId);
const notice = ref('');
const submittedId = ref('');

const selectedOption = computed(() =>
  options.value.find((option) => option.value === selectedId.value)
  ?? null
);

function onSelectionChange() {
  notice.value = '';
  submittedId.value = '';
}

function clearSelection() {
  selectedId.value = '';
  submittedId.value = '';
  notice.value = 'Selection cleared.';
}

function resetSelection() {
  options.value = makeInitialOptions();
  selectedId.value = initialId;
  submittedId.value = '';
  notice.value = 'Initial selection restored.';
}

function replaceOptions(nextOptions) {
  const previousId = selectedId.value;
  options.value = nextOptions;
  submittedId.value = '';

  if (previousId && !nextOptions.some(
    (option) => option.value === previousId
  )) {
    selectedId.value = '';
    notice.value = 'That workspace is no longer available. Choose another.';
  } else {
    notice.value = 'Options updated.';
  }
}

function simulateRefresh() {
  replaceOptions([
    { value: 'marketing', label: 'Marketing site' },
    { value: 'tools', label: 'Internal tools' },
  ]);
}

function submit(event) {
  if (!selectedOption.value) {
    notice.value = 'Choose an available workspace.';
    return;
  }

  const value = new FormData(event.currentTarget).get('workspaceId');
  if (value !== selectedId.value) {
    notice.value = 'Selection changed. Please try again.';
    return;
  }

  submittedId.value = value;
  notice.value = 'Payload prepared locally. Nothing has been sent.';
}
</script>

<template>
  <form @submit.prevent="submit">
    <label for="workspace">Workspace (required)</label>
    <p id="workspace-help">Choose where this item belongs.</p>

    <select
      id="workspace"
      v-model="selectedId"
      name="workspaceId"
      required
      aria-describedby="workspace-help workspace-notice"
      @change="onSelectionChange"
    >
      <option disabled value="">Choose a workspace</option>
      <option
        v-for="option in options"
        :key="option.value"
        :value="option.value"
      >
        {{ option.label }}
      </option>
    </select>

    <p>Selected ID: <code>{{ selectedId || '(empty)' }}</code></p>
    <p>Selected label: {{ selectedOption ? selectedOption.label : 'None' }}</p>
    <p id="workspace-notice" role="status">{{ notice }}</p>

    <button type="button" @click="clearSelection">Clear</button>
    <button type="button" @click="resetSelection">Reset demo</button>
    <button type="button" @click="simulateRefresh">Refresh options</button>
    <button type="submit">Prepare payload</button>

    <p v-if="submittedId">
      Payload preview: workspaceId = <code>{{ submittedId }}</code>
    </p>
  </form>
</template>

There are two separate connections here. v-model synchronizes the native select with selectedId; name="workspaceId" gives the field its submission key. Vue uses the select’s value and change event for this binding, and treats JavaScript state as the initial source of truth, as described in Form Input Bindings.

The FormData constructor reads named, successful controls from the form. Its get method retrieves the value for our key. Disabled controls are excluded, so disabling a field is not a way to submit a locked value.

Check: choose Marketing site and prepare the payload. Both the displayed ID and payload preview should read marketing, while the label remains “Marketing site.” Nothing should navigate or make a network request.

For a visual companion, Codevolution’s Vue 3 form-handling lesson provides background on form binding. The reset and changing-option policies in this guide are additional application decisions.

4. Make initial selection, clearing, and resetting explicit

An edit form should start from the saved ID, not whichever option happens to appear first. In our fixture, initialId is design. For a create form that requires an intentional choice, initialize the model to the empty string instead.

Do not combine v-model with competing selected attributes. Vue’s binding guidance makes the bound JavaScript state authoritative.

Clear and reset have different meanings:

  • Clear moves the model to the empty value and removes the previous payload preview.
  • Reset restores a defined baseline, including any related state your form owns.
  • Changing a selection invalidates the old preview because that preview no longer describes the field.

The demo’s Reset button restores the original fixture options as well as the initial ID, making repeated experiments possible. A production reset should use the current authoritative option set. It must not resurrect a choice that has actually been removed or revoked.

We use an explicit type="button" handler for reset, so its effect on Vue state is visible in the component. Keep any native reset action coordinated with that same model rather than introducing a second reset path.

Verification sequence: choose Marketing site, clear it, and attempt submission. The first, empty-valued placeholder and required constraint should prevent successful submission. Then reset the demo and confirm that Design system returns. The select documentation explains the required single-select placeholder behavior.

If the model returns to its baseline but the label does not, inspect whether the corresponding option exists in the current list. Resetting an ID cannot create its missing label.

5. Reconcile changing and asynchronously loaded options

The replaceOptions function implements one explicit policy: preserve a selection if its ID still exists in the new complete list; otherwise clear it and explain the change. Try Refresh options while Design system is selected. The model should become empty rather than silently switching to Marketing site.

When a complete option list changes, retain a matching selected ID or clear a missing ID and explain the change before submission.

Now reset, choose Internal tools, and refresh again. Because tools remains available, that selection should survive. A label change with the same ID should also preserve the selection, while the computed display follows the updated option data.

Distinguish loading from a confirmed empty result

The example refresh is synchronous. When connecting an API, add loading and error state around the same reconciliation boundary:

Incoming state Recommended selection policy
Request pending Preserve the existing selection; show loading and block premature submission
Complete list received Reconcile the selected ID against that accepted list
Successful response with no options Explain that no choices are available; clear or mark the selection unavailable according to product rules
Request failed Preserve existing data where appropriate and offer retry; do not treat failure as an empty list

Calling replaceOptions([]) merely to show a spinner would incorrectly invoke the “no longer available” policy. Keep loading separate from option data.

Also distinguish a complete option set from a filtered page of results. An ID missing from the current search page has not necessarily been deleted. Retain the selected record separately or resolve it by ID before concluding that it is invalid.

Prevent older responses from overwriting newer state

For dependent fields, associate each request with its parent selection and a request version. Apply a response only if it still belongs to the current parent and latest request. Apply the same guard to errors and loading completion, not just successful results.

Resetting or changing the edited record should invalidate pending work too. Otherwise, a late response can overwrite the state the user just restored. These request guards are application logic, not behavior supplied by the synchronous example.

Finally, revalidate the submitted ID and the user’s permission on the server. A permitted choice in the browser is not authorization; OWASP recommends checking permissions on every request.

6. Verify keyboard access and the selected-value contract

Test the finished field through a complete interaction, not only by setting its ref in development tools. Our visible label uses matching for and id values, following W3C’s labeling guidance.

For the native example, check these outcomes:

  1. Reach the select with Tab and confirm that focus is visible.
  2. Choose another option using the platform’s keyboard interaction, then leave the field normally.
  3. Confirm that the spoken and visible label identify Workspace and that the current choice is understandable.
  4. Prepare the payload and compare its ID with the visible choice.
  5. Clear and reset the selection, checking both the field and status feedback with a screen reader.
  6. Refresh once with a retained ID and once with a removed ID. Confirm the documented policy in both cases.

Record the browser, operating system, and assistive technology used. Do not impose one universal open-and-close key sequence on every native platform.

When adapting the data model to a custom component, check its value contract before assuming it emits a scalar ID. Vue’s default component v-model contract uses a modelValue prop and an update:modelValue event; the component determines what value it sends.

For a custom listbox, verify arrow-key navigation, an accessible name, and exposed selected state against the WAI-ARIA pattern. Focus and selection are distinct. Test dismissal and return focus when the control actually has a popup, rather than assuming every listbox has a trigger.

Keep these checks alongside regression cases for renamed labels, reordered options, removed IDs, and late responses. A visually correct field can still submit the wrong identifier.

Put the selection contract into your application

We now have a field whose visible label, selected ID, and payload can be checked independently, with deliberate rules for clear, reset, and option replacement. The next useful action is to run the example in your application and connect one real option source without weakening those rules.

Compare our Native Select playground when platform picker behavior matters. Explore our Listbox examples when visible choices need richer presentation. Whichever control you choose, keep the label-to-value relationship and verification cases intact.

Sources

Recommended Reads