Skip to content

Select

Displays a list of options for the user to pick from—triggered by a button.

Installation

bash
npx @galaxy-stack/nebula-cli@latest add select
bash
pnpm dlx @galaxy-stack/nebula-cli@latest add select
bash
yarn dlx @galaxy-stack/nebula-cli@latest add select
bash
bunx @galaxy-stack/nebula-cli@latest add select
bash
# If you have installed galaxy-design globally
galaxy-design add select

Dependencies

This component automatically installs the following dependencies:

  • React: @radix-ui/react-select
  • Vue: radix-vue
  • Angular: @radix-ng/primitives

No manual installation needed!

Usage

React

tsx
import {
  Select,
  SelectTrigger,
  SelectContent,
  SelectItem,
  SelectValue,
} from "@/components/ui/select"

export default function App() {
  return (
    <Select defaultValue="apple">
      <SelectTrigger className="w-[180px]">
        <SelectValue placeholder="Select a fruit" />
      </SelectTrigger>
      <SelectContent>
        <SelectItem value="apple">Apple</SelectItem>
        <SelectItem value="banana">Banana</SelectItem>
        <SelectItem value="orange">Orange</SelectItem>
      </SelectContent>
    </Select>
  )
}

Vue

vue
<script setup lang="ts">
import {
  Select,
  SelectTrigger,
  SelectContent,
  SelectItem,
  SelectValue,
} from '@/components/ui/select'
</script>

<template>
  <Select default-value="apple">
    <SelectTrigger class="w-[180px]">
      <SelectValue placeholder="Select a fruit" />
    </SelectTrigger>
    <SelectContent>
      <SelectItem value="apple">Apple</SelectItem>
      <SelectItem value="banana">Banana</SelectItem>
      <SelectItem value="orange">Orange</SelectItem>
    </SelectContent>
  </Select>
</template>

Angular

typescript
import { Component } from '@angular/core';
import { SelectComponent } from '@/components/ui/select';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [SelectComponent],
  template: `
    <ui-select default-value="apple">
      <ui-select-trigger class="w-[180px]">
        <ui-select-value placeholder="Select a fruit" />
      </ui-select-trigger>
      <ui-select-content>
        <ui-select-item value="apple">Apple</ui-select-item>
        <ui-select-item value="banana">Banana</ui-select-item>
        <ui-select-item value="orange">Orange</ui-select-item>
      </ui-select-content>
    </ui-select>
  `
})
export class AppComponent {}

React Native

tsx
import {
  Select,
  SelectTrigger,
  SelectContent,
  SelectItem,
  SelectValue,
} from '@/components/ui/select'

export default function App() {
  return (
    <Select defaultValue="apple">
      <SelectTrigger>
        <SelectValue placeholder="Select a fruit" />
      </SelectTrigger>
      <SelectContent>
        <SelectItem value="apple">Apple</SelectItem>
        <SelectItem value="banana">Banana</SelectItem>
        <SelectItem value="orange">Orange</SelectItem>
      </SelectContent>
    </Select>
  )
}

Flutter

dart
import 'package:flutter/material.dart';
import 'package:galaxy_design/galaxy_select.dart';

class SelectExample extends StatefulWidget {
  @override
  _SelectExampleState createState() => _SelectExampleState();
}

class _SelectExampleState extends State<SelectExample> {
  String? selectedValue;

  @override
  Widget build(BuildContext context) {
    return GalaxySelect(
      value: selectedValue,
      hint: 'Select a fruit',
      items: [
        GalaxySelectOption(value: 'apple', label: 'Apple'),
        GalaxySelectOption(value: 'banana', label: 'Banana'),
        GalaxySelectOption(value: 'orange', label: 'Orange'),
      ],
      onChanged: (value) {
        setState(() {
          selectedValue = value;
        });
      },
    );
  }
}

API Reference

Props

PropTypeDefaultDescriptionFrameworks
valuestringundefinedControlled selected valueAll
defaultValuestringundefinedUncontrolled initial valueAll
onValueChange(value: string) => void-Called when value changesAll
openbooleanundefinedControlled open stateReact, Vue, Angular
defaultOpenbooleanfalseUncontrolled initial open stateAll
onOpenChange(open: boolean) => void-Called when open state changesReact, Vue, Angular
disabledbooleanfalseDisables the selectAll
dir'ltr' | 'rtl''ltr'Reading directionReact, Vue, Angular
namestring-Name for form submissionAll
requiredbooleanfalseRequires value before form submissionAll
classNamestring''CSS class namesReact, React Native
classstring''CSS class namesVue, Angular, Flutter

Subcomponents

SelectTrigger

PropTypeDefaultDescriptionFrameworks
asChildbooleanfalseRender as child elementReact, Vue, Angular
classNamestring''CSS class namesReact, React Native
classstring''CSS class namesVue, Angular, Flutter

SelectContent

PropTypeDefaultDescriptionFrameworks
position'popper' | 'item-aligned''popper'Content positioningReact, Vue, Angular
side'top' | 'bottom' | 'left' | 'right''bottom'Side to render contentReact, Vue, Angular
sideOffsetnumber4Offset from sideReact, Vue, Angular
asChildbooleanfalseRender as child elementReact, Vue, Angular
classNamestring''CSS class namesReact, React Native
classstring''CSS class namesVue, Angular, Flutter

SelectItem

PropTypeDefaultDescriptionFrameworks
valuestring-Unique value for the itemAll
labelstring-Display labelAll
disabledbooleanfalseDisables the itemAll
asChildbooleanfalseRender as child elementReact, Vue, Angular

SelectValue

PropTypeDefaultDescriptionFrameworks
placeholderstring-Placeholder text when no valueAll
classNamestring''CSS class namesReact, React Native
classstring''CSS class namesVue, Angular, Flutter

Subcomponents

SelectTrigger

Button that opens the select dropdown

SelectContent

Container for select options

SelectItem

Individual selectable option

SelectValue

Displays the selected value

Accessibility

  • Keyboard Navigation: Arrow keys to navigate, Enter to select, Escape to close
  • Screen Reader: Uses proper ARIA select pattern
  • Focus Management: Focus management between trigger and options
  • WCAG Compliance: WAI-ARIA design pattern compliant

Author

Bùi Trọng Hiếu (kevinbui)

License

MIT © 2025 Bùi Trọng Hiếu (kevinbui)

Released under the MIT License.