Skip to content

Commit 8673c4c

Browse files
spliffonekfenner
authored andcommitted
refactor(autocomplete): migrate to component bindings
1 parent 641eb6f commit 8673c4c

2 files changed

Lines changed: 15 additions & 22 deletions

File tree

api-goldens/element-ng/autocomplete/index.api.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
55
```ts
66

7+
import * as _angular_core from '@angular/core';
78
import { Highlightable } from '@angular/cdk/a11y';
8-
import * as i0 from '@angular/core';
99
import { OnInit } from '@angular/core';
1010

1111
// @public (undocumented)
@@ -20,13 +20,13 @@ export class SiAutocompleteListboxDirective<T> implements OnInit {
2020
// (undocumented)
2121
get active(): SiAutocompleteOptionDirective<T> | null;
2222
// (undocumented)
23-
readonly autocomplete: i0.InputSignal<SiAutocompleteDirective<T>>;
23+
readonly autocomplete: _angular_core.InputSignal<SiAutocompleteDirective<T>>;
2424
// (undocumented)
25-
readonly id: i0.InputSignal<string>;
25+
readonly id: _angular_core.InputSignal<string>;
2626
// (undocumented)
27-
readonly siAutocompleteDefaultIndex: i0.InputSignal<number>;
27+
readonly siAutocompleteDefaultIndex: _angular_core.InputSignal<number>;
2828
// (undocumented)
29-
readonly siAutocompleteOptionSubmitted: i0.OutputEmitterRef<T | undefined>;
29+
readonly siAutocompleteOptionSubmitted: _angular_core.OutputEmitterRef<T | undefined>;
3030
}
3131

3232
// @public (undocumented)
@@ -38,11 +38,11 @@ export class SiAutocompleteOptionDirective<T = unknown> implements Highlightable
3838
// (undocumented)
3939
get disabled(): boolean;
4040
// (undocumented)
41-
readonly disabledInput: i0.InputSignalWithTransform<boolean, unknown>;
41+
readonly disabledInput: _angular_core.InputSignalWithTransform<boolean, unknown>;
4242
// (undocumented)
43-
readonly id: i0.InputSignal<string>;
43+
readonly id: _angular_core.InputSignal<string>;
4444
// (undocumented)
45-
readonly value: i0.InputSignal<T | undefined>;
45+
readonly value: _angular_core.InputSignal<T | undefined>;
4646
}
4747

4848
// (No @packageDocumentation comment for this package)

projects/element-ng/autocomplete/si-autocomplete-option.directive.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,7 @@
33
* SPDX-License-Identifier: MIT
44
*/
55
import { Highlightable } from '@angular/cdk/a11y';
6-
import {
7-
booleanAttribute,
8-
Directive,
9-
ElementRef,
10-
HostBinding,
11-
HostListener,
12-
inject,
13-
input
14-
} from '@angular/core';
6+
import { booleanAttribute, Directive, ElementRef, inject, input, signal } from '@angular/core';
157

168
import { AUTOCOMPLETE_LISTBOX } from './si-autocomplete.model';
179

@@ -20,7 +12,9 @@ import { AUTOCOMPLETE_LISTBOX } from './si-autocomplete.model';
2012
host: {
2113
role: 'option',
2214
'[id]': 'id()',
23-
'[attr.aria-disabled]': 'disabledInput()'
15+
'[attr.aria-disabled]': 'disabledInput()',
16+
'[class.active]': 'active()',
17+
'(click)': 'click()'
2418
},
2519
exportAs: 'siAutocompleteOption'
2620
})
@@ -47,21 +41,20 @@ export class SiAutocompleteOptionDirective<T = unknown> implements Highlightable
4741
/** @defaultValue undefined */
4842
readonly value = input<T>(undefined, { alias: 'siAutocompleteOption' });
4943

50-
@HostBinding('class.active') protected active?: boolean;
44+
protected readonly active = signal(false);
5145

52-
@HostListener('click')
5346
protected click(): void {
5447
this.parent.siAutocompleteOptionSubmitted.emit(this.value());
5548
}
5649

5750
/** @internal */
5851
setActiveStyles(): void {
59-
this.active = true;
52+
this.active.set(true);
6053
this.element.nativeElement.scrollIntoView({ block: 'nearest' });
6154
}
6255

6356
/** @internal */
6457
setInactiveStyles(): void {
65-
this.active = false;
58+
this.active.set(false);
6659
}
6760
}

0 commit comments

Comments
 (0)