| 40 | |
| 41 | /** The UI pattern for a grid cell. */ |
| 42 | export class GridCellPattern implements GridCell { |
| 43 | /** A unique identifier for the cell. */ |
| 44 | readonly id: SignalLike<string> = () => this.inputs.id(); |
| 45 | |
| 46 | /** The html element that should receive focus. */ |
| 47 | readonly element: SignalLike<HTMLElement> = () => this.inputs.element(); |
| 48 | |
| 49 | /** Whether the cell has focus. */ |
| 50 | readonly isFocused: WritableSignalLike<boolean> = signal(false); |
| 51 | |
| 52 | /** Whether the cell is selected. */ |
| 53 | readonly selected: WritableSignalLike<boolean>; |
| 54 | |
| 55 | /** Whether the cell is selectable. */ |
| 56 | readonly selectable: SignalLike<boolean> = () => this.inputs.selectable(); |
| 57 | |
| 58 | /** Whether a cell is disabled. */ |
| 59 | readonly disabled: SignalLike<boolean> = () => this.inputs.disabled(); |
| 60 | |
| 61 | /** The number of rows the cell should span. */ |
| 62 | readonly rowSpan: SignalLike<number> = () => this.inputs.rowSpan(); |
| 63 | |
| 64 | /** The number of columns the cell should span. */ |
| 65 | readonly colSpan: SignalLike<number> = () => this.inputs.colSpan(); |
| 66 | |
| 67 | /** Whether the cell is active. */ |
| 68 | readonly active: SignalLike<boolean> = computed(() => this.inputs.grid().activeCell() === this); |
| 69 | |
| 70 | /** Whether the cell is a selection anchor. */ |
| 71 | readonly anchor: SignalLike<true | undefined> = computed(() => |
| 72 | this.inputs.grid().anchorCell() === this ? true : undefined, |
| 73 | ); |
| 74 | |
| 75 | /** The `aria-selected` attribute for the cell. */ |
| 76 | readonly ariaSelected: SignalLike<boolean | undefined> = computed(() => |
| 77 | this.inputs.grid().inputs.enableSelection() && this.selectable() ? this.selected() : undefined, |
| 78 | ); |
| 79 | |
| 80 | /** The `aria-rowindex` attribute for the cell. */ |
| 81 | readonly ariaRowIndex: SignalLike<number | undefined> = computed( |
| 82 | () => |
| 83 | this.inputs.row().rowIndex() ?? |
| 84 | this.inputs.rowIndex() ?? |
| 85 | this.inputs.grid().gridBehavior.rowIndex(this), |
| 86 | ); |
| 87 | |
| 88 | /** The `aria-colindex` attribute for the cell. */ |
| 89 | readonly ariaColIndex: SignalLike<number | undefined> = computed( |
| 90 | () => this.inputs.colIndex() ?? this.inputs.grid().gridBehavior.colIndex(this), |
| 91 | ); |
| 92 | |
| 93 | /** The internal tab index calculation for the cell. */ |
| 94 | private readonly _tabIndex: SignalLike<-1 | 0> = computed(() => |
| 95 | this.inputs.grid().gridBehavior.cellTabIndex(this), |
| 96 | ); |
| 97 | |
| 98 | /** The tab index for the cell. If the cell contains a widget, the cell's tab index is -1. */ |
| 99 | readonly tabIndex: SignalLike<-1 | 0> = computed(() => { |
nothing calls this directly
no test coverage detected
searching dependent graphs…