Select
Forms
Dropdown selection with pixel borders.
Installation
npm install @radix-ui/react-selectImport
import { PixelSelect, PixelSelectTrigger, PixelSelectValue, PixelSelectContent, PixelSelectItem } from "@/components/ui/pixel-select"Usage
Component Source
Copy and paste the following code into your project at /src/components/ui/pixel-select.tsx
"use client";
import * as SelectPrimitive from "@radix-ui/react-select";
import { Check, ChevronDown, ChevronUp } from "lucide-react";
import * as React from "react";
import { cn } from "@/lib/utils";
const PixelSelect = SelectPrimitive.Root;
const PixelSelectGroup = SelectPrimitive.Group;
const PixelSelectValue = SelectPrimitive.Value;
const PixelSelectTrigger = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
>(({ className, children, ...props }, ref) => (
<SelectPrimitive.Trigger
ref={ref}
className={cn(
"flex h-12 w-full items-center justify-between pixel-borders border-[3px] border-black bg-white px-4 py-3 text-sm placeholder:text-black/50 focus:outline-none focus:ring-2 focus:ring-[#ff8c00] disabled:cursor-not-allowed disabled:opacity-50 dark:border-[#ff8c00] dark:bg-[#1a1a1a] dark:text-white transition-none duration-0",
className,
)}
{...props}
>
{children}
<SelectPrimitive.Icon asChild>
<ChevronDown className="h-4 w-4 opacity-50" />
</SelectPrimitive.Icon>
</SelectPrimitive.Trigger>
));
PixelSelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
const PixelSelectScrollUpButton = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
>(({ className, ...props }, ref) => (
<SelectPrimitive.ScrollUpButton
ref={ref}
className={cn(
"flex cursor-default items-center justify-center py-1",
className,
)}
{...props}
>
<ChevronUp className="h-4 w-4" />
</SelectPrimitive.ScrollUpButton>
));
PixelSelectScrollUpButton.displayName =
SelectPrimitive.ScrollUpButton.displayName;
// ... (more code below)Accessibility
This component is built with accessibility in mind, including proper ARIA attributes, keyboard navigation, and focus management.