Skip to content

useActiveTableItem ​

Manages the selected row in a table and the associated detail/side panel. When a row is selected (modelValue), a detail panel opens; clicking outside or calling closeItemDetails clears the selection.

File: vue/src/js/hooks/useActiveTableItem.js
Props factory: makeActiveTableItemProps


Usage ​

js
import { useActiveTableItem, makeActiveTableItemProps } from '@/hooks'

const props = defineProps({ ...makeActiveTableItemProps() })
const {
  item,
  modalStatus,
  activeKey,
  activeBlock,
  items,
  selectNested,
  clickOutside,
  closeItemDetails
} = useActiveTableItem(props, context)
html
<!-- In a data-table -->
<v-data-table
  v-model="item"
  :items="tableItems"
  @click:outside="clickOutside"
/>

<!-- Detail panel -->
<v-navigation-drawer v-model="modalStatus">
  <div v-if="activeBlock">{{ activeBlock }}</div>
</v-navigation-drawer>

Props (via makeActiveTableItemProps) ​

Extends makeModelValueProps plus:

PropTypeDefaultDescription
modelValueString|Number|Object|Boolean—The currently selected row (two-way via v-model)
tableHeadersArray[]Table header definitions
itemDataObject{}A map of data blocks keyed by a string; accessed via activeKey

Returns ​

NameTypeDescription
itemComputedRefTwo-way proxy for modelValue — set to null to deselect
modalStatusComputedRef<Boolean>True when a row is selected and the detail panel is open
modalOpenedRef<Boolean>Whether the modal has been opened at least once
modalActiveRef<Boolean>Whether the modal content area is active
activeKeyRef<String|null>The currently selected nested data block key
activeBlockComputedRef<any>itemData[activeKey] — the resolved nested data
itemsComputedRef<Array>[item.value] when a row is selected, [] otherwise
selectNested(key) => voidSet activeKey and emit toggle(true)
clickOutside(event) => voidClear item and activeKey
closeItemDetails(key?) => voidClose the nested block view; emit toggle(false)

Reactive behaviour ​

TriggerEffect
item changes to a non-null valuemodalActive becomes true
item becomes nullmodalActive becomes false
activeKey is setmodalActive becomes false (switches to nested view)

See Also ​