SiCustomSelectDirective documentation¶
import { SiCustomSelectDirective } from '@siemens/element-ng/select';Host directive for building custom selects.
Add this as a hostDirective on your component and expose the inputs/outputs you need. The directive handles:
• ControlValueAccessor integration (formControl, ngModel, [(value)])
• Disabled / readonly state management
• Overlay lifecycle for the dropdown (open/close)
• Focus management and focus trapping in the dropdown
• Opening the dropdown on click, Enter, Space, ArrowDown, ArrowUp
• SiFormItemControl integration
Use SiSelectDropdownDirective to mark the dropdown template in your component, and call open, close, updateValue from your component logic.
Example:
@Component({
selector: 'app-my-select',
hostDirectives: [{
directive: SiCustomSelectDirective,
inputs: ['disabled', 'readonly', 'value'],
outputs: ['valueChange']
}],
template: `
<si-select-combobox>
{{ select.value() }}
</si-select-combobox>
<ng-template si-select-dropdown contentType="listbox">
<button (click)="select.updateValue('new'); select.close()">Pick</button>
</ng-template>
`
})
export class MySelectComponent {
readonly select = inject(SiCustomSelectDirective);
}
Input Properties¶
| Name | Type | Default | Description |
|---|---|---|---|
| disabled ¶ | boolean | false | Whether the select input is disabled. |
| errormessageId ¶ | string | `${this.id()}-errormessage` | This ID will be bound to the Implements SiFormItemControl |
| id ¶ | string | `__si-select-${SiCustomSelectDirective.idCounter++}` | Unique identifier. Implements SiFormItemControl |
| labelledby ¶ | string | undefined | undefined | Aria labelledby of the select. |
| readonly ¶ | boolean | false | Readonly state. Similar to disabled but with higher contrast. |
| siCustomSelectScrollStrategy ¶ | ScrollStrategy | defaultConnectedOverlayScrollStrategy() | Optional CDK scroll strategy used for the custom select overlay. |
| value ¶ | T | null | undefined | undefined | The current value, supports two-way binding via |
Output Properties¶
| Name | Type | Description |
|---|---|---|
| openChange ¶ | boolean | Emits when the dropdown open state changes. |
| valueChange ¶ | T | null | undefined | The current value, supports two-way binding via |
Attributes and Methods¶
| Name | Type | Default | Description |
|---|---|---|---|
| close() ¶ | () => void | Closes the dropdown overlay and restores focus. | |
| (readonly) disabled ¶ | Signal<boolean> | computed(() => this.disabledInput() || this.disabledByForm()) | Combined disabled state from input and form control. |
| (readonly) isOpen ¶ | WritableSignal<boolean> | false | Whether the dropdown is currently open. |
| open() ¶ | Opens the dropdown overlay. | ||
| updateValue() ¶ | Updates the value programmatically. Call this from your dropdown template to set the new value. |
Types Documentation¶
import type { SiFormItemControl } from '@siemens/element-ng/form';Common interface for form item controls. Controls that should be connected to SiFormItemComponent must implement this interface and must be provided using the SI_FORM_ITEM_CONTROL token.
-
Generated ID that the SiFormItemComponent will assign to the element containing the error messages. Implementations of SiFormItemControl must generate this ID and assign it to the
aria-describedbyattribute of their focusable elements.errormessageId:
readonlystring | Signal<string>¶ -
The actual id of the control that should be used in the
forattribute of a label.id?:
readonlystring | Signal<string | undefined>¶ - readonly
If the control is meant to be used a checkbox. This affects the label positioning.
-
ID that should be assigned to the label element inside the SiFormItemComponent.
If the target control is not of type input, select or button, it cannot be referenced by a label. Instead, aria-labelledby must be used to create a reference to a label. In such a case, an implementation of SiFormItemControl must provide the id of the label in labelledby. SiFormItemComponent will apply the id to the label so that it can be used inside the control to reference it in the aria-labelledby attribute.
labelledby?:
readonlystring | Signal<string | undefined> | null¶
Except where otherwise noted, content on this site is licensed under MIT License.