Native Select

The browser's own select, in the look of the app's style.

FormsExperimental

Usage

import { Component, ViewEncapsulation } from '@angular/core';import {  ScField,  ScLabel,  ScNativeSelect,  ScNativeSelectContainer,  ScNativeSelectIcon,  ScNativeSelectOption,} from '@semantic-components/ui';import { SiChevronDownIcon } from '@semantic-icons/lucide-icons';
/** The browser's own select, in the style's look: here a status, its label from the field. */@Component({  selector: 'app-native-select-usage-demo',  imports: [    ScField,    ScLabel,    ScNativeSelect,    ScNativeSelectContainer,    ScNativeSelectIcon,    ScNativeSelectOption,    SiChevronDownIcon,  ],  template: `    <div scField class="w-56">      <label scLabel>Status</label>      <div scNativeSelectContainer class="w-full">        <select scNativeSelect>          <option scNativeSelectOption value="">Select status</option>          <option scNativeSelectOption value="todo">Todo</option>          <option scNativeSelectOption value="in-progress">In Progress</option>          <option scNativeSelectOption value="done">Done</option>          <option scNativeSelectOption value="cancelled">Cancelled</option>        </select>        <svg siChevronDownIcon scNativeSelectIcon></svg>      </div>    </div>  `,  host: { class: 'flex w-full justify-center' },  encapsulation: ViewEncapsulation.None,})export class NativeSelectUsageDemo {}

Anatomy

A real select and its options, in a container beside your chevron. Its label, description and errors go round it, in a field.

import {  ScNativeSelect, ScNativeSelectContainer, ScNativeSelectIcon,  ScNativeSelectOption, ScNativeSelectOptionGroup,} from '@semantic-components/ui';
<div scField>  <label scLabel>…</label>  <div scNativeSelectContainer>    <select scNativeSelect [formField]="…">      <option scNativeSelectOption value="…">…</option>      <optgroup scNativeSelectOptionGroup label="…">        <option scNativeSelectOption value="…">…</option>      </optgroup>    </select>    <svg siChevronDownIcon scNativeSelectIcon></svg>  </div>  <p scFieldErrors></p></div>

Accessibility

  • A real select: its keyboard, its list and the phone's picker are the browser's, and read as a combo box.
  • Its name from the field's label (it takes the field's id); a description and errors are read with it. Without a field, give it an aria-label.
  • The chevron is hidden from screen readers.
  • Invalid once left (aria-invalid), with Signal Forms.

Native Select or Select

  • Native Select: the browser's behaviour, light and fast, and the phone's own picker.
  • Select: its list styled as the app, animated, with richer items (icons, descriptions) and more ways to interact.

Examples

Groups

import { Component, ViewEncapsulation } from '@angular/core';import {  ScField,  ScLabel,  ScNativeSelect,  ScNativeSelectContainer,  ScNativeSelectIcon,  ScNativeSelectOption,  ScNativeSelectOptionGroup,} from '@semantic-components/ui';

Disabled

import { Component, ViewEncapsulation } from '@angular/core';import {  ScField,  ScLabel,  ScNativeSelect,  ScNativeSelectContainer,  ScNativeSelectIcon,  ScNativeSelectOption,} from '@semantic-components/ui';import { SiChevronDownIcon } from '@semantic-icons/lucide-icons';

Invalid

import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, form, required } from '@angular/forms/signals';import {  ScField,  ScFieldErrors,  ScLabel,  ScNativeSelect,  ScNativeSelectContainer,  ScNativeSelectIcon,  ScNativeSelectOption,

Sizes

import { Component, ViewEncapsulation } from '@angular/core';import {  ScNativeSelect,  ScNativeSelectContainer,  ScNativeSelectIcon,  ScNativeSelectOption,} from '@semantic-components/ui';import { SiChevronDownIcon } from '@semantic-icons/lucide-icons';
/** Two heights: default, and sm (size="sm"), its chevron following. */

RTL

import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import {  ScField,  ScLabel,  ScNativeSelect,  ScNativeSelectContainer,  ScNativeSelectIcon,  ScNativeSelectOption,} from '@semantic-components/ui';

API reference

Each part takes class, merged over the style (cn: a later class wins).

PartSelectorDescription
ScNativeSelectselect[scNativeSelect] The browser's select, in the style's look. size ('default', 'sm'); its id and description from a scField; [formField] on it (disabled and required from the schema); aria-invalid once touched.
ScNativeSelectContainerdiv[scNativeSelectContainer] Around the select and your chevron: as wide as its content (w-full to fill a field), dimmed while the select is disabled; its select's size, for the chevron.
ScNativeSelectIconsvg[scNativeSelectIcon] Your chevron (siChevronDownIcon), after the select: at its end, by the style; hidden from screen readers.
ScNativeSelectOption, ScNativeSelectOptionGroupoption[…], optgroup[…] An option, and a group of them under its label: the system's colours, so the browser's list reads in dark mode too.