Skip to content

Commit 61d8b93

Browse files
spliffonedr-itz
authored andcommitted
refactor(select): migrate to component bindings
1 parent b682c4f commit 61d8b93

3 files changed

Lines changed: 14 additions & 17 deletions

File tree

projects/element-ng/select/select-input/si-select-input.component.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
ChangeDetectionStrategy,
88
Component,
99
computed,
10-
HostListener,
1110
inject,
1211
input,
1312
output,
@@ -46,7 +45,14 @@ import { SelectOption } from '../si-select.types';
4645
'[attr.aria-disabled]': 'selectionStrategy.disabled()',
4746
'[attr.tabindex]': 'selectionStrategy.disabled() ? "-1" : "0"',
4847
'[class.disabled]': 'selectionStrategy.disabled()',
49-
'[class.active]': 'open()'
48+
'[class.active]': 'open()',
49+
'(blur)': 'blur()',
50+
'(click)': 'click($event)',
51+
'(keydown.arrowDown)': 'click($event)',
52+
'(keydown.alt.arrowDown)': 'click($event)',
53+
'(keydown.arrowUp)': 'click($event)',
54+
'(keydown.enter)': 'click($event)',
55+
'(keydown.space)': 'click($event)'
5056
}
5157
})
5258
export class SiSelectInputComponent<T> {
@@ -85,19 +91,12 @@ export class SiSelectInputComponent<T> {
8591
protected readonly labeledBy = computed(() => `${this.baseId()}-aria-label ${this.labelledby()}`);
8692
protected readonly icons = addIcons({ elementDown2 });
8793

88-
@HostListener('blur')
8994
protected blur(): void {
9095
if (!this.open()) {
9196
this.selectionStrategy.onTouched();
9297
}
9398
}
9499

95-
@HostListener('click')
96-
@HostListener('keydown.arrowDown', ['$event'])
97-
@HostListener('keydown.alt.arrowDown', ['$event'])
98-
@HostListener('keydown.arrowUp', ['$event'])
99-
@HostListener('keydown.enter')
100-
@HostListener('keydown.space')
101100
protected click(event?: Event): void {
102101
event?.preventDefault();
103102
this.openListbox.emit();

projects/element-ng/select/select-list/si-select-list.base.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import { ConfigurableFocusTrap, ConfigurableFocusTrapFactory } from '@angular/cd
66
import {
77
Directive,
88
ElementRef,
9-
HostBinding,
10-
HostListener,
119
inject,
1210
input,
1311
OnDestroy,
@@ -25,7 +23,9 @@ import { SelectGroup, SelectOption } from '../si-select.types';
2523

2624
@Directive({
2725
host: {
28-
class: 'dropdown-menu position-static w-100 py-4 d-flex flex-column'
26+
class: 'dropdown-menu position-static w-100 py-4 d-flex flex-column',
27+
'[class.si-multi-select]': 'multiSelect',
28+
'(keydown.tab)': 'keydownTab()'
2929
}
3030
})
3131
export abstract class SiSelectListBase<T> implements OnInit, OnDestroy {
@@ -54,7 +54,6 @@ export abstract class SiSelectListBase<T> implements OnInit, OnDestroy {
5454
protected rows = this.selectOptions.rows;
5555
protected focusTrap!: ConfigurableFocusTrap;
5656

57-
@HostBinding('class.si-multi-select')
5857
protected multiSelect = this.selectionStrategy.allowMultiple;
5958

6059
ngOnInit(): void {
@@ -65,7 +64,6 @@ export abstract class SiSelectListBase<T> implements OnInit, OnDestroy {
6564
this.focusTrap.destroy();
6665
}
6766

68-
@HostListener('keydown.tab')
6967
protected keydownTab(): void {
7068
// Ignore tab key if actions are displayed.
7169
if (!this.actionsTemplate()) {

projects/element-ng/select/si-select-action.directive.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
* Copyright (c) Siemens 2016 - 2026
33
* SPDX-License-Identifier: MIT
44
*/
5-
import { booleanAttribute, Directive, HostListener, inject, input } from '@angular/core';
5+
import { booleanAttribute, Directive, inject, input } from '@angular/core';
66

77
import { SiSelectComponent } from './si-select.component';
88

99
@Directive({
1010
selector: '[siSelectAction]',
1111
host: {
12-
class: 'mx-5 my-4'
12+
class: 'mx-5 my-4',
13+
'(click)': 'close()'
1314
},
1415
exportAs: 'si-select-action'
1516
})
@@ -21,7 +22,6 @@ export class SiSelectActionDirective {
2122
*/
2223
readonly selectActionAutoClose = input(false, { transform: booleanAttribute });
2324

24-
@HostListener('click')
2525
protected close(): void {
2626
if (this.selectActionAutoClose()) {
2727
this.select.close();

0 commit comments

Comments
 (0)