MCPcopy Create free account
hub / github.com/angular/components / GridCellWidgetPattern

Class GridCellWidgetPattern

src/aria/private/grid/widget.ts:44–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42
43/** The UI pattern for a widget inside a grid cell. */
44export class GridCellWidgetPattern {
45 /** The html element that should receive focus. */
46 readonly element: SignalLike<HTMLElement> = () => this.inputs.element();
47
48 /** The element that should receive focus. */
49 readonly widgetHost: SignalLike<HTMLElement> = () =>
50 resolveElement(this.inputs.focusTarget(), this.element()) ?? this.element();
51
52 /** Whether the widget is disabled. */
53 readonly disabled: SignalLike<boolean> = computed(
54 () => this.inputs.disabled() || this.inputs.cell().disabled(),
55 );
56
57 /** The tab index for the widget. */
58 readonly tabIndex: SignalLike<-1 | 0> = computed(() => {
59 if (this.inputs.focusTarget()) {
60 return -1;
61 }
62 return this.inputs.cell().widgetTabIndex();
63 });
64
65 /** Whether the widget is the active widget in the cell. */
66 readonly active: SignalLike<boolean> = computed(
67 () => this.inputs.cell().active() && this.inputs.cell().widget() === this,
68 );
69
70 /** Whether the widget is currently activated. */
71 readonly isActivated: WritableSignalLike<boolean> = signal(false);
72
73 /** The last event that caused the widget to be activated. */
74 readonly lastActivateEvent: WritableSignalLike<KeyboardEvent | FocusEvent | undefined> =
75 signal(undefined);
76
77 /** The last event that caused the widget to be deactivated. */
78 readonly lastDeactivateEvent: WritableSignalLike<KeyboardEvent | FocusEvent | undefined> =
79 signal(undefined);
80
81 /** The keyboard event manager for the widget. */
82 readonly keydown = computed(() => {
83 const manager = new KeyboardEventManager();
84
85 // Simple widgets emit notification on interaction without capturing event flow
86 if (this.inputs.widgetType() === 'simple') {
87 return manager
88 .on('Enter', e => this.inputs.onActivate?.(e), {
89 preventDefault: false,
90 stopPropagation: false,
91 })
92 .on(' ', e => this.inputs.onActivate?.(e), {
93 preventDefault: false,
94 stopPropagation: false,
95 });
96 }
97
98 // If a widget is activated, only listen to events that exits activate state.
99 if (this.isActivated()) {
100 manager.on('Escape', e => this.deactivate(e));
101

Callers

nothing calls this directly

Calls 11

deactivateMethod · 0.95
activateMethod · 0.95
resolveElementFunction · 0.90
computedFunction · 0.90
signalFunction · 0.90
widgetTabIndexMethod · 0.80
elementMethod · 0.45
disabledMethod · 0.45
activeMethod · 0.45
onMethod · 0.45
isActivatedMethod · 0.45

Tested by

no test coverage detected