Skip to content

Commit 88196da

Browse files
jasonvargaclaude
andauthored
[6.x] Don't reserve space when a field's display label is hidden (#14803)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 5c7e3c4 commit 88196da

4 files changed

Lines changed: 22 additions & 42 deletions

File tree

resources/css/components/fieldtypes/grid.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
border-spacing: 0;
88
table-layout: auto;
99

10-
[data-ui-field-text] {
11-
@apply sr-only;
12-
}
13-
1410
thead th {
1511
@apply sticky -top-2 table-cell z-(--z-index-above) border-b bg-gray-50 p-2 text-sm font-medium text-gray-900 dark:border-gray-700 dark:bg-gray-925 dark:text-gray-100;
1612
/* Prevent the sticky toolbar from hitting the very end of container, which causes it to overlap the container's border-radius */

resources/js/components/ui/Field.vue

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,10 @@ const rootClasses = computed(() =>
5252
},
5353
inline: {
5454
true: 'grid md:grid-cols-2 items-start px-4.5 py-4 gap-y-3 md:gap-y-0 md:gap-x-5!',
55+
false: 'flex flex-col gap-2',
5556
},
5657
fullWidthSetting: {
57-
true: 'md:grid-cols-1',
58-
},
59-
},
60-
})({
61-
...props,
62-
})),
63-
);
64-
65-
const descriptionClasses = computed(() =>
66-
twMerge(cva({
67-
base: ['mb-2 -mt-0.5'],
68-
variants: {
69-
inline: {
70-
true: 'mb-0',
71-
},
72-
fullWidthSetting: {
73-
true: 'mb-3',
58+
true: 'md:grid-cols-1 md:gap-y-3',
7459
},
7560
},
7661
})({
@@ -96,35 +81,30 @@ const hasErrors = computed(() => {
9681

9782
<template>
9883
<div :class="[rootClasses, $attrs.class]" data-ui-input-group :data-ui-field-has-errors="hasErrors ? '' : null">
99-
<div v-if="label || (instructions && !instructionsBelow) || $slots.label || $slots.actions">
84+
<div
85+
v-if="label || $slots.label || $slots.actions || (instructions && !instructionsBelow)"
86+
class="flex flex-col gap-1.5"
87+
data-ui-field-header
88+
>
10089
<div
10190
v-if="$slots.actions"
102-
:class="[
103-
'flex items-center gap-x-1 mb-0',
104-
props.label || $slots.label ? 'justify-between' : 'justify-end',
105-
]"
106-
data-ui-field-header
91+
class="flex items-center gap-x-1"
92+
:class="label || $slots.label ? 'justify-between' : 'justify-end'"
10793
>
10894
<slot name="label">
10995
<Label v-if="label" v-bind="labelProps" class="flex-1" />
11096
</slot>
11197
<slot name="actions" />
11298
</div>
113-
<div
114-
v-if="(!$slots.actions && (label || (instructions && !instructionsBelow) || $slots.label)) || ($slots.actions && instructions && !instructionsBelow)"
115-
data-ui-field-text
116-
:class="inline ? 'mb-0' : 'mb-2'"
117-
>
118-
<slot v-if="!$slots.actions" name="label">
119-
<Label v-if="label" v-bind="labelProps" class="flex-1" />
120-
</slot>
121-
<Description :text="instructions" v-if="instructions && !instructionsBelow" :class="descriptionClasses" />
122-
</div>
99+
<slot v-else name="label">
100+
<Label v-if="label" v-bind="labelProps" />
101+
</slot>
102+
<Description :text="instructions" v-if="instructions && !instructionsBelow" />
123103
</div>
124104
<slot />
125-
<div v-if="(instructions && instructionsBelow) || hasErrors">
126-
<Description :text="instructions" v-if="instructions && instructionsBelow" class="mt-2" />
127-
<ErrorMessage v-if="errors" v-for="(error, i) in errors" :key="i" :text="error" class="mt-2" />
105+
<div v-if="(instructions && instructionsBelow) || hasErrors" class="flex flex-col gap-2">
106+
<Description :text="instructions" v-if="instructions && instructionsBelow" />
107+
<ErrorMessage v-if="errors" v-for="(error, i) in errors" :key="i" :text="error" />
128108
</div>
129109
</div>
130110
</template>

resources/js/components/ui/Label.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const props = defineProps({
1818

1919
<template>
2020
<label
21-
class="flex justify-between mb-1.5 text-sm font-medium [&_button]:font-medium text-gray-925 select-none dark:text-gray-300 [&_button:has(svg)]:h-auto"
21+
class="flex justify-between text-sm font-medium [&_button]:font-medium text-gray-925 select-none dark:text-gray-300 [&_button:has(svg)]:h-auto"
2222
data-ui-label
2323
:for="for"
2424
>

resources/js/components/ui/Publish/Field.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,13 @@ const shouldShowField = computed(() => {
151151
152152
const shouldShowLabelText = computed(() => !props.config.hide_display);
153153
154+
// Whether the label renders anything visible. When it doesn't, we avoid rendering
155+
// the field header entirely (so it doesn't reserve space) and instead attach a
156+
// screen-reader-only label to the control below.
154157
const shouldShowLabel = computed(
155158
() =>
156159
shouldShowLabelText.value || // Need to see the text
157-
props.config.hide_display || // Need label for accessibility (visually hidden)
160+
isRequired.value || // Need to see the required asterisk
158161
isLocked.value || // Need to see the avatar
159162
isSyncable.value, // Need to see the icon
160163
);
@@ -267,6 +270,7 @@ const fieldtypeComponentEvents = computed(() => ({
267270
<template #actions v-if="shouldShowFieldActions">
268271
<FieldActions :actions="fieldActions" />
269272
</template>
273+
<label v-if="!shouldShowLabel && config.hide_display" :for="fieldId" class="sr-only">{{ __(config.display) }}</label>
270274
<div class="text-xs text-red-600" v-if="!fieldtypeComponentExists && fieldtypeComponent !== 'spacer-fieldtype'">
271275
Component <code v-text="fieldtypeComponent"></code> does not exist.
272276
</div>

0 commit comments

Comments
 (0)