Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions resources/js/modules/ui/TableControl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,21 @@ describe('Vue table rows', () => {
expect(referencedText(input, 'aria-labelledby')).toContain('Required');
});

it('treats column widths without a unit as pixels, as Craft 5 did', async () => {
await mountTable(false, undefined, {
columns: {
title: {type: 'singleline', heading: 'Title', width: ' 25 '},
count: {type: 'number', heading: 'Count', width: 75},
url: {type: 'url', heading: 'URL', width: '40%'},
},
});

const widths = [...form.querySelectorAll<HTMLElement>('thead th')]
.slice(0, 3)
.map((th) => th.style.width);
expect(widths).toEqual(['25px', '75px', '40%']);
});

it.each([
{includeRowId: true, field: 'rowId'},
{includeRowId: 'uid', field: 'uid'},
Expand Down
14 changes: 8 additions & 6 deletions resources/js/modules/ui/TableControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@
);
const autopopulation = useAutopopulation();
const columns = computed(() => Object.entries(props.control.props.columns));

/** Widths without a unit are pixels, as in Craft 5. */
function columnWidth(width: string | number | undefined) {
const trimmed = String(width ?? '').trim();
return /^\d*\.?\d+$/.test(trimmed) ? `${trimmed}px` : trimmed || undefined;
}

const rowIdField = computed(() =>
typeof props.control.props.includeRowId === 'string'
? props.control.props.includeRowId
Expand Down Expand Up @@ -547,12 +554,7 @@
scope="col"
:hidden="column.type === 'hidden'"
:class="column.class"
:style="{
width:
typeof column.width === 'number'
? `${column.width}%`
: column.width,
}"
:style="{width: columnWidth(column.width)}"
>
<span v-if="column.headingHtml" v-html="column.headingHtml" />
<template v-else>{{
Expand Down
4 changes: 2 additions & 2 deletions src/Field/Matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public function settingsUi(UiContext $context = new UiContext): Ui
];
}
// The URI and Route columns share the remaining width equally
$uriWidth = Cms::config()->headlessMode ? [] : ['width' => 50];
$uriWidth = Cms::config()->headlessMode ? [] : ['width' => '50%'];
$siteColumns = [
'heading' => ['heading' => t('Site'), 'type' => 'heading', 'class' => 'thin'],
'uriFormat' => [
Expand All @@ -465,7 +465,7 @@ public function settingsUi(UiContext $context = new UiContext): Ui
if (! Cms::config()->headlessMode) {
$siteColumns['destination'] = [
...ElementSiteSettings::destinationColumn(Entry::class),
'width' => 50,
'width' => '50%',
];
}

Expand Down
4 changes: 2 additions & 2 deletions src/Http/ViewModels/SectionEditViewModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private function siteSettingsControl(SectionType $type): Table
? t('Leave blank if the entry doesn’t have a URL')
: t('Leave blank if entries don’t have URLs');
// The URI and Route columns share the remaining width equally
$uriWidth = $this->headlessMode ? [] : ['width' => 50];
$uriWidth = $this->headlessMode ? [] : ['width' => '50%'];

return Table::make('sites')
->keyed()
Expand Down Expand Up @@ -299,7 +299,7 @@ private function siteSettingsControl(SectionType $type): Table
]),
'destination' => $show(! $this->headlessMode, [
...ElementSiteSettings::destinationColumn(EntryElement::class),
'width' => 50,
'width' => '50%',
]),
'enabledByDefault' => $show(! $single, ['heading' => t('Default Status'), 'type' => 'lightswitch', 'class' => 'thin centered']),
]);
Expand Down
Loading