| 57 | }, |
| 58 | }) |
| 59 | export class ToolbarWidget<V> implements OnInit, OnDestroy { |
| 60 | /** A reference to the host element. */ |
| 61 | private readonly _elementRef = inject(ElementRef); |
| 62 | |
| 63 | /** A reference to the host element. */ |
| 64 | readonly element = this._elementRef.nativeElement as HTMLElement; |
| 65 | |
| 66 | /** The parent Toolbar. */ |
| 67 | private readonly _toolbar = inject<Toolbar<V>>(Toolbar); |
| 68 | |
| 69 | /** A unique identifier for the widget. */ |
| 70 | readonly id = input(inject(_IdGenerator).getId('ng-toolbar-widget-', true)); |
| 71 | |
| 72 | /** The parent Toolbar UIPattern. */ |
| 73 | readonly _toolbarPattern = computed<ToolbarPattern<V>>(() => this._toolbar._pattern); |
| 74 | |
| 75 | /** Whether the widget is disabled. */ |
| 76 | readonly disabled = input(false, {transform: booleanAttribute}); |
| 77 | |
| 78 | /** Whether the widget is 'hard' disabled, which is different from `aria-disabled`. A hard disabled widget cannot receive focus. */ |
| 79 | readonly hardDisabled = computed(() => this._pattern.disabled() && !this._toolbar.softDisabled()); |
| 80 | |
| 81 | /** The optional ToolbarWidgetGroup this widget belongs to. */ |
| 82 | readonly _group = inject<ToolbarWidgetGroup<V>>(TOOLBAR_WIDGET_GROUP, {optional: true}); |
| 83 | |
| 84 | /** The value associated with the widget. */ |
| 85 | readonly value = input.required<V>(); |
| 86 | |
| 87 | /** Whether the widget is currently active (focused). */ |
| 88 | readonly active = computed(() => this._pattern.active()); |
| 89 | |
| 90 | /** Whether the widget is selected (only relevant in a selection group). */ |
| 91 | readonly selected = () => this._pattern.selected(); |
| 92 | |
| 93 | private readonly _groupPattern: SignalLike< |
| 94 | ToolbarWidgetGroupPattern<ToolbarWidgetPattern<V>, V> | undefined |
| 95 | > = () => this._group?._pattern; |
| 96 | |
| 97 | /** The ToolbarWidget UIPattern. */ |
| 98 | readonly _pattern = new ToolbarWidgetPattern<V>({ |
| 99 | ...this, |
| 100 | group: this._groupPattern, |
| 101 | toolbar: this._toolbarPattern, |
| 102 | id: this.id, |
| 103 | value: this.value, |
| 104 | element: () => this.element, |
| 105 | }); |
| 106 | |
| 107 | ngOnInit() { |
| 108 | this._toolbar._collection.register(this); |
| 109 | } |
| 110 | |
| 111 | ngOnDestroy() { |
| 112 | this._toolbar._collection.unregister(this); |
| 113 | } |
| 114 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…