Skip to content

Commit

Permalink
feat(angular/dropdown): add trigger directive (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielleroux committed Dec 7, 2022
1 parent 90363be commit e698bc9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/angular-test-app/src/preview-examples/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { Component } from '@angular/core';
@Component({
selector: 'app-dropdown',
template: `
<ix-button id="triggerId">Open</ix-button>
<ix-dropdown trigger="triggerId">
<ix-button #trigger>Open</ix-button>
<ix-dropdown [ixDropdownTrigger]="trigger">
<ix-dropdown-item label="Item 1"></ix-dropdown-item>
<ix-dropdown-item label="Item 2"></ix-dropdown-item>
<ix-dropdown-item label="Item 3"></ix-dropdown-item>
Expand Down
22 changes: 22 additions & 0 deletions packages/angular/src/dropdown/trigger.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* SPDX-FileCopyrightText: 2022 Siemens AG
*
* SPDX-License-Identifier: MIT
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { Directive, ElementRef, Input } from '@angular/core';

@Directive({
selector: '[ixDropdownTrigger]',
})
export class IxDropdownTriggerDirective {
@Input() ixDropdownTrigger!: any;

constructor(private element: ElementRef) {}

protected ngOnChanges() {
this.element.nativeElement.trigger = this.ixDropdownTrigger.el;
}
}
2 changes: 1 addition & 1 deletion packages/angular/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

export * from '@siemens/ix';
export * from './components';
export * from './dropdown/trigger.directive';
export * from './modal';
export * from './module';
export * from './toast';
export * from './tree';

12 changes: 7 additions & 5 deletions packages/angular/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@

import { DOCUMENT } from '@angular/common';
import {
APP_INITIALIZER,
ModuleWithProviders,
NgModule,
NgZone
APP_INITIALIZER,
ModuleWithProviders,
NgModule,
NgZone,
} from '@angular/core';
import { appInitialize } from './app-initialize';
import { DIRECTIVES } from './declare-components';
import { IxDropdownTriggerDirective } from './dropdown/trigger.directive';
import { ModalService } from './modal';
import { ToastService } from './toast';
import * as tree from './tree';
const DECLARATIONS = [...DIRECTIVES, tree.IxTree];

const DECLARATIONS = [...DIRECTIVES, tree.IxTree, IxDropdownTriggerDirective];

@NgModule({
declarations: DECLARATIONS,
Expand Down

0 comments on commit e698bc9

Please sign in to comment.