Skip to content

Commit

Permalink
Add aria-readonly to readonly cells (#2379)
Browse files Browse the repository at this point in the history
* Add aria-readonly

* Update src/Cell.tsx

Co-authored-by: Nicolas Stepien <[email protected]>

Co-authored-by: Nicolas Stepien <[email protected]>
  • Loading branch information
amanmahajan7 and nstepien authored Apr 27, 2021
1 parent 24b9c6a commit be8cd4a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { RefAttributes } from 'react';
import { css } from '@linaria/core';

import { cellSelectedClassname } from './style';
import { getCellStyle, getCellClassname } from './utils';
import { getCellStyle, getCellClassname, isCellEditable } from './utils';
import type { CellRendererProps } from './types';

const cellCopied = css`
Expand Down Expand Up @@ -107,6 +107,7 @@ function Cell<R, SR>({
aria-colindex={column.idx + 1} // aria-colindex is 1-based
aria-selected={isCellSelected}
aria-colspan={colSpan}
aria-readonly={isCellEditable(column, row) || undefined}
ref={ref}
className={className}
style={getCellStyle(column, colSpan)}
Expand Down
5 changes: 4 additions & 1 deletion src/utils/selectedCellUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ interface IsSelectedCellEditableOpts<R, SR> {
export function isSelectedCellEditable<R, SR>({ selectedPosition, columns, rows, isGroupRow }: IsSelectedCellEditableOpts<R, SR>): boolean {
const column = columns[selectedPosition.idx];
const row = rows[selectedPosition.rowIdx];
return !isGroupRow(row) && isCellEditable(column, row);
}

export function isCellEditable<R, SR>(column: CalculatedColumn<R, SR>, row: R): boolean {
return column.editor != null
&& !column.rowGroup
&& !isGroupRow(row)
&& (typeof column.editable === 'function' ? column.editable(row) : column.editable) !== false;
}

Expand Down

0 comments on commit be8cd4a

Please sign in to comment.