Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions src/aria/grid/grid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,96 @@ describe('Grid directives', () => {
expect(widgetDirective.isActivated()).toBeFalse();
});
});

describe('disabled element roving tabindex calculation', () => {
it('should not choose disabled element as active cell when softDisabled is false upon cell deletion', async () => {
const gridData: RowConfig[] = [
{
cells: [{id: 'c0-0'}, {id: 'c0-1', disabled: true}, {id: 'c0-2'}],
},
];
await setupGrid({
gridData,
softDisabled: false,
focusMode: 'roving',
});
gridInstance._pattern.setDefaultStateEffect();
await fixture.whenStable();

expect(getActiveCellId()).toBe('c0-0');

// Delete c0-0 so c0-1 (disabled) is now at index 0
fixture.componentInstance.gridData.set([
{
cells: [{id: 'c0-1', disabled: true}, {id: 'c0-2'}],
},
]);
await fixture.whenStable();
await fixture.whenStable();

expect(getActiveCellId()).toBe('c0-2');
});

it('should not choose cell with disabled widget as active cell when softDisabled is false upon cell deletion', async () => {
const gridData: RowConfig[] = [
{
cells: [
{id: 'c0-0'},
{id: 'c0-1', widgets: [{id: 'w0-1', disabled: true}]},
{id: 'c0-2'},
],
},
];
await setupGrid({
gridData,
softDisabled: false,
focusMode: 'roving',
});
gridInstance._pattern.setDefaultStateEffect();
await fixture.whenStable();

expect(getActiveCellId()).toBe('c0-0');

// Delete c0-0 so c0-1 (with disabled widget) is now at index 0
fixture.componentInstance.gridData.set([
{
cells: [{id: 'c0-1', widgets: [{id: 'w0-1', disabled: true}]}, {id: 'c0-2'}],
},
]);
await fixture.whenStable();
await fixture.whenStable();

expect(getActiveCellId()).toBe('c0-2');
});

it('should recalculate active cell when active cell dynamically becomes disabled and softDisabled is false', async () => {
const gridData: RowConfig[] = [
{
cells: [{id: 'c0-0'}, {id: 'c0-1'}, {id: 'c0-2'}],
},
];
await setupGrid({
gridData,
softDisabled: false,
focusMode: 'roving',
});
gridInstance._pattern.setDefaultStateEffect();
await fixture.whenStable();

expect(getActiveCellId()).toBe('c0-0');

// Dynamically disable c0-0 in-place
fixture.componentInstance.gridData.set([
{
cells: [{id: 'c0-0', disabled: true}, {id: 'c0-1'}, {id: 'c0-2'}],
},
]);
await fixture.whenStable();
await fixture.whenStable();

expect(getActiveCellId()).toBe('c0-1');
});
});
});

describe('structural validations', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/aria/private/behaviors/grid/grid-focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export class GridFocus<T extends GridFocusCell> {

const activeCellNotValid = activeCellCoords === undefined;
const activeCellMismatch = activeCell !== activeCoordsCell;
return activeCellNotValid || activeCellMismatch;
const activeCellNotFocusable = !this.isFocusable(activeCell!);
return activeCellNotValid || activeCellMismatch || activeCellNotFocusable;
});

/** The id of the current active cell, for ARIA activedescendant. */
Expand Down
4 changes: 3 additions & 1 deletion src/aria/private/grid/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export class GridCellPattern implements GridCell {
readonly selectable: SignalLike<boolean> = () => this.inputs.selectable();

/** Whether a cell is disabled. */
readonly disabled: SignalLike<boolean> = () => this.inputs.disabled();
readonly disabled: SignalLike<boolean> = computed(
() => this.inputs.disabled() || (this.inputs.widget()?.inputs.disabled() ?? false),
);

/** The number of rows the cell should span. */
readonly rowSpan: SignalLike<number> = () => this.inputs.rowSpan();
Expand Down
Loading