Skip to content

Commit 3c00f96

Browse files
committed
refactor: remove onNavigate output
1 parent 5963c32 commit 3c00f96

File tree

4 files changed

+16
-100
lines changed

4 files changed

+16
-100
lines changed

src/aria/grid/grid.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,7 @@ import {
2121
Signal,
2222
} from '@angular/core';
2323
import {Directionality} from '@angular/cdk/bidi';
24-
import {
25-
GridPattern,
26-
GridRowPattern,
27-
GridCellPattern,
28-
GridCellWidgetPattern,
29-
NavigateEvent,
30-
} from '../private';
31-
32-
export {NavigateEvent} from '../private';
24+
import {GridPattern, GridRowPattern, GridCellPattern, GridCellWidgetPattern} from '../private';
3325

3426
/**
3527
* The container for a grid. It provides keyboard navigation and focus management for the grid's
@@ -135,9 +127,6 @@ export class Grid {
135127
/** Whether enable range selections (with modifier keys or dragging). */
136128
readonly enableRangeSelection = input(false, {transform: booleanAttribute});
137129

138-
/** Emits when navigation occurs within the grid. */
139-
readonly onNavigate = output<NavigateEvent>();
140-
141130
/** The UI pattern for the grid. */
142131
readonly _pattern = new GridPattern({
143132
...this,
@@ -151,12 +140,6 @@ export class Grid {
151140
afterRenderEffect(() => this._pattern.resetFocusEffect());
152141
afterRenderEffect(() => this._pattern.restoreFocusEffect());
153142
afterRenderEffect(() => this._pattern.focusEffect());
154-
afterRenderEffect(() => {
155-
const navigateEvent = this._pattern.lastNavigateEvent();
156-
if (navigateEvent) {
157-
this.onNavigate.emit(navigateEvent);
158-
}
159-
});
160143
}
161144

162145
/** Gets the cell pattern for a given element. */

src/aria/private/grid/grid.ts

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,13 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {computed, signal, untracked, WritableSignal} from '@angular/core';
9+
import {computed, signal, untracked} from '@angular/core';
1010
import {SignalLike} from '../behaviors/signal-like/signal-like';
1111
import {KeyboardEventManager, PointerEventManager, Modifier} from '../behaviors/event-manager';
1212
import {NavOptions, Grid, GridInputs as GridBehaviorInputs} from '../behaviors/grid';
1313
import type {GridRowPattern} from './row';
1414
import type {GridCellPattern} from './cell';
1515

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-
2316
/** Represents the required inputs for the grid pattern. */
2417
export interface GridInputs extends Omit<GridBehaviorInputs<GridCellPattern>, 'cells'> {
2518
/** The html element of the grid. */
@@ -74,9 +67,6 @@ export class GridPattern {
7467
: undefined,
7568
);
7669

77-
/** The last navigation event that occurred in the grid. */
78-
readonly lastNavigateEvent: WritableSignal<NavigateEvent | undefined> = signal(undefined);
79-
8070
/** Whether to pause grid navigation and give the keyboard control to cell or widget. */
8171
readonly pauseNavigation: SignalLike<boolean> = computed(() =>
8272
this.gridBehavior.data
@@ -117,14 +107,14 @@ export class GridPattern {
117107
selectOne: this.inputs.enableSelection() && this.inputs.selectionMode() === 'follow',
118108
};
119109
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));
128118

129119
// Basic explicit selection handlers.
130120
if (this.inputs.enableSelection() && this.inputs.selectionMode() === 'explicit') {
@@ -164,14 +154,12 @@ export class GridPattern {
164154

165155
// Navigation without selection.
166156
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;
171160

172-
this.gridBehavior.gotoCell(cell);
173-
}, e),
174-
);
161+
this.gridBehavior.gotoCell(cell);
162+
});
175163
}
176164

177165
// Navigation with selection.
@@ -406,16 +394,4 @@ export class GridPattern {
406394
activeCell.focus();
407395
}
408396
}
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-
}
421397
}

src/components-examples/aria/grid/grid-calendar/grid-calendar-example.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
[enableSelection]="true"
1919
[softDisabled]="false"
2020
selectionMode="explicit"
21-
(onNavigate)="onNavigate($event)"
2221
>
2322
<thead>
2423
<tr>

src/components-examples/aria/grid/grid-calendar/grid-calendar-example.ts

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ import {
1414
computed,
1515
untracked,
1616
afterRenderEffect,
17-
viewChildren,
1817
} from '@angular/core';
1918
import {DateAdapter, MAT_DATE_FORMATS, MatDateFormats} from '@angular/material/core';
20-
import {Grid, GridRow, GridCell, GridCellWidget, NavigateEvent} from '@angular/aria/grid';
19+
import {Grid, GridRow, GridCell, GridCellWidget} from '@angular/aria/grid';
2120

2221
const DAYS_PER_WEEK = 7;
2322

@@ -36,7 +35,6 @@ interface CalendarCell<D = any> {
3635
imports: [Grid, GridRow, GridCell, GridCellWidget],
3736
})
3837
export class GridCalendarExample<D> {
39-
private readonly _buttons = viewChildren(GridCellWidget);
4038
private readonly _dateAdapter = inject<DateAdapter<D>>(DateAdapter, {optional: true})!;
4139
private readonly _dateFormats = inject<MatDateFormats>(MAT_DATE_FORMATS, {optional: true})!;
4240
private readonly _firstWeekOffset: Signal<number> = computed(() => {
@@ -102,26 +100,6 @@ export class GridCalendarExample<D> {
102100
}
103101
}
104102
});
105-
106-
afterRenderEffect(() => {
107-
const buttons = this._buttons();
108-
const scrollUp = untracked(() => this.scrolledUp());
109-
110-
if (scrollUp) {
111-
buttons[buttons.length - 1].element().focus();
112-
this.scrolledUp.set(false);
113-
}
114-
});
115-
116-
afterRenderEffect(() => {
117-
const buttons = this._buttons();
118-
const scrollDown = untracked(() => this.scrolledDown());
119-
120-
if (scrollDown) {
121-
buttons[0].element().focus();
122-
this.scrolledDown.set(false);
123-
}
124-
});
125103
}
126104

127105
nextMonth(): void {
@@ -132,26 +110,6 @@ export class GridCalendarExample<D> {
132110
this.viewMonth.set(this._dateAdapter.addCalendarMonths(this.viewMonth(), -1));
133111
}
134112

135-
onNavigate(event: NavigateEvent) {
136-
const prev = event.prev;
137-
const next = event.next;
138-
if (prev === undefined || next == undefined) return;
139-
if (!(event.rawEvent instanceof KeyboardEvent)) return;
140-
141-
const key = event.rawEvent.key;
142-
// Hitting edge
143-
if (prev === next) {
144-
if (key === 'ArrowUp' || key === 'ArrowLeft') {
145-
this.prevMonth();
146-
this.scrolledUp.set(true);
147-
}
148-
if (key === 'ArrowDown' || key === 'ArrowRight') {
149-
this.nextMonth();
150-
this.scrolledDown.set(true);
151-
}
152-
}
153-
}
154-
155113
private _createWeekCells(viewMonth: D): CalendarCell[][] {
156114
const daysInMonth = this._dateAdapter.getNumDaysInMonth(viewMonth);
157115
const dateNames = this._dateAdapter.getDateNames();

0 commit comments

Comments
 (0)