Fields

Select

One or more values from a fixed list of options.
The select field in the admin

Example

cms/collections/posts.ts
export const posts = defineCollection({
  fields: {
    category: { type: "select", options: ["news", "guide"], required: true },
    tags: { type: "select", options: ["vue", "react", "astro"], many: true },
    color: {
      type: "select",
      options: [
        { value: "brand", label: "Brand color" },
        { value: "muted", label: "Muted" },
      ],
    },
  },
});

The type of a read is the union of the values:

post.category; // "news" | "guide"
post.tags; // ("vue" | "react" | "astro")[] | null | undefined
post.color; // "brand" | "muted" | null | undefined
  • An option is a string, or { value, label } when the label in the admin should differ from the stored value.
  • A label can be translated: { value: "brand", label: { en: "Brand color", de: "Markenfarbe" } }.

Render it

---
const categories = { news: "News", guide: "Guide" };
---

<article class={`category-${post.category}`}>
  <span>{categories[post.category]}</span>
  <ul>
    {post.tags?.map((tag) => <li>#{tag}</li>)}
  </ul>
</article>

A read returns the stored value, not the label. Map it to a label in your site, as above. Because the type is a union, TypeScript checks that the map covers every value.

Many values

many: true stores a list of distinct values. With required, the list needs at least one value:

The select-many field in the admin

A many select cannot be filtered and cannot be unique.

Appearance

appearance picks the input in the admin:

AppearanceInputFits
"dropdown" (default)A menu. With many, a combobox with chipsMany options
"list"Radio buttons, or checkboxes with manyA few options
"buttons"A row of toggle buttonsTwo to five short options
align: { type: "select", options: ["left", "center", "right"], appearance: "buttons" },
The select-buttons field in the admin
The select-list field in the admin

Options

The allowed values.Store a list of values instead of one. Default false.The input in the admin. Default "dropdown".