Getting Started
Overview
Installation
Theme
Forms
Basic Inputs
Custom Inputs
Select
Components
Components
78
Micro Charts
Navigation
Libraries
Content Editor
Data View
Form Builder
Image Designer
Kanban Board
PDF Viewer
Video Player
Latest npm version of @ngstarter-ui/componentsWeekly npm downloads of @ngstarter-ui/components
Buy License

Select

Select lets users choose one or multiple values from a known dropdown list. Use it in one ngs-form-field for forms, filters, settings, table filters, and admin configuration fields when the available options are predefined.

Use ngs-select with ngs-option for each option and ngs-optgroup when options need visible grouping. Select supports placeholder, required and disabled states, single and multiple selection, Angular forms, value, selectionChange, custom trigger content, and optional header, body, and footer slots for richer dropdown panels.

Do not use Select as a command menu, action list, route navigation, compact mode switch, simple visible radio group, rich card choice, or free text search input. Use Menu, Navigation, Tabs, Segmented, Radio, RadioCard, or Autocomplete when those match the job better. Use dedicated selectors such as CountrySelect, CurrencySelect, DateFormatSelect, or TimezoneSelect when the domain already has its own component.

Select API

Clearable usage

<ngs-select clearable [formControl]="status">
  <ngs-option value="active">Active</ngs-option>
  <ngs-option value="pending">Pending</ngs-option>
</ngs-select>

Inputs

NameDescription
idUnique identifier for the select component.
placeholderPlaceholder text to display when no value is selected.
disabledWhether the select is disabled.
requiredWhether the select is required.
multipleWhether the user can select multiple options.
hideCheckIconWhether to hide the check icon for selected options.
clearableWhether to show a clear button next to the arrow when a value is selected. Clearing emits selectionChange and writes null for single select or an empty array for multiple select.
dataSourceAsync option source for server-backed select values. Receives paging, search, selected values, request reason, and an optional abort signal.
pageSizeNumber of async options requested per page. Defaults to 25.
searchableShows the async search input in the panel. Search requests are sent to dataSource.
searchDebounceDebounce in milliseconds before sending a search request. Defaults to 250.
minSearchLengthMinimum number of typed characters before remote search runs. Defaults to 0.
loadOnOpenLoads async options when the select panel opens. Defaults to true.
ariaLabelAria-label for the select.
tabIndexTabIndex for the select.
aria-describedbyAria-describedby for the select.

Async data source

Use dataSource when options come from an API. The function must return the selected option during the first request when selectedValues contains the current form value, so the trigger can render the selected label before the option page is opened.

import { SelectDataSource } from '@ngstarter-ui/components/select';

readonly usersDataSource: SelectDataSource<User> = async request => {
  const response = await usersApi.search({
    search: request.search,
    page: request.page,
    pageSize: request.pageSize,
    selectedValues: request.selectedValues,
  });

  return {
    items: response.users.map(user => ({
      label: user.name,
      value: user.id,
      data: user,
    })),
    hasMore: response.hasMore,
    nextCursor: response.nextPage,
  };
};
<ngs-select
  [formControl]="owner"
  [dataSource]="usersDataSource"
  [pageSize]="20"
  searchable
  [minSearchLength]="1">
</ngs-select>

SelectDataSourceRequest

NameDescription
searchCurrent search text. Empty for initial and open requests.
pageOne-based page number requested by the select.
pageSizeConfigured page size passed from the select.
selectedValuesCurrent selected value or values. Return matching options on the first request.
reasonWhy the request was made: initial, open, search, or page.
signalOptional abort signal for cancelling stale remote requests.

Async templates

Use ngsOptionContentDef to customize async option rows and ngsSelectValueDef to customize the selected value display. Both templates receive the option data payload.

<ng-template ngsOptionContentDef let-user let-label="label">
  <strong>{{ user.name }}</strong>
  <span>{{ user.team }}</span>
</ng-template>

<ng-template ngsSelectValueDef let-user let-label="label">
  {{ user?.name || label }}
</ng-template>

Outputs

NameDescription
selectionChangeEvent emitted when the selected value changes.
openedEvent emitted when the select panel is opened.
closedEvent emitted when the select panel is closed.

Public Properties

NameDescription
hasValueComputed signal that returns true when the select currently has a selected value. It is false for null, undefined, an empty string, or an empty array.

ngs-option Inputs

NameDescription
valueValue written to the parent select control when this option is selected.
dataOptional full option payload, such as an object or typed status. The select value still uses value, while filter trigger custom value templates receive data for rendering richer selected values.
disabledWhether the option is disabled.
selectedWhether the option starts selected.