Skip to content

Commit

Permalink
refactor(shared-docs): make the SearchItem directive OnPush compatible (
Browse files Browse the repository at this point in the history
#2072)

The SearchItem directive has a local state (isActive) used in a host binding.
Prior to this change the state was updated from a method call without marking
the corresponding view for check. This meant that the directive in question
could not be used in an OnPush component as the directive's host bindings
would not be re-evaluated.

PR Close #2072
  • Loading branch information
Pawel Kozlowski authored and josephperrott committed May 17, 2024
1 parent 7d12344 commit fca0d3f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions docs/directives/search-item/search-item.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/

import {Directive, ElementRef, Input, inject} from '@angular/core';
import {Directive, ElementRef, Input, inject, signal} from '@angular/core';
import {Highlightable} from '@angular/cdk/a11y';
import {SearchResult} from '../../interfaces/search-results';

Expand All @@ -23,18 +23,18 @@ export class SearchItem implements Highlightable {

private readonly elementRef = inject(ElementRef<HTMLLIElement>);

private _isActive = false;
private _isActive = signal(false);

protected get isActive() {
return this._isActive;
return this._isActive();
}

setActiveStyles(): void {
this._isActive = true;
this._isActive.set(true);
}

setInactiveStyles(): void {
this._isActive = false;
this._isActive.set(false);
}

getLabel(): string {
Expand Down

0 comments on commit fca0d3f

Please sign in to comment.