Select Menu
The <smart-select-menu> component renders a single-select menu with a placeholder, list of items (label/value, optional avatar/secondary text/status/disabled), an optional empty state slot, and a two-way value binding. It follows the Base + Standard + Wrapper pattern with an InjectionToken-based extension mechanism. The abstract SelectMenuBaseComponent defines the shared API — value (two-way ModelSignal<SelectMenuValue>), disabled, optional ISelectMenuOptions, cssClass (alias class), and a select(next) method that updates value while respecting the disabled state. SelectMenuStandardComponent is a barebones placeholder concrete implementation using a native <select> element. SelectMenuComponent is the public wrapper that renders SelectMenuStandardComponent by default and accepts a custom replacement via SELECT_MENU_STANDARD_COMPONENT_TOKEN.
Usage
<smart-select-menu [options]="options" [(value)]="plan" />
@if (plan()) {
<p>Selected plan: {{ plan() }}</p>
}
The preview renders the code above in an application that registers every preset (provideSmartPresets(), see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Components
SelectMenuComponent (<smart-select-menu>)
Main wrapper component. Renders SelectMenuStandardComponent by default. When SELECT_MENU_STANDARD_COMPONENT_TOKEN is provided, renders the injected component via NgComponentOutlet, hands it value, disabled, options and class, and forwards its value changes back, so [(value)] on <smart-select-menu> works with any implementation. There is no preset for this component.
SelectMenuStandardComponent (<smart-select-menu-standard>)
Barebones placeholder concrete implementation using a native <select>. Renders an outer wrapper <div>, a <div class="select-menu">, and a <select> (with aria-label from options.ariaLabel) with one <option> per item (with the item's ariaLabel); an optional placeholder is rendered as a disabled first option, selected while value is null. Disabled items get the disabled attribute on their <option>. The <select> is disabled when disabled() is true. On change, the standard reads the raw string value, looks up the matching item by String(value) === String(item.value) (preserving numeric types), and calls select(). When items is empty and emptyTpl is provided, the empty template is rendered inside <div class="empty">. The external cssClass is applied to the root wrapper. It does not include any Tailwind UI styling — it exists solely as the default structural placeholder until a custom implementation is registered through the token.
SelectMenuBaseComponent (abstract)
Abstract base directive for extending custom select menu implementations. Exposes:
value: ModelSignal<SelectMenuValue>(defaultnull) — two-way bindabledisabled: InputSignal<boolean>(defaultfalse)options: InputSignal<ISelectMenuOptions | undefined>cssClass: InputSignal<string>(aliasclass)select(next: SelectMenuValue): void— updatesvalueonly when not disabled
SelectMenuValue is string | number | null.
API
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
value | ModelSignal<SelectMenuValue> | null | Currently selected value (two-way bindable) |
disabled | InputSignal<boolean> | false | Whether the menu is disabled |
options | InputSignal<ISelectMenuOptions | undefined> | - | Optional configuration (items, placeholder, variant, slots) |
class | InputSignal<string> | '' | External CSS classes (alias for cssClass) |
ISelectMenuOptions
| Field | Type | Default | Description |
|---|---|---|---|
items | ISelectMenuItem[] | [] | The choices. |
placeholder | string | - | A disabled first option, selected while value is null. |
ariaLabel | string | - | Accessible name of the <select>. |
emptyTpl | TemplateRef<unknown> | - | Rendered under the select when items is empty. |
variant | SmartSelectMenuVariant | - | Not read by the built-in implementations; available to a custom implementation (e.g. a listbox look). |
SmartSelectMenuVariant is 'native' | 'custom' | 'with-check' | 'with-status' | 'with-avatar' | 'with-secondary' | 'branded'.
ISelectMenuItem
| Field | Type | Default | Description |
|---|---|---|---|
value | string | number | required | The value written to value; a numeric value stays a number. |
label | string | required | The option text. |
disabled | boolean | - | Disables the option. |
ariaLabel | string | - | Accessible name of the option. |
avatarUrl | string | - | Not read by the built-in implementations; available to a custom implementation. |
iconTpl | TemplateRef<unknown> | - | Not read by the built-in implementations; available to a custom implementation. |
secondary | string | - | Not read by the built-in implementations; available to a custom implementation. |
status | 'online' | 'offline' | 'busy' | string | - | Not read by the built-in implementations; available to a custom implementation. |
SELECT_MENU_STANDARD_COMPONENT_TOKEN
InjectionToken that allows replacing the default SelectMenuStandardComponent with a custom implementation. Provide a component class extending SelectMenuBaseComponent under SELECT_MENU_STANDARD_COMPONENT_TOKEN; every <smart-select-menu> below that injector renders it.
Extending the base class
import {
ChangeDetectionStrategy,
Component,
computed,
signal,
ViewEncapsulation,
} from '@angular/core';
import {
ISelectMenuOptions,
SELECT_MENU_STANDARD_COMPONENT_TOKEN,
SelectMenuBaseComponent,
SelectMenuComponent,
SelectMenuValue,
} from '@smartsoft001/angular';
@Component({
selector: 'docs-custom-select-menu',
template: `
<div [class]="containerClasses()">
<button
type="button"
class="docs-select-menu__trigger"
[disabled]="disabled()"
[attr.aria-expanded]="expanded()"
[attr.aria-label]="options()?.ariaLabel"
(click)="toggle()"
>
{{ currentLabel() ?? options()?.placeholder ?? 'Select' }}
</button>
@if (expanded()) {
<ul class="docs-select-menu__list" role="listbox">
@for (item of items(); track item.value) {
<li
role="option"
class="docs-select-menu__option"
[attr.aria-selected]="value() === item.value"
[attr.aria-disabled]="item.disabled ?? false"
(click)="pick(item.value, item.disabled ?? false)"
>
{{ item.label }}
</li>
}
</ul>
}
</div>
`,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomSelectMenuComponent extends SelectMenuBaseComponent {
readonly expanded = signal(false);
readonly items = computed(() => this.options()?.items ?? []);
readonly currentLabel = computed(
() => this.items().find((item) => item.value === this.value())?.label,
);
readonly containerClasses = computed(() => {
const classes = ['docs-select-menu'];
const extra = this.cssClass();
if (extra) classes.push(extra);
return classes.join(' ');
});
toggle(): void {
if (this.disabled()) return;
this.expanded.update((open) => !open);
}
pick(next: SelectMenuValue, itemDisabled: boolean): void {
if (itemDisabled) return;
// select() is the base class API: it ignores the call while disabled.
this.select(next);
this.expanded.set(false);
}
}
@Component({
selector: 'docs-select-menu-custom-example',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [SelectMenuComponent],
// The token swaps the standard native select for the custom listbox
// everywhere below this component, so consumers keep writing
// `<smart-select-menu>`.
providers: [
{
provide: SELECT_MENU_STANDARD_COMPONENT_TOKEN,
useValue: CustomSelectMenuComponent,
},
],
// The wrapper forwards `value` both ways: `selected` reaches the custom
// component, and the item it selects comes back to `selected`.
template: ` <smart-select-menu [(value)]="selected" [options]="options" /> `,
})
export class SelectMenuCustomExampleComponent {
readonly selected = signal<SelectMenuValue>(null);
readonly options: ISelectMenuOptions = {
placeholder: 'Choose a country',
ariaLabel: 'Country',
items: [
{ value: 'pl', label: 'Poland' },
{ value: 'de', label: 'Germany' },
{ value: 'us', label: 'United States' },
],
};
}
Source
The component lives in packages/shared/angular/src/lib/components/select-menu and is documented for Claude Code by the angular-components-select-menu skill.
SmartSelectMenu lets the user pick one item from options.items. SmartSelectMenuStandard is a native <select>; the chosen option is matched back to its item, so a numeric item value stays a number. The value is controlled (value + onValueChange) or kept inside (defaultValue, null by default); disabled blocks the choice. The item fields for avatars, icons, statuses and secondary text, and the variant option, are there for a custom listbox registered under the select-menu key: the standard select shows only the labels. There is no preset.
Usage
import { useState } from 'react';
import {
ISelectMenuOptions,
SelectMenuValue,
SmartSelectMenu,
} from '@smartsoft001/react';
const options: ISelectMenuOptions = {
placeholder: 'Choose a plan',
ariaLabel: 'Subscription plan',
items: [
{ value: 'starter', label: 'Starter' },
{ value: 'pro', label: 'Professional' },
{ value: 'enterprise', label: 'Enterprise', disabled: true },
],
};
export function SelectMenuUsageExample() {
const [plan, setPlan] = useState<SelectMenuValue>(null);
return (
<>
<SmartSelectMenu options={options} value={plan} onValueChange={setPlan} />
{plan && <p>Selected plan: {plan}</p>}
</>
);
}
The preview renders the code above in an application that registers every preset (SMART_PRESET_COMPONENTS on SmartProvider, see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Exports
All from @smartsoft001/react.
| Export | Kind | What it is |
|---|---|---|
SmartSelectMenu | component | Renders the implementation registered as components['select-menu'] on SmartProvider, SmartSelectMenuStandard by default. |
SmartSelectMenuStandard | component | The default select menu: a native <select>. |
useSelectMenu | hook | The behaviour every select menu variant shares: the value, controlled through value / onValueChange or kept internally from defaultValue, and select(), which ignores the choice while disabled. |
Props and Types
SmartSelectMenuProps
| Prop | Type | Default | Description |
|---|---|---|---|
value? | SelectMenuValue | — | The selected item value. Leave it undefined for an uncontrolled select that starts from defaultValue. |
defaultValue? | SelectMenuValue | null | Initial value of an uncontrolled select. |
onValueChange? | (value: SelectMenuValue) => void | — | Called with the value of the chosen item. |
disabled? | boolean | false | Disables the select; select() ignores choices. |
options? | ISelectMenuOptions | — | Items, placeholder, variant and slots. |
className? | string | — | Classes on the root element. |
ISelectMenuOptions
| Field | Type | Default | Description |
|---|---|---|---|
items? | ISelectMenuItem[] | [] | The choices. |
placeholder? | string | — | An empty first option. |
variant? | SmartSelectMenuVariant | — | Not read by the built-in implementations; available to a custom implementation. |
emptyTpl? | ReactNode | — | Shown when there are no items. |
ariaLabel? | string | — | Accessible name of the select. |
ISelectMenuItem
| Field | Type | Default | Description |
|---|---|---|---|
value | string | number | required | The value reported through onValueChange. |
label | string | required | The option text. |
avatarUrl? | string | — | Not read by the built-in implementations; available to a custom implementation. |
iconTpl? | ReactNode | — | Not read by the built-in implementations; available to a custom implementation. |
secondary? | string | — | Not read by the built-in implementations; available to a custom implementation. |
status? | 'online' | 'offline' | 'busy' | string | — | Not read by the built-in implementations; available to a custom implementation. |
disabled? | boolean | — | Disables the option. |
ariaLabel? | string | — | Accessible name of the option. |
Related types
SelectMenuValue:string \| number \| null— The value type: a string, a number ornull.SmartSelectMenuVariant:'native' \| 'custom' \| 'with-check' \| 'with-status' \| 'with-avatar' \| 'with-secondary' \| 'branded'
Replacing the Implementation
SmartSelectMenu renders the component registered under the 'select-menu' key of SmartProvider's components, and SmartSelectMenuStandard when nothing is registered there. Every SmartSelectMenu below the provider then renders the registered component, which receives the same props.
There is no preset for this component: register a component of your own that takes SmartSelectMenuProps, as shown below, as components={{ 'select-menu': MySelectMenu }}. Pass components as a stable object (a module constant or a memoised value), or the context changes on every render.
The useSelectMenu hook
The behaviour every select menu variant shares: the value, controlled through value / onValueChange or kept internally from defaultValue, and select(), which ignores the choice while disabled.
| Returns | Type | Description |
|---|---|---|
value | SelectMenuValue | The selected value (controlled or internal). |
select | (next: SelectMenuValue) => void | Selects a value and calls onValueChange; ignored while disabled. |
import { useState } from 'react';
import {
cn,
ISelectMenuOptions,
SelectMenuValue,
SmartProvider,
SmartSelectMenu,
SmartSelectMenuProps,
useSelectMenu,
} from '@smartsoft001/react';
export function CustomSelectMenu(props: SmartSelectMenuProps) {
const { options, className, disabled = false } = props;
// useSelectMenu keeps the value (controlled or internal) and select(),
// which ignores the choice while disabled.
const { value, select } = useSelectMenu(props);
const [expanded, setExpanded] = useState(false);
const items = options?.items ?? [];
const currentLabel = items.find((item) => item.value === value)?.label;
const toggle = () => {
if (disabled) return;
setExpanded((open) => !open);
};
const pick = (next: SelectMenuValue, itemDisabled: boolean) => {
if (itemDisabled) return;
select(next);
setExpanded(false);
};
return (
<div className={cn('docs-select-menu', className)}>
<button
type="button"
className="docs-select-menu__trigger"
disabled={disabled}
aria-expanded={expanded}
aria-label={options?.ariaLabel}
onClick={toggle}
>
{currentLabel ?? options?.placeholder ?? 'Select'}
</button>
{expanded && (
<ul className="docs-select-menu__list" role="listbox">
{items.map((item) => (
<li
key={item.value}
role="option"
className="docs-select-menu__option"
aria-selected={value === item.value}
aria-disabled={item.disabled ?? false}
onClick={() => pick(item.value, item.disabled ?? false)}
>
{item.label}
</li>
))}
</ul>
)}
</div>
);
}
// A module constant: a new object on every render would change the context.
const components = { 'select-menu': CustomSelectMenu };
const options: ISelectMenuOptions = {
placeholder: 'Choose a country',
ariaLabel: 'Country',
items: [
{ value: 'pl', label: 'Poland' },
{ value: 'de', label: 'Germany' },
{ value: 'us', label: 'United States' },
],
};
export function SelectMenuCustomExample() {
const [selected, setSelected] = useState<SelectMenuValue>(null);
// Every SmartSelectMenu below the provider renders CustomSelectMenu.
return (
<SmartProvider components={components}>
<SmartSelectMenu
options={options}
value={selected}
onValueChange={setSelected}
/>
</SmartProvider>
);
}
Registered under the 'select-menu' key, as above, every SmartSelectMenu below the provider renders the custom listbox.
Styling
- The native select is unstyled (no Tailwind classes, only the
select-menuandemptyclass hooks);classNameis set on the root element.
Source
The component lives in packages/shared/react/src/lib/components/select-menu and is documented for Claude Code by the react-components-select-menu skill.