Skip to content

feat(Table): add colgroup slot - #7468

Open
mateusznarowski wants to merge 1 commit into
nuxt:v4from
mateusznarowski:feat/table-colgroup
Open

mateusznarowski wants to merge 1 commit into
nuxt:v4from
mateusznarowski:feat/table-colgroup

Conversation

@mateusznarowski

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Resolves #7399

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Add an optional #colgroup slot to UTable, rendered after <caption> and before <thead>.

With a fixed table layout, widths on header cells work for simple tables. When the first header row contains a cell that spans multiple columns, a <colgroup> lets users set a separate width for each column under that shared header.

Include a docs example with grouped headers and a test for the slot's placement.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@vercel

vercel Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ui Ready Ready Preview Nov 22, 2026 10:33pm UTC
ui-repl Ready Ready Preview Nov 22, 2026 10:33pm UTC

Request Review

@mateusznarowski

Copy link
Copy Markdown
Contributor Author

I also tried using TanStack’s column sizes with the current slot. You can get the visible columns in render order from tableApi and use column.getSize() for each <col>:

<script setup lang="ts">
import { computed, useTemplateRef } from 'vue'
import type { TableColumn } from '@nuxt/ui'

const data = [{ order: 101, status: 'Paid', amount: '$42.00' }]
const columns: TableColumn<typeof data[number]>[] = [
  { accessorKey: 'order', header: 'Order', size: 96 },
  { accessorKey: 'status', header: 'Status', size: 112 },
  { accessorKey: 'amount', header: 'Amount', size: 128 }
]

const table = useTemplateRef('table')

const visibleColumns = computed(() => {
  const api = table.value?.tableApi
  if (!api) return []

  return [
    ...api.getLeftVisibleLeafColumns(),
    ...api.getCenterVisibleLeafColumns(),
    ...api.getRightVisibleLeafColumns()
  ]
})
</script>

<template>
  <UTable ref="table" :data="data" :columns="columns">
    <template #colgroup>
      <colgroup v-if="visibleColumns.length">
        <col
          v-for="column in visibleColumns"
          :key="column.id"
          :style="{ width: `${column.getSize()}px` }"
        >
      </colgroup>
    </template>
  </UTable>
</template>

One small follow-up could be to move that computed into Table.vue, use its existing tableApi, and expose the list as a typed columns: Column<T>[] slot prop:

<slot name="colgroup" :columns="visibleColumns" />

The caller would keep the same <colgroup> markup and width bindings. They’d use #colgroup="{ columns }" and loop over columns from the slot. If the table ref and computed were only there to build that list, both could go away.

I’ve kept the slot simple in this PR. Do you think exposing columns would be useful?

@github-actions

Copy link
Copy Markdown
Contributor

Client output of the apps in test/bundle that changed, compared to the base branch.

Fixture JS (gzip) CSS (gzip)
nuxt-full 908.0 kB (+7 B, +0.0%) 29.3 kB
Raw sizes
Fixture JS CSS
nuxt-full 2846.1 kB (+23 B, +0.0%) 212.3 kB

@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

UTable adds an optional colgroup slot and renders its content after the caption and before the table head. The documentation and example describe column widths and sizing considerations. A test checks the rendered order and the first column’s class.

Estimated code review effort: 2 (Simple) | ~10 minutes

Severity of issue fixed: Medium

Merge Risk: Minimal · up to cd003

This adds an optional colgroup slot to UTable so callers can set column widths. Existing tables are unaffected and the slot placement is tested, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: an optional colgroup slot added to the Table component. It is specific and matches the changeset, which adds the slot to Table.vue, a docs example, and a test. The tit…
Description check Passed The description states the purpose: an optional #colgroup slot rendered between caption and thead, with a docs example and a placement test. It also links issue #7399 and explains why per-column width…
Linked Issues check Passed [#7399] requests an optional colgroup slot in UTable, rendered before thead. The whole-PR diff of src/runtime/components/Table.vue (merge base to head) adds 'colgroup'?: (props?: {}) => VNode[] to Tab…
Out of Scope Changes check Passed All changes relate to the colgroup slot. The Table.vue change is the slot type and its render position. The test checks slot placement. The docs example (TableColgroupExample.vue) and the docs section…
Full details: Title check

Explanation

The title names the main change: an optional colgroup slot added to the Table component. It is specific and matches the changeset, which adds the slot to Table.vue, a docs example, and a test. The title follows a conventional commit style.

Full details: Description check

Explanation

The description states the purpose: an optional #colgroup slot rendered between caption and thead, with a docs example and a placement test. It also links issue #7399 and explains why per-column widths help with grouped headers. This matches the changeset.

Full details: Linked Issues check

Explanation

[#7399] requests an optional colgroup slot in UTable, rendered before thead. The whole-PR diff of src/runtime/components/Table.vue (merge base to head) adds 'colgroup'?: (props?: {}) => VNode[] to TableSlots and adds <slot name="colgroup" /> between the caption block and the thead element. This meets the core coding requirement. The PR summary also reports a test that checks the first children are caption, colgroup and thead, and a docs example with grouped headers and fixed column widths. The issue's workaround note (w-full with table-fixed) is a usage detail, and the docs example covers it. The test and docs hunks were taken from the PR summary and were not read line by line. The Table.vue placement was verified in the diff.

Full details: Out of Scope Changes check

Explanation

All changes relate to the colgroup slot. The Table.vue change is the slot type and its render position. The test checks slot placement. The docs example (TableColgroupExample.vue) and the docs section in table.md show the slot use with grouped headers. The docs also note how to keep <col> elements aligned when columns are hidden, reordered or pinned. This guidance follows from the slot behaviour and is not unrelated work. No unrelated file changes appear in the file list from the PR summary.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9c2bf1ad-ad05-49c4-9347-7f6a65334bb6
Commits

Reviewing files that changed from the base of the PR and between 422d015 and cd003c0.

Files selected for processing: 4

  • docs/app/components/content/examples/table/TableColgroupExample.vue
  • docs/content/docs/2.components/table.md
  • src/runtime/components/Table.vue
  • test/components/Table.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Nov 22, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@nuxt/ui@7468

commit: cd003c0

@codspeed

codspeed Bot commented Nov 22, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 41.59%

2 warnings

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚠️ 1 benchmark with a significant change ran in a different software environment

Its base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the change might come from this difference rather than from the code. Open the benchmark to see what changed.

See affected benchmarks

⚡ 1 improved benchmark
✅ 32 untouched benchmarks
⏩ 10 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ navigation-menu (~31 slots) 1,014 µs 716.1 µs +41.59%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing mateusznarowski:feat/table-colgroup (cd003c0) with v4 (422d015)

Open in CodSpeed

Footnotes

  1. 10 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

This branch was successfully deployed

2 active deployments
Preview – ui — cd003c00 Deployed Nov 22, 2026 by vercel[bot]
Preview – ui-repl — cd003c00 Deployed Nov 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v4 #4488

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UTable: allow a <colgroup>

1 participant