MCPcopy Index your code
hub / github.com/angular/components / ToolbarWidget

Class ToolbarWidget

src/aria/toolbar/toolbar-widget.ts:59–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57 },
58})
59export 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}

Callers

nothing calls this directly

Calls 7

inputFunction · 0.85
computedFunction · 0.85
getIdMethod · 0.45
disabledMethod · 0.45
requiredMethod · 0.45
activeMethod · 0.45
selectedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…