|
6 | 6 | * found in the LICENSE file at https://angular.dev/license |
7 | 7 | */ |
8 | 8 |
|
9 | | -import {computed, signal, untracked, WritableSignal} from '@angular/core'; |
| 9 | +import {computed, signal, untracked} from '@angular/core'; |
10 | 10 | import {SignalLike} from '../behaviors/signal-like/signal-like'; |
11 | 11 | import {KeyboardEventManager, PointerEventManager, Modifier} from '../behaviors/event-manager'; |
12 | 12 | import {NavOptions, Grid, GridInputs as GridBehaviorInputs} from '../behaviors/grid'; |
13 | 13 | import type {GridRowPattern} from './row'; |
14 | 14 | import type {GridCellPattern} from './cell'; |
15 | 15 |
|
16 | | -/** An event that represents navigation within the grid. */ |
17 | | -export interface NavigateEvent { |
18 | | - prev?: HTMLElement; |
19 | | - next?: HTMLElement; |
20 | | - rawEvent?: KeyboardEvent | PointerEvent; |
21 | | -} |
22 | | - |
23 | 16 | /** Represents the required inputs for the grid pattern. */ |
24 | 17 | export interface GridInputs extends Omit<GridBehaviorInputs<GridCellPattern>, 'cells'> { |
25 | 18 | /** The html element of the grid. */ |
@@ -74,9 +67,6 @@ export class GridPattern { |
74 | 67 | : undefined, |
75 | 68 | ); |
76 | 69 |
|
77 | | - /** The last navigation event that occurred in the grid. */ |
78 | | - readonly lastNavigateEvent: WritableSignal<NavigateEvent | undefined> = signal(undefined); |
79 | | - |
80 | 70 | /** Whether to pause grid navigation and give the keyboard control to cell or widget. */ |
81 | 71 | readonly pauseNavigation: SignalLike<boolean> = computed(() => |
82 | 72 | this.gridBehavior.data |
@@ -117,14 +107,14 @@ export class GridPattern { |
117 | 107 | selectOne: this.inputs.enableSelection() && this.inputs.selectionMode() === 'follow', |
118 | 108 | }; |
119 | 109 | manager |
120 | | - .on('ArrowUp', e => this._advance(() => this.gridBehavior.up(opts), e)) |
121 | | - .on('ArrowDown', e => this._advance(() => this.gridBehavior.down(opts), e)) |
122 | | - .on(this.prevColKey(), e => this._advance(() => this.gridBehavior.left(opts), e)) |
123 | | - .on(this.nextColKey(), e => this._advance(() => this.gridBehavior.right(opts), e)) |
124 | | - .on('Home', e => this._advance(() => this.gridBehavior.firstInRow(opts), e)) |
125 | | - .on('End', e => this._advance(() => this.gridBehavior.lastInRow(opts), e)) |
126 | | - .on([Modifier.Ctrl], 'Home', e => this._advance(() => this.gridBehavior.first(opts), e)) |
127 | | - .on([Modifier.Ctrl], 'End', e => this._advance(() => this.gridBehavior.last(opts), e)); |
| 110 | + .on('ArrowUp', () => this.gridBehavior.up(opts)) |
| 111 | + .on('ArrowDown', () => this.gridBehavior.down(opts)) |
| 112 | + .on(this.prevColKey(), () => this.gridBehavior.left(opts)) |
| 113 | + .on(this.nextColKey(), () => this.gridBehavior.right(opts)) |
| 114 | + .on('Home', () => this.gridBehavior.firstInRow(opts)) |
| 115 | + .on('End', () => this.gridBehavior.lastInRow(opts)) |
| 116 | + .on([Modifier.Ctrl], 'Home', () => this.gridBehavior.first(opts)) |
| 117 | + .on([Modifier.Ctrl], 'End', () => this.gridBehavior.last(opts)); |
128 | 118 |
|
129 | 119 | // Basic explicit selection handlers. |
130 | 120 | if (this.inputs.enableSelection() && this.inputs.selectionMode() === 'explicit') { |
@@ -164,14 +154,12 @@ export class GridPattern { |
164 | 154 |
|
165 | 155 | // Navigation without selection. |
166 | 156 | if (!this.inputs.enableSelection()) { |
167 | | - manager.on(e => |
168 | | - this._advance(() => { |
169 | | - const cell = this.inputs.getCell(e.target as Element); |
170 | | - if (!cell || !this.gridBehavior.focusBehavior.isFocusable(cell)) return; |
| 157 | + manager.on(e => { |
| 158 | + const cell = this.inputs.getCell(e.target as Element); |
| 159 | + if (!cell || !this.gridBehavior.focusBehavior.isFocusable(cell)) return; |
171 | 160 |
|
172 | | - this.gridBehavior.gotoCell(cell); |
173 | | - }, e), |
174 | | - ); |
| 161 | + this.gridBehavior.gotoCell(cell); |
| 162 | + }); |
175 | 163 | } |
176 | 164 |
|
177 | 165 | // Navigation with selection. |
@@ -406,16 +394,4 @@ export class GridPattern { |
406 | 394 | activeCell.focus(); |
407 | 395 | } |
408 | 396 | } |
409 | | - |
410 | | - /** Performs a navigation operation and emits a navigate event. */ |
411 | | - private _advance(op: () => void, event?: KeyboardEvent | PointerEvent): void { |
412 | | - const prev = this.activeCell()?.element(); |
413 | | - op(); |
414 | | - const next = this.activeCell()?.element(); |
415 | | - this.lastNavigateEvent.set({ |
416 | | - prev, |
417 | | - next, |
418 | | - rawEvent: event, |
419 | | - }); |
420 | | - } |
421 | 397 | } |
0 commit comments