|
1 | | -import {Component, DebugElement, signal} from '@angular/core'; |
| 1 | +import {Component, DebugElement, Directive, inject, signal} from '@angular/core'; |
2 | 2 | import {ComponentFixture, TestBed} from '@angular/core/testing'; |
3 | 3 | import {By} from '@angular/platform-browser'; |
4 | 4 | import {Toolbar, ToolbarWidget, ToolbarWidgetGroup} from './toolbar'; |
@@ -533,6 +533,23 @@ describe('Toolbar', () => { |
533 | 533 | expect(document.activeElement).toBe(initialActiveElement); |
534 | 534 | }); |
535 | 535 | }); |
| 536 | + |
| 537 | + describe('with wrapped toolbar widgets', () => { |
| 538 | + beforeEach(() => { |
| 539 | + TestBed.configureTestingModule({imports: [WrappedToolbarExample]}); |
| 540 | + fixture = TestBed.createComponent(WrappedToolbarExample) as any; |
| 541 | + fixture.detectChanges(); |
| 542 | + }); |
| 543 | + |
| 544 | + it('should navigate on click', () => { |
| 545 | + const widgets = fixture.debugElement |
| 546 | + .queryAll(By.css('[toolbar-button]')) |
| 547 | + .map((debugEl: DebugElement) => debugEl.nativeElement as HTMLElement); |
| 548 | + console.log('clicking:', widgets[0]); |
| 549 | + click(widgets[0]); |
| 550 | + expect(document.activeElement).toBe(widgets[0]); |
| 551 | + }); |
| 552 | + }); |
536 | 553 | }); |
537 | 554 |
|
538 | 555 | describe('Selection', () => { |
@@ -638,3 +655,27 @@ class ToolbarExample { |
638 | 655 |
|
639 | 656 | groups = [{disabled: signal(false)}]; |
640 | 657 | } |
| 658 | + |
| 659 | +@Directive({ |
| 660 | + selector: 'button[toolbar-button]', |
| 661 | + hostDirectives: [{directive: ToolbarWidget, inputs: ['value', 'disabled']}], |
| 662 | + host: { |
| 663 | + type: 'button', |
| 664 | + class: 'example-button material-symbols-outlined', |
| 665 | + '[aria-label]': 'widget.value()', |
| 666 | + }, |
| 667 | +}) |
| 668 | +export class SimpleToolbarButton { |
| 669 | + widget = inject(ToolbarWidget); |
| 670 | +} |
| 671 | + |
| 672 | +@Component({ |
| 673 | + template: ` |
| 674 | + <div ngToolbar> |
| 675 | + <button toolbar-button value="undo">undo</button> |
| 676 | + <button toolbar-button value="redo">redo</button> |
| 677 | + </div> |
| 678 | + `, |
| 679 | + imports: [Toolbar, SimpleToolbarButton], |
| 680 | +}) |
| 681 | +class WrappedToolbarExample {} |
0 commit comments