Select with Custom Menu Position

PreviousNext

A select component with custom menu position

Docs
shadcnui-blockscomponent

Preview

Loading preview…
components/customized/select/select-09.tsx
import * as React from "react";

import {
  Select,
  SelectContent,
  SelectGroup,
  SelectItem,
  SelectLabel,
  SelectTrigger,
  SelectValue,
} from "@/registry/ui/select";
import { Label } from "@/registry/ui/label";

export default function SelectMenuPositionDemo() {
  return (
    <div className="grid sm:grid-cols-2 gap-3 w-full">
      <div className="grow">
        <Label className="mb-2 block">Popper (Default)</Label>
        <Select defaultValue="apple">
          <SelectTrigger className="w-full">
            <SelectValue placeholder="Select a fruit" />
          </SelectTrigger>
          <SelectContent position="popper">
            <SelectGroup>
              <SelectLabel>Fruits</SelectLabel>
              <SelectItem value="apple">Apple</SelectItem>
              <SelectItem value="banana">Banana</SelectItem>
              <SelectItem value="blueberry">Blueberry</SelectItem>
              <SelectItem value="grapes">Grapes</SelectItem>
              <SelectItem value="pineapple">Pineapple</SelectItem>
            </SelectGroup>
          </SelectContent>
        </Select>
      </div>
      <div className="grow">
        <Label className="mb-2 block">Item Aligned</Label>
        <Select defaultValue="apple">
          <SelectTrigger className="w-full">
            <SelectValue placeholder="Select a fruit" />
          </SelectTrigger>
          <SelectContent position="item-aligned">
            <SelectGroup>
              <SelectLabel>Fruits</SelectLabel>
              <SelectItem value="apple">Apple</SelectItem>
              <SelectItem value="banana">Banana</SelectItem>
              <SelectItem value="blueberry">Blueberry</SelectItem>
              <SelectItem value="grapes">Grapes</SelectItem>
              <SelectItem value="pineapple">Pineapple</SelectItem>
            </SelectGroup>
          </SelectContent>
        </Select>
      </div>
    </div>
  );
}

Installation

npx shadcn@latest add @shadcnui-blocks/select-09

Usage

import { Select09 } from "@/components/select-09"
<Select09 />