Skip to content

Commit bfc7a41

Browse files
feat(section): group Section under "Layout" in the add menu
A section is not a question: it has no answer and only structures the form. Listed among the question types it reads like one more kind of question. The "Add a question" menu now shows two captioned groups, "Questions" with every answerable type in the existing order, and "Layout" with Section, so display-only entries stand apart. Content blocks will join "Layout" later. The captions are not focusable; the arrow keys move between the entries of both groups. A menu without layout entries shows no captions. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
1 parent 68b8ece commit bfc7a41

2 files changed

Lines changed: 77 additions & 14 deletions

File tree

‎playwright/e2e/sections.spec.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,4 +458,41 @@ test.describe('Sections', () => {
458458
).toBeVisible()
459459
await expect(page.getByRole('menuitem', { name: 'Section' })).toBeVisible()
460460
})
461+
462+
test('The add menu groups the question types under "Questions" and Section under "Layout"', async ({
463+
page,
464+
}) => {
465+
const form = await api(page.request, 'POST', '/forms')
466+
await page.goto(`apps/forms/${form.hash}/edit`)
467+
468+
await page.getByRole('button', { name: 'Add a question' }).focus()
469+
await page.keyboard.press('Enter')
470+
const menu = page.getByRole('menu')
471+
const items = menu.getByRole('menuitem')
472+
await expect(menu.getByText('Questions', { exact: true })).toBeVisible()
473+
await expect(menu.getByText('Layout', { exact: true })).toBeVisible()
474+
await expect(items.last()).toHaveAccessibleName('Section')
475+
await expect(items.first()).toBeFocused()
476+
477+
await page.keyboard.press('ArrowUp')
478+
await expect(items.last()).toBeFocused()
479+
await page.keyboard.press('ArrowUp')
480+
await expect(items.nth(-2)).toBeFocused()
481+
})
482+
483+
test('The add menu fits a 320 px wide screen', async ({ page }) => {
484+
const form = await api(page.request, 'POST', '/forms')
485+
await page.setViewportSize({ width: 320, height: 640 })
486+
await page.goto(`apps/forms/${form.hash}/edit`)
487+
488+
await page.getByRole('button', { name: 'Add a question' }).click()
489+
const menu = page.getByRole('menu')
490+
await expect(menu.getByText('Layout', { exact: true })).toBeVisible()
491+
const box = await menu.boundingBox()
492+
expect(box!.x).toBeGreaterThanOrEqual(0)
493+
expect(box!.x + box!.width).toBeLessThanOrEqual(320)
494+
expect(
495+
await page.evaluate(() => document.documentElement.scrollWidth),
496+
).toBeLessThanOrEqual(320)
497+
})
461498
})

‎src/components/AddQuestionMenu.vue‎

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@
1818
</template>
1919

2020
<template v-if="!activeQuestionType">
21-
<NcActionButton
22-
v-for="(answer, type) in answerTypesFilter"
23-
:key="answer.label"
24-
:closeAfterClick="!hasSubtypes(answer)"
25-
:disabled="isLoadingQuestions"
26-
:isMenu="hasSubtypes(answer)"
27-
class="question-menu__question"
28-
@click="onPrimaryClick(answer, type, position)">
29-
<template #icon>
30-
<NcIconSvgWrapper :svg="answer.icon" />
31-
</template>
32-
{{ answer.label }}
33-
</NcActionButton>
21+
<template v-for="group in groups" :key="group.name">
22+
<NcActionCaption v-if="groups.length > 1" :name="group.name" />
23+
<NcActionButton
24+
v-for="[type, answer] in group.types"
25+
:key="answer.label"
26+
:closeAfterClick="!hasSubtypes(answer)"
27+
:disabled="isLoadingQuestions"
28+
:isMenu="hasSubtypes(answer)"
29+
class="question-menu__question"
30+
@click="onPrimaryClick(answer, type, position)">
31+
<template #icon>
32+
<NcIconSvgWrapper :svg="answer.icon" />
33+
</template>
34+
{{ answer.label }}
35+
</NcActionButton>
36+
</template>
3437
</template>
3538

3639
<template v-else>
@@ -75,19 +78,23 @@ import type { AnswerTypeConfig } from '../models/AnswerTypes.ts'
7578
import IconPlus from '@material-symbols/svg-400/outlined/add.svg?raw'
7679
import IconChevronLeft from '@material-symbols/svg-400/outlined/chevron_left.svg?raw'
7780
import { t } from '@nextcloud/l10n'
78-
import { defineComponent, ref, watch } from 'vue'
81+
import { computed, defineComponent, ref, watch } from 'vue'
7982
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
83+
import NcActionCaption from '@nextcloud/vue/components/NcActionCaption'
8084
import NcActions from '@nextcloud/vue/components/NcActions'
8185
import NcActionSeparator from '@nextcloud/vue/components/NcActionSeparator'
8286
import NcIconSvgWrapper from '@nextcloud/vue/components/NcIconSvgWrapper'
8387
import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon'
8488
89+
const LAYOUT_TYPES = ['section']
90+
8591
export default defineComponent({
8692
name: 'AddQuestionMenu',
8793
8894
components: {
8995
NcActions,
9096
NcActionButton,
97+
NcActionCaption,
9198
NcActionSeparator,
9299
NcIconSvgWrapper,
93100
NcLoadingIcon,
@@ -121,6 +128,24 @@ export default defineComponent({
121128
const activeQuestionType = ref<string | null>(null)
122129
const openLocal = ref<boolean>(props.open)
123130
131+
/**
132+
* The menu entries in captioned groups: answerable types under "Questions",
133+
* display-only types under "Layout"; groups without entries are left out
134+
*/
135+
const groups = computed(() => {
136+
const types = Object.entries(props.answerTypesFilter)
137+
return [
138+
{
139+
name: t('forms', 'Questions'),
140+
types: types.filter(([type]) => !LAYOUT_TYPES.includes(type)),
141+
},
142+
{
143+
name: t('forms', 'Layout'),
144+
types: types.filter(([type]) => LAYOUT_TYPES.includes(type)),
145+
},
146+
].filter((group) => group.types.length > 0)
147+
})
148+
124149
watch(
125150
() => props.open,
126151
(value: boolean) => {
@@ -174,6 +199,7 @@ export default defineComponent({
174199
}
175200
176201
return {
202+
groups,
177203
activeQuestionType,
178204
openLocal,
179205
onPrimaryClick,

0 commit comments

Comments
 (0)