fix(components): add undefined checks in GanttChartPrimitive

- Add undefined check for first row before accessing cellsByRow
- Add nullish coalescing for focusedRow.value in emit calls
This commit is contained in:
kolaente 2025-11-22 16:05:07 +01:00
parent 59fedb6757
commit a615afa934
1 changed files with 8 additions and 5 deletions

View File

@ -35,9 +35,12 @@ const focusedCellIndex = ref<number | null>(null)
const focusedRow = computed(() => focusedRowIndex.value === null
? null
: props.rows[focusedRowIndex.value])
const cellsCount = computed(() => props.rows.length
? props.cellsByRow[props.rows[0]].length
: 0)
const cellsCount = computed(() => {
const firstRow = props.rows[0]
return firstRow !== undefined && props.cellsByRow[firstRow]
? props.cellsByRow[firstRow].length
: 0
})
onClickOutside(chartRef, () => {
focusedRowIndex.value = null
@ -63,7 +66,7 @@ function initializeFocus() {
if (focusedRowIndex.value === null && props.rows.length > 0) {
focusedRowIndex.value = 0
focusedCellIndex.value = 0
emit('update:focused', { row: focusedRow.value, cell: focusedCellIndex.value })
emit('update:focused', { row: focusedRow.value ?? null, cell: focusedCellIndex.value })
}
}
@ -72,7 +75,7 @@ function setFocus(rowId: string, cellIndex: number = 0) {
if (rowIndex !== -1) {
focusedRowIndex.value = rowIndex
focusedCellIndex.value = Math.max(0, Math.min(cellIndex, cellsCount.value - 1))
emit('update:focused', { row: focusedRow.value, cell: focusedCellIndex.value })
emit('update:focused', { row: focusedRow.value ?? null, cell: focusedCellIndex.value })
}
}