Skip to content

Commit

Permalink
fix(command): add valueChanged again
Browse files Browse the repository at this point in the history
  • Loading branch information
elite-benni committed Feb 11, 2025
1 parent e4f4a2a commit 86278c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions libs/brain/command/src/lib/brn-command.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import {
inject,
Injector,
input,
output,
PLATFORM_ID,
} from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { BrnCommandItemDirective } from './brn-command-item.directive';
import { BrnCommandItemToken } from './brn-command-item.token';
import { BrnCommandSearchInputDirective } from './brn-command-search-input.directive';
import { provideBrnCommand } from './brn-command.token';
Expand Down Expand Up @@ -42,6 +45,9 @@ export class BrnCommandDirective implements AfterViewInit {
/** A custom filter function to use when searching. */
public readonly filter = input<CommandFilter>(this._defaultFilter);

/** when the selection has changed */
public readonly valueChanged = output<string>();

/** @internal The search query */
public readonly search = computed(() => this._searchInput()?.value() ?? '');

Expand Down Expand Up @@ -76,6 +82,13 @@ export class BrnCommandDirective implements AfterViewInit {
},
{ allowSignalWrites: true },
);

this.keyManager.change.pipe(takeUntilDestroyed()).subscribe(() => {
const value = (this.keyManager.activeItem as BrnCommandItemDirective)?.value();
if (value) {
this.valueChanged.emit(value);
}
});
}

ngAfterViewInit(): void {
Expand Down
7 changes: 6 additions & 1 deletion libs/ui/command/helm/src/lib/hlm-command.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { hlm } from '@spartan-ng/brain/core';
template: `
<ng-content />
`,
hostDirectives: [BrnCommandDirective],
hostDirectives: [
{
directive: BrnCommandDirective,
outputs: ['valueChanged'],
},
],
host: {
'[class]': '_computedClass()',
},
Expand Down

0 comments on commit 86278c1

Please sign in to comment.